From stephane.bronsart at teledisnet.be Tue May 17 09:00:20 2005 From: stephane.bronsart at teledisnet.be (StepH) Date: Tue, 17 May 2005 15:00:20 +0200 Subject: Design Question. Data Acquisition/Display related. Message-ID: <4289eae4$0$344$4d4efb8e@read.news.be.uu.net> Hi, I'm building a little application, which the goal is to: 1./ Collect data via Serial line and or via a file (for playback). 2./ Display these data as graph, oscilloscope, ... How manage this ? 1./ Is each "display" must responsible to acquire/read the data ? 2./ Or an engine collect the data then send them to each "display" ? Also, how to "anim" this ? 1./ Via a timer ? 2./ Via a simple loop (read/update display/pause/read user key) The app. will be a GUI (tkInter) app. and the user must be able to stop the process at any time. Sure, all this must be maintenable, let's say to acquire data via other type of channel or to other type of display... Yes, it's like a "mini" labView... Any idea or link is welcome. Thanks. STepH. From gandalf at geochemsource.com Tue May 17 17:48:24 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Tue, 17 May 2005 23:48:24 +0200 Subject: EpyDoc problem In-Reply-To: <428A5CAA.906@geochemsource.com> References: <428A5CAA.906@geochemsource.com> Message-ID: <428A66A8.9090000@geochemsource.com> > >At the end of the traceback: > >wx\_misc.py line 3665, in _eq_ > return _misc_.DateTime.__eq__(*args) >TypeError: Expected a pointer > >I have no clue what does it mean but I guess it is an EpyDoc bug. >Does anyone ran into the same problem? Any ideas? > > Looks like it is a problem with wxWidgets. There is no problem if I do not import wx. How to overcome this problem? Currently I cannot document modules that import wx. :-( -- _________________________________________________________________ Laszlo Nagy web: http://designasign.biz IT Consultant mail: gandalf at geochemsource.com Python forever! From s_dehmand at yahoo.com Tue May 17 03:11:11 2005 From: s_dehmand at yahoo.com (Shariar Dehmand) Date: Tue, 17 May 2005 00:11:11 -0700 (PDT) Subject: No subject Message-ID: <20050517071111.85467.qmail@web50803.mail.yahoo.com> To whom it may concern, I am looking to start a python organization in Iran from scrtch, Please help me with it, or give me the mailing address of a reson which is advanced/experienced in what I try to achieve. best regards Mesean Dehmand __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From newsgroups at jhrothjr.com Fri May 6 09:10:53 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 6 May 2005 08:10:53 -0500 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: <117mr70hrp721be@news.supernews.com> "mrstephengross" wrote in message news:1115314620.902071.323410 at f14g2000cwb.googlegroups.com... > Hi all... How can I find out the number of significant digits (to the > right of the decimal place, that is) in a double? At least, I *think* > that's what I'm asking for. For instance: > > 0.103 --> 3 > 0.0103 --> 4 > 0.00103 --> 5 > 0.000103 --> 6 > 0.0000103 --> 7 > > Thanks in advance! > --Steve (mrstephengross at hotmail.com) As a lot of the responders have pointed out, it's effectively impossible to do so in any meaningful fashion if all you have is the binary representation of the number. One way of doing it is the ScientificDouble class in PyFit (and in all other versions of FIT, for that matter.) That provides a class that saves the original string representation so it can be used to determine precision for compares. It's a niche approach: it works well for FIT's purposes, but it's not a general purpose method of estimating precision throughout a lengthy calculation. That requires quite different techniques. See: fit.c2.com www.fitnesse.org FitNesse Yahoo mailing list (see the files section for PyFit.) John Roth > From __peter__ at web.de Mon May 30 02:28:55 2005 From: __peter__ at web.de (Peter Otten) Date: Mon, 30 May 2005 08:28:55 +0200 Subject: finding indices in a sequence of parentheses References: <429a382d$0$15392$626a14ce@news.free.fr> Message-ID: tiissa wrote: > Steven Bethard wrote: >> (2) Does anyone see an easier/clearer/simpler[1] way of doing this? > > I'd personnally extract the parenthesis then zip the lists of indices. > In short: > > >>> def indices(mylist): > ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in > enumerate(mylist)],[]) > ... lclose=reduce(list.__add__, [[i]*s.count(')') for i,s in > enumerate(mylist)],[]) > ... return zip(lopen,lclose) > ... > >>> indices(lst) > [(2, 2), (4, 7), (6, 7), (8, 9), (8, 10)] > >>> > > Before returning, you can check if the lists have same size and if the > '(' has lower or equal index than ')' in each of these couples. If not > you can raise the appropriate exception. > > Disclaimer: not tested further than example above (but confident). Not tested but confident should be an oxymoron for a programmer. Some examples: lst: ['(', '(', ')', ')'] hettinger [(1, 2), (0, 3)] bethard [(1, 2), (0, 3)] tiissa [(0, 2), (1, 3)] oops (or am I just spoilt by the XML spec?) lst: ['(', ')(', ')'] hettinger [(0, 1), (1, 2)] bethard [(1, 1), (0, 2)] oops tiissa [(0, 1), (1, 2)] So far Raymond's solution is my favourite... Peter From garabik-news-2005-05 at kassiopeia.juls.savba.sk Mon May 30 01:54:17 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Mon, 30 May 2005 05:54:17 +0000 (UTC) Subject: cpu usage limit References: <1117206216.695085.282510@g44g2000cwa.googlegroups.com> <7xpsvcnx54.fsf@ruckus.brouhaha.com> <1117244652.455368.227250@g43g2000cwa.googlegroups.com> Message-ID: elbertlev at hotmail.com wrote: > I understand, that what I suggest does not solve the problem you want, > but.. > > Why do you want to restrict CPU usage to 30%? In Windows I run CPU there might be three reasons: 1) less power consumed (notebooks, PDA's) 2) less heat from CPU 3) (cross platform) scheduling of low priority tasks (e.g. all my background tasks are already running with lowest priority since I do not want them to influence my desktop in any way, but still I want some of them to be of higher priority) generally, modern OS'es do not provide any ways to schedule tasks with such constrains, which makes the question perfectly legitimate -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From savemoney at excites.com Mon May 30 13:00:09 2005 From: savemoney at excites.com (savemoney at excites.com) Date: Mon, 30 May 2005 17:00:09 GMT Subject: Uk Shoppers - Discount Vouchers and Promotional Codes - NOREPLY Message-ID: Do you shop online? Do you want to save money? Discount vouchers and promotional codes exist for a wide range of on-line retailers. A comprehensive list of these retailers are to be found here: http://www.ukshops.h15.ru/vouchers.html The site includes codes and vouchers for top UK shops such as Marks & Spencer, Currys, Boots and John Lewis. Plus many, many more. Click here for full details: http://www.ukshops.h15.ru/vouchers.html Note: J=? From mefjr75 at hotmail.com Sat May 14 16:26:43 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 14 May 2005 13:26:43 -0700 Subject: A new to Python question In-Reply-To: References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> Message-ID: <1116102403.216512.324610@o13g2000cwo.googlegroups.com> I said exactly what I meant, the parantheses around the values creates a tuple that you have no reference to! It also has a side effect of binding the names inside the tuple to a value and placing them in the local namespace. It might be the "same" but it isn't very clear. If you want a tuple make it explicit, if you want individual names make it explicit. >>> def f(q,w,e,r): ... return q,w,e,r ... >>> # diff names >>> a,b,c,d= f(1,2,3,4)# explicit tuple unpacking >>> dir() ['__builtins__', '__doc__', '__name__', 'a', 'b', 'c', 'd', 'f', 'shell'] >>> del a,b,c,d >>> # where is the tuple >>> (a,b,c,d)= f(1,2,3,4)# implicit tuple unpacking !? >>> dir() ['__builtins__', '__doc__', '__name__', 'a', 'b', 'c', 'd', 'f', 'shell'] >>> del a,b,c,d >>> # Where is the tuple (a,b,c,d)? There isn't one. >>> # assign to a single name ( don't do tuple unpacking ) >>> tup=f(1,2,3,4) >>> dir() ['__builtins__', '__doc__', '__name__', 'f', 'shell', 'tup'] Now there is. Steve since you are closer to expert than novice you understand the difference. I feel this can be confusing to newbies, maybe you disagree. M.E.Farmer From steve at REMOVETHIScyber.com.au Sat May 7 19:42:30 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 08 May 2005 09:42:30 +1000 Subject: Need help subclassing Borg References: Message-ID: On Sat, 07 May 2005 22:28:34 +1000, Steven D'Aprano wrote: > I've been working with the Borg design pattern from here: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 Thanks to everyone who took the time to answer. I've learnt a lot from the discussion, not the least of which was to watch out for those mysterious bunnies. Steven. From gabor at nekomancer.net Fri May 27 08:32:53 2005 From: gabor at nekomancer.net (gabor) Date: Fri, 27 May 2005 14:32:53 +0200 Subject: write to the same file from multiple processes at the same time? Message-ID: hi, what i want to achieve: i have a cgi file, that writes an entry to a text-file.. like a log entry (when was it invoked, when did his worke end). it's one line of text. the problem is: what happens if 2 users invoke the cgi at the same time? and it will happen, because i am trying now to stress test it, so i will start 5-10 requests in parallel and so on. so, how does one synchronizes several processes in python? first idea was that the cgi will create a new temp file every time, and at the end of the stress-test, i'll collect the content of all those files. but that seems as a stupid way to do it :( another idea was to use a simple database (sqlite?) which probably has this problem solved already... any better ideas? thanks, gabor From andre.roberge at gmail.com Sun May 8 10:28:44 2005 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Sun, 08 May 2005 11:28:44 -0300 Subject: Question about Pycon 2005 (Python Visual Sandbox) Message-ID: Hi all, I was wondering if the session: Intuition and Python Programming - the Python Visual Sandbox did occur, of if it was canceled. To this day, there is still no sign of a corresponding paper on http://www.python.org/pycon/2005/papers/ nor did I see any report about it. Just curious, Andr? From kay.schluehr at gmx.net Mon May 23 16:39:24 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 23 May 2005 13:39:24 -0700 Subject: first release of PyPy In-Reply-To: References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> Message-ID: <1116880764.260884.286720@g49g2000cwa.googlegroups.com> Carl Friedrich Bolz wrote: > Rocco Moretti wrote: > > Alex Stapleton wrote: > > > >>The question still remains, can it run it's self? ;) > >> > > This allready worked in the past, though it doesn't at the moment. > > > > > > > I think they try, every once in a while, to self host. The only problem > > at this stage of the game is the ~2000x speed slowdown. Using that > > figure, a five second startup time for PyPy on CPython would take about > > 3 hours for PyPy on PyPy on CPython (5s*2000). Running a 1 second (on > > CPython) Python program would take a month and a half for PyPy on PyPy > > on CPython. (1s*2000*2000) > > > > Once they get the speed issue licked, the self hosting problems should > > be no trouble. ;) > > Speed isn't even the biggest problem when running PyPy on itself. PyPy > still 'fakes' some objects, e.g. borrows them from the underlying > Python. Does it mean You create an RPython object that runs on top of CPython, but is just an RPython facade wrapped around a CPython object? So You have four kinds of Pythons: RPy - translateable into LL code APy - non-translateable but interpretable by translated RPy RPy* - non-translateable but consistent interface with RPy. Calls APy* APy* - not translateable and not interpreteable by translated RPy "Selfhosting" would imply vanishing RPy* and APy*. But the problem seems to be that selfhosting must somehow be broken because the system needs to interact with OS-dependend librarys. As long as You run the system upon CPython the problem does not occur but once You drop it, a kind of "extension objectspace" must be created which is translated into code with nice interfacing properties. Or do You think that RPython translations will be sufficient and another ext-objectspace is just useless epi-cycling? Kay From steven.bethard at gmail.com Sat May 14 14:19:24 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sat, 14 May 2005 12:19:24 -0600 Subject: A new to Python question In-Reply-To: <1116093118.599403.35940@g14g2000cwa.googlegroups.com> References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> Message-ID: M.E.Farmer wrote: > (x,y,dotp,sumx,maxv) = abc(x,y,dotp,sumx,maxv) > This will only create a tuple in memory that has no name to reference > it by! Huh? This binds the names "x", "y", "dotp", "sumx" and "maxv" to the values returned by abc: py> def abc(*args): ... return args ... py> (x,y,dotp,sumx,maxv) = abc(2,3,5,7,11) py> x 2 py> y 3 py> dotp 5 py> sumx 7 py> maxv 11 Of course, the parentheses around x,y,dotp,sumx,maxv are unnecessary. STeVe From glauco.silva at cenpra.gov.br Mon May 16 09:16:18 2005 From: glauco.silva at cenpra.gov.br (Glauco Silva) Date: Mon, 16 May 2005 10:16:18 -0300 Subject: Multiple "cmp"s chained one after another References: Message-ID: <00ad01c55a19$72297910$e87290c8@piau> You can try this : >>> l = [(2001, 5, 2),(2111,3,3),(1984, 3, 1), (2001, 1, 1)] >>> l.sort(lambda x = l[0],y = l[1] : cmp((x[1],x[2]),(y[1],y[2]))) ----- Original Message ----- From: "Volker Grabsch" To: Sent: Saturday, May 14, 2005 7:09 AM Subject: Multiple "cmp"s chained one after another Hello! Ich just found a very nice 'pythonic' solution for an often appearing problem. I didn't find it documented anywhere, so I'm posting it here. If this isn't new in any way, I'd really like to get to know it. Example problem: I have some "datetime" objects and want to sort them, as here: birthdays = [d1,d2,d3,d4] birthdays.sort() However, I don't want to sort them the default way. These are birthdays, so only the month and day do matter, not the year. E.g.: 2003-01-01 should be smaller than 1984-05-01 So I have to write the comparison on my own, e.g. def cmp_birthdays(d1,d2): if d1.month > d2.month: return 1 if d1.month < d2.month: return -1 if d1.day > d2.day: return 1 if d1.day < d2.day: return -1 return 0 ... birthdays.sort(cmp_birthdays) This implementation of cmp_birthdays is very ugly. Image you want to chain more than 2 values in that "cmp_birthdays". I also want to use the builtin "cmp" function, not ">" and "<". After thinking some minutes about it, I found a very nice solution: I have some "cmp"s one aftter another. If one if them return 1 oder -1, it sould be returned. If it returns 0, the next "cmp" is used. In other words: I have a sequence of numbers, and want to get the first one that is not 0. (or return 0, if all numbers were 0) But this is exactly what the "or" operator does, due to short-circuit evaluation. In this example, that means: def cmp_bithdays(d1,d2): return cmp(d1.month,d2.month) or cmp(d1.day,d2.day) The generic pattern is: return cmp(...) or cmp (...) or cmp(...) or ... I'm not sure whether this pattern is already a "common recipe", but I found it to be a very nice idea. :-) Any opinions? Greets, Volker -- Volker Grabsch ---<<(())>>--- \frac{\left|\vartheta_0\times\{\ell,\kappa\in\Re\}\right|}{\sqrt [G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint\!c_\hbar\right]}}} -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.11.10 - Release Date: 13/5/2005 From stnchris at xmission.com Thu May 5 17:40:32 2005 From: stnchris at xmission.com (Steve Christensen) Date: Thu, 5 May 2005 21:40:32 +0000 (UTC) Subject: Encryption with Python? References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com> <7xoebpie84.fsf@ruckus.brouhaha.com> Message-ID: In article <7xoebpie84.fsf at ruckus.brouhaha.com>, Paul Rubin wrote: > "Blake T. Garretson" writes: > >> I found a few modules out there, but they seem to be all but abandoned. >> Most seem to have died several years ago. The most promising package >> is A.M. Kuchling's Python Cryptography Toolkit >> (http://www.amk.ca/python/code/crypto.html). > > Nice toolkit, more flexible and powerful than p3.py, but also more > complicated. There's also http://www.freenet.org.nz/ezPyCrypto/ , built on top of PyCrypto -Steve From me at privacy.net Fri May 27 10:52:36 2005 From: me at privacy.net (Dan Sommers) Date: 27 May 2005 10:52:36 -0400 Subject: Incrementing letters References: Message-ID: On Fri, 27 May 2005 16:10:32 +0200, Wolfram Kraus wrote: > Duncan Booth wrote: >>>>> import string >>>>> upone = string.maketrans( >> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', >> 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA') >> >>>>> string.translate("I've got a string s....", upone) >> "J'wf hpu b tusjoh t...." >> Note the difference though: the Python code does what you said you >> wanted, whereas your sample code corrupts punctuation. > Wow, that's quite nice. You really learn something new every day :-) A > minor improvement: Use string.ascii_letters as the first parameter for > string.maketrans And use string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ] for the second parameter to string.maketrans. Regards, Dan -- Dan Sommers From sjmachin at lexicon.net Tue May 31 20:04:00 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 01 Jun 2005 10:04:00 +1000 Subject: Problem with re.match - Newbie needs some advice In-Reply-To: <1117579323.153831.118090@f14g2000cwb.googlegroups.com> References: <1117579323.153831.118090@f14g2000cwb.googlegroups.com> Message-ID: <429CFB70.4020909@lexicon.net> rh0dium wrote: > Hi all, > >I can't seem to get into the > second re.match. Can someone point out my apparent error? errorS: 1. Imprecision -- the problem is in the *third* re.match ... 2. ... which should be re.search 3. Using re at all when simple string methods would do -- see below [snip] > for line in self.cpudata: > # Remove the newlines.. > ### line=line.strip() tokens = line.split() > ### if re.match(r"^processor\s+:", line): if tokens[0] == "processor": > cpucount += 1 > ### if re.match(r"^flags\s+:", line): elif tokens[0] == "flags" and "ht" in tokens: > ### flags=re.split(r":\s",line) > #### print "Found flags", flags[1] > ### if re.match(r"\bht\b",flags[1]): > print "HT on" > ht=1 From mahs at telcopartners.com Wed May 4 18:09:06 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Wed, 04 May 2005 15:09:06 -0700 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <4279366B.6070800@zopatista.com> References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> <8764y29x3m.fsf@uwo.ca> <877jihc7qv.fsf@uwo.ca> <4279366B.6070800@zopatista.com> Message-ID: Martijn Pieters wrote: > Dan Christensen wrote: > >> Any hints for level 13? I know how to make a call, but don't know "who" >> to call. > > > I haven't figured this one out yet either. Rather frustrating really. > All the hints I've been given so far is to rmember the solution for > level 12. > > Banging-my-head-against-it-didn't-help-either-ly yours, > > Martijn Pieters > Same here. BTW I was unable to open one of the objects created in level 12. It didn't stop me guessing the answer based on the others, but now I wonder whether I might need the missing piece for level 13. Anyone else encounter this? Michael From awb at fluent.com Fri May 20 07:31:24 2005 From: awb at fluent.com (Andrew Bushnell) Date: Fri, 20 May 2005 07:31:24 -0400 Subject: SSL (HTTPS) with 2.4 In-Reply-To: <1116550788.207740.171780@o13g2000cwo.googlegroups.com> References: <1116392416.139727.84630@g49g2000cwa.googlegroups.com> <428AD4D1.8030405@v.loewis.de> <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> <1116524774.606167.98240@f14g2000cwb.googlegroups.com> <1116550788.207740.171780@o13g2000cwo.googlegroups.com> Message-ID: <428DCA8C.5050305@fluent.com> That would be nice if something could be added to the distribution. In general, what needs to be done is as follows: #1: Connect to proxy host:port #2: Send "CONNECT" request with host:443 of secure url you want to "tunnel" to. Additional headers can be added depending on authorization needed for connection. #3: Once connection is established, setup a SSL handshake/connection via the proxy then start getting/sending data. I have steps #1 and #2 down and working with no problems, I keep getting hung up on step 3 and that is where the SSL Errors are occuring for me with squid etc. Bloke wrote: > Ideally, we should aim at a 'fix' that can be included in the > distribution. I am going to look at what communication goes on between > the proxy server and a working browser by monitoring the traffic. From > what i understand, the proxy needs to be told first to set up a secure > connection with the web site, and only then do you pass the url to the > proxy. > > > Bloke > -- ************************************ Andrew Bushnell Lead Development Engineer Fluent Inc. 10 Cavendish Court Centerra Resource Park Lebanon, NH 03766 awb at fluent.com Phone: 603-643-2600, ext. 757 Fax: 603-643-1721 www.fluent.com ************************************ From multicast_2004 at hotmail.com Fri May 6 09:42:16 2005 From: multicast_2004 at hotmail.com (=?gb2312?B?s8Ig0fQ=?=) Date: Fri, 06 May 2005 13:42:16 +0000 Subject: [HELP] Tkinter Application Minimized to System Tray :) Message-ID: I write a program with Python 2.4 + Tkinter Execute it, there will be a window show something. If I minimize it, it will be minimized to the taskbar. But I would like it to miniminze to the System Tray, this can make taskbar more clear. Would you please tell me how to modify my program. Thanks a lot !! Soure Code : # Display digits of pi in a window, calculating in a separate thread. # Compare with wpi.py in the Demo/threads/wpi.py import sys import time import thread from Tkinter import * class ThreadExample: def __init__(self, master=None): self.ok = 1 self.digits = [] self.digits_calculated = 0 self.digits_displayed = 0 self.master = master thread.start_new_thread(self.worker_thread, ()) self.frame = Frame(master, relief=RAISED, borderwidth=2) self.text = Text(self.frame, height=26, width=50) self.scroll = Scrollbar(self.frame, command=self.text.yview) self.text.configure(yscrollcommand=self.scroll.set) self.text.pack(side=LEFT) self.scroll.pack(side=RIGHT, fill=Y) self.frame.pack(padx=4, pady=4) Button(master, text='Close', command=self.shutdown).pack(side=TOP) self.master.after(100, self.check_digits) def worker_thread(self): while self.ok: self.digits.append(`9`) time.sleep(0.001) def shutdown(self): self.ok =0 self.master.after(100, self.master.quit) def check_digits(self): self.digits_calculated = len(self.digits) diff = self.digits_calculated - self.digits_displayed ix = self.digits_displayed for i in range(diff): self.text.insert(END, self.digits[ix+i]) self.digits_displayed = self.digits_calculated self.master.title('%d digits of pi' % self.digits_displayed) self.master.after(100, self.check_digits) root = Tk() root.option_readfile('optionDB') example = ThreadExample(root) root.mainloop() _________________________________________________________________ ???? MSN Explorer: http://explorer.msn.com/lccn/ From Please Wed May 18 19:06:03 2005 From: Please (Please) Date: 18 May 2005 18:06:03 -0500 Subject: * * * Important Please Read * * * May 18, 2005 6:52:44 pm (Best Viewed at 1024x768) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * References: <1116456748.906548.175760@g49g2000cwa.googlegroups.com> Message-ID: Send abuse reports, with full headers, to: groups-abuse at google.com, groups-support at google.com, abuse at aol.com, ToSReports at AOL.Com, tosusenet at aol.com, ToSGeneral at Aol.com, mail-abuse at cc.yahoo-inc.com, spam at uce.gov From http Fri May 20 21:45:22 2005 From: http (Paul Rubin) Date: 20 May 2005 18:45:22 -0700 Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116443474.565264.176640@g44g2000cwa.googlegroups.com> <7xd5rn93zi.fsf@ruckus.brouhaha.com> <7x1x81d5bx.fsf@ruckus.brouhaha.com> Message-ID: <7xacmpgxn1.fsf@ruckus.brouhaha.com> Dave Brueck writes: > > What do you use for HTTPS? > > m2crypto (plus some patches to make asynchronous SSL do what we needed). That seems to be a nice piece of code, but it's still at version 0.13; if something goes wrong, are you sure you want to explain that you were using beta-test software to protect your customers' production financial transactions? There's also been some traffic on the python-crypto list about Zope encountering memory leaks with it. I haven't read the messages carefully though, so I'm not sure what the situation is. > > did you use the Cookie module in your HTTP servers?... > Are you referring to the use of pickle for cookie serialization? Yes. From querejeto at gmail.com Tue May 3 12:19:12 2005 From: querejeto at gmail.com (querejeto) Date: 3 May 2005 09:19:12 -0700 Subject: Pydev Refactoring Feature in Eclipse Message-ID: <1115137151.978023.29890@z14g2000cwz.googlegroups.com> Folks: I cannot get a refactoring menu to show up on my Eclipse (3.1M3, Windows XP). F3 works, I can run and debug scripts. Can't refactor, though. Any idea what I could be missing on my installation? Thanks: Querejeto From xah at xahlee.org Mon May 23 06:22:41 2005 From: xah at xahlee.org (Xah Lee) Date: 23 May 2005 03:22:41 -0700 Subject: What are OOP's Jargons and Complexities? Message-ID: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> What are OOP's Jargons and Complexities Xah Lee, 20050128 The Rise of Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } In advanced languages such as LISP family, it is not uncommon to define functions inside a function. For example: subroutine f (x1, x2, ...) { variables... subroutine f1 (x1...) {...} subroutine f2 (x1...) {...} } Often these f1 f2 inner functions are used inside f, and are not relevant outside of f. Such power of the language gradually developed into a style of programing. For example: subroutine a_surface () { coordinatesList = ...; subroutine translate (distance) {...} subroutine rotate (angle) {..} } Such a style is that the a_surface is no longer viewed as a function. But instead, a boxed set of functions, centered around a piece of data. And, all functions for manipulating this piece of data are all embodied in this function. For example: subroutine a_surface (arg) { coordinatesList = ... subroutine translate (distance) {set coordinatesList to translated version} subroutine rotate (angle) {set coordinatesList to rotated version} subroutine return () {return coordinatesList} if (no arg) {return coordinatesList} else { apply arg to coordinatesList } } In this way, one uses a_surface as a data, which comes with its owe set of functions: mySurface = a_surface(); mySurface(rotate(angle)); // now the surface data has been rotated mySurface(translate(distance)); // now its translated newSurface = mySurface(return()) So now, a_surface is no longer viewed as a subroutine, but a boxed set of things centered around a piece of data. All functions that work on the data are included in the boxed set. This paradigm possible in functional languages has refined so much so that it spread to other groups and became known as Object Oriented Programing, and complete languages with new syntax catered to such scheme emerged. In such languages, instead of writing them like this: mySurface = a_surface(); mySurface(rotate(angle)); the syntax is changed to like this, for example: mySurface = new a_surface(); mySurfaceRotated = mySurface.rotate(angle); In such languages, the super subroutine a_surface is no longer called a function or subroutine. It is now called a ?Class?. And now the variable holding the function "mySurface = a_surface()" is now called a ?Object?. Subroutines inside the function a_surface() are no longer called inner-subroutines. They are called ?Methods?. The act of assigning a super-subroutine to a variable is called instantiation. This style of programing and language have become so fanatical that in such dedicated languages like Java, everything in the language are ?Classes?. One can no longer just define a variable or subroutine. Instead, one creates these meta-subroutine ?Classes?. Everything one do are inside Classes. And one assign Classes inside these Classes to create ?Objects?. And one uses ?Methods? to manipulate Objects. In this fashion, even basic primitives like numbers, strings, and lists are no longer atomic entities. They are now Classes. For example, in Java, a string is a class String. And inside the class String, there are Methods to manipulate strings, such as finding the number of chars, or extracting parts of the string. This can get very complicated. For example, in Java, there are actually two Classes of strings: One is String, and the other is StringBuffer. Which one to use depends on whether you intend to change the data. So, a simple code like this in normal languages: a = "a string"; b = "another one"; c = join(a,b); print c; or in lisp style (set a "a string") (set b "another one") (set c (join a b)) (print c) becomes in pure OOP languages: public class test { public static void main(String[] args) { String a = new String("a string"); String b = new String("another one"); StringBuffer c = new StringBuffer(40); c.append(a); c.append(b); System.out.println(c.toString()); } } Here, the "new String" creates a String object. The "new StringBuffer(40)" creates the changeable string object StringBuffer, with room for 40 chars. "append" is a method of StringBuffer. It is used to join two Strings. Notice the syntax "c.append(a)", which we can view it as calling a inner subroutine "append", on a super subroutine that has been assigned to c, where, the inner subroutine modifies the inner data by appending a to it. And in the above Java example, StringBuffer class has another method "toString()" used to convert this into a String Class, necessary because System.out.println's parameter requires a String type, not StringBuffer. For a example of the complexity of classes and methods, see the Java documentation for the StringBuffer class at http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html (local copy) In the same way, numbers in Java have become a formalization of many classes: Double, Float, Integer, Long... and each has a bunch of "methods" to operate or convert from one to the other. Instead of aNumber = 3; print aNumber^3; In Java the programer needs to master the ins and outs of the several number classes, and decide which one to use. (and if a program later needs to change from one type of number to another, it is often cumbersome.) This Object Oriented Programing style and dedicated languages (such as C++, Java) have become a fad like wild fire among the programing mass of ignoramuses in the industry. Partly because of the data-centric new perspective, partly because the novelty and mysticism of new syntax and jargonization. It is especially hyped by the opportunist Sun Microsystems with the inception of Java, internet, and web applications booms around 1995. At those times, OOP (and Java) were thought to revolutionize the industry and solve all software engineering problems, in particular by certain "reuse of components" concept that was thought to come with OOP. As part of this new syntax and purity, where everything in a program is of Classes and Objects and Methods, many complex issues and concept have arisen in OOP. We now know that the jargon Class is originally and effectively just a boxed set of data and subroutines, all defined inside a subroutine. And the jargon "Object" is just a variable that has been set to this super subroutine. And the inner subroutines are what's called Methods. ---------- to be continued tomorrow. This is part of an installment of the article ?What are OOP's Jargons and Complexities? by Xah Lee, 20050128. The full text is at http://xahlee.org/Periodic_dosage_dir/t2/oop.html ? Copyright 2005 by Xah Lee. Verbatim duplication of the complete article for non-profit purposes is granted. The article is published in the following newsgroups: comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns Xah xah at xahlee.org ? http://xahlee.org/ From jamesdcarroll at hotmail.com Sat May 28 00:26:01 2005 From: jamesdcarroll at hotmail.com (James D Carroll) Date: Sat, 28 May 2005 00:26:01 -0400 Subject: Intellisense and the psychology of typing References: <1117125072.825389.74190@g47g2000cwa.googlegroups.com> Message-ID: wrote> > 1) Intellisense is really just another crutch that does more harm than > good? There were a few hardcore defenders of this position but not > many. I'm primarily a VB programmer, but I also do Java and web stuff as well. Whenever I look at a new IDE the FIRST thing I look at is whether Intellisense-like functionality is present. If it is not, I discard it from further consideration. The reason has nothing to do with static vs dynamic typing. It has to do with the fact that I spend a considerably amount of time thinking about how I'm going to solve the problem at hand. Filling my head with API specs that I have to look up is just a pain. And frankly if I have to type 'boolean' instead of 'boo' I get real cranky real fast. > 2) Intellisense is really useful but hard to implement well in IDEs for > dynamic languages? Can anyone comment on the status of > Intellisense-like tools for dynamic-language IDEs? It might be and probably is. But I say if dynamic typers want the flexibility they think they are getting then they should have to deal with ALL of the consequences. > 3) Users of dynamic languages are always developing/debugging running > programs where the current type of a variable is known and hence > Intellisense is possible again? My own limited experience with dynamic > languages (Ruby) is limited to edit-run cycles. I can't speak to that only to say that, how in the world can an object that accepts anything reasonable be expected to protect itself from misuse or provide reliable services given a set of parameters? From skip at pobox.com Wed May 11 21:41:30 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 May 2005 20:41:30 -0500 Subject: Python Documentation (should be better?) In-Reply-To: References: Message-ID: <17026.46154.988018.268004@montanaro.dyndns.org> Christopher> Exactly!! See thats what I'm saying. I _think_ its widely Christopher> accepted that PHP has awesome documentation. And like rbt Christopher> said, that makes it extremely useful. Why can't Python Christopher> have documentation like that? It's just a simple matter of writing, editing, proofreading, feedback, etc. Given the current documentation set, does it appear what you're looking for is mostly a reorganization of the existing content? You gave the example of searching for "array". That happens to return something very useful because it maps directly to a section of the PHP manual. I tried searching for "float" and "string" but got much less on-target responses. When I searched for a term and selected selected the "online documentation" search category it did a Google search, which is what the search box on docs.python.org does. Skip From ville at spammers.com Thu May 26 03:24:07 2005 From: ville at spammers.com (Ville Vainio) Date: 26 May 2005 10:24:07 +0300 Subject: Just remember that Python is sexy References: <1116899839.323185.58350@g49g2000cwa.googlegroups.com> Message-ID: >>>>> "Peter" == Peter Hansen writes: Peter> Sion Arrowsmith wrote: >> But can you come up with a method for remembering which way >> round str.find() and str.index() are? Peter> Don't use "str" and you won't have anything to remember: Peter> 'foo bar baz'.find('spam') Peter> 'spanish inquisition'.index('parrot') But which one raises an exception, and which one returns -1? -- Ville Vainio http://tinyurl.com/2prnb From jstroud at mbi.ucla.edu Fri May 6 15:05:41 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 6 May 2005 12:05:41 -0700 Subject: hard memory limits In-Reply-To: References: <200505061052.28325.jstroud@mbi.ucla.edu> Message-ID: <200505061205.41254.jstroud@mbi.ucla.edu> On Friday 06 May 2005 11:27 am, Fredrik Lundh wrote: > James Stroud wrote: > > > does Mac OS X ship with memory limits set by default? isn't that > > > a single-user system? > > > > Dear original poster or whoever is interested in OS X: > > > > OS X is not a single user system. It is BSD based unix. And its fv at king > > sweeeeeeeeeeeeeet! (Though I'm using only Linux right now :o/ > > Well, Apple's marketing materials contain no signs whatsoever that the > systems Apple sells are designed for massive numbers of users, compared > to systems from RedHat, Sun, HP, etc. (if you look at apple.com in this > very moment, it talks a lot about "your mac" and "your desktop" and "your > computer", not "the mac/desktop/computer you share with hundreds of > other users"). > > So why would Apple insist on setting unusably low process limits, when > the others don't? > > I think that two different markets exist for this computer: 1. Joe user who has never seen a command line interface. These people need a nice, cozy little user environment that takes as little understanding as possible to use. They also buy the most computers and are probably most responsive to fluffy advertising campaigns. Hence the targeted advertising on apple.com In this case, my guess is that memory allocation, etc, is left to the application. For cocoa apps it is the objective c runtime handling this kind of thing and for carbon apps, it is probobably tacked on during the process of carbonizing. But I should say that I really don't know much about the low level workings of either. 2. Scientists/Engineers/Programmer types. These people configure their own limits instinctively and probably forgot that they ever put that unlimit in their rc files (like I did) and the dozens of other customizations they did to get their OS X boxes just so for unix use. When Joe User makes the crossover, such customizations don't seem very intuitive. Plus, I remember having to ulimit my IRIX account on SGIs I used back in the day--so other *nixes seem to have similar requirements. To answer your question, my guess is that no one has complained yet. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From arutz at mimoza.pantel.net Mon May 30 10:44:43 2005 From: arutz at mimoza.pantel.net (Antal Rutz) Date: Mon, 30 May 2005 16:44:43 +0200 Subject: Threading questions In-Reply-To: References: Message-ID: <429B26DB.2050204@mimoza.pantel.net> Magnus Lycka wrote: > Antal Rutz wrote: > >>Hi, All! >> >>I'm new to threading. I have some design questions: >>Task: I collect data and store them in an RDBMS (mysql or pgsql) >> >>The question is how to do that with threading? >>The data-collecting piece of the code runs in a thread. >> >>1. Open the db, and each thread writes the result immediately. >> (Sub-question: which is better: cursor object passed to the thread >> or stored in a global var.) >>2. Threads return data, which is written to DB after that. >>3. Threads write to global variable, after 'join()' data is written. >> (Can be used global (write-only) variables with threads at all?) >>4. ?... > > > I'm not sure why you need threading at all here, but I would avoid > both globals and passing cursors between threads. I don't think all > DB-API implementations can handle threading properly. I 'snmpwalk' routers and some are very slow, so it's better to spread the routers among data-collecting threads. > I suspect it might be useful to do data collection in one thread, > DB communication in another, and to use a Queue.Queue object to > pass data from data collection to DB insertion thread. Yes, I just figure out how the many-collecting-one-dbwriting-thread design could be made. It doesn't seem to be too difficult. Thanks for the hints! -- --arutz From Dennis.Benzinger at gmx.net Thu May 19 15:24:36 2005 From: Dennis.Benzinger at gmx.net (Dennis Benzinger) Date: Thu, 19 May 2005 21:24:36 +0200 Subject: Self-modifying Code In-Reply-To: <1116522647.227661.99290@g43g2000cwa.googlegroups.com> References: <1116522647.227661.99290@g43g2000cwa.googlegroups.com> Message-ID: <428ce7f5@news.uni-ulm.de> qwweeeit at yahoo.it schrieb: > [...] > Also Python can (writing and running a module, in-line): > > fNew =open("newModule.py",'w') > lNew=['print 123\n','print 454\n','print 789\n'] > fNew.writelines(lNew) > fNew.close() > from newModule import * > [...] You don't even need a file for this. Try: exec("print 123; print 456; print 789") Bye, Dennis From roy at panix.com Mon May 9 09:23:21 2005 From: roy at panix.com (Roy Smith) Date: Mon, 09 May 2005 09:23:21 -0400 Subject: __brace__ (PEP?) References: <1115617678.841460.294970@z14g2000cwz.googlegroups.com> Message-ID: "Kay Schluehr" wrote: > Roy Smith wrote: > > > foo->bar ==> foo.__arrrow__(bar) > > foo$bar ==> foo.__dollar__(bar) > > foo#bar ==> foo.__hash__(bar) > > foo::bar ==> foo.__scope__(bar) > > I'm strongly in favor for the arrow ( but with two "r" only ). The > question is simply: for what? I'm confused. You're strongly in favor of a piece of punctuation even though you don't have any idea what it might be used for? From rschroev_nospam_ml at fastmail.fm Sun May 8 17:40:14 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 08 May 2005 21:40:14 GMT Subject: Clueless with cPickle In-Reply-To: References: Message-ID: <2Hvfe.85711$te6.5343369@phobos.telenet-ops.be> les wrote: > Traceback (most recent call last): > File "/home/les/workspace/Module 2/questor.py", line 18, in ? > f = file(questorlistfile) > NameError: name 'questorlistfile' is not defined > > I thought that I had defined questorlistfile on the 4th line below > > # define some constants for future use > > import cPickle as p > #import pickle as p > > questorfile = 'questor.data' # the name of the file where we will store the object You defined questorfile, not questorlistfile. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From mwm at mired.org Sat May 28 16:12:34 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 28 May 2005 15:12:34 -0500 Subject: __call__ References: <42987f9a$0$26432$9b622d9e@news.freenet.de> <1117293143.679768.286600@g43g2000cwa.googlegroups.com> <4298ce99$0$176$9b622d9e@news.freenet.de> Message-ID: <86ekbrun2l.fsf@guru.mired.org> TK writes: > Simon Percivall wrote: >> Look at http://docs.python.org/ref/callable-types.html >> >>>>>class Test(object): >> ... def __call__(self): >> ... print "the instance was called" >> ... >> >>>>>t = Test() >>>>>t() >> the instance was called >> Is this what you wanted? > > Sorry but it does not work. Here's my code: > > >>> class Test(object): > ... def __call__(self): > ... print 'Hi' > ... > >>> Test() > <__main__.Test object at 0x3e6d0> Test() invokes the class, which returns an instance of the class. Look back at what Simon did. He stored the value returned by Test() as t, then called t with "t()". That's what __call__ is - the routine invoked when an instance of a class is invoked as a callable object. To change what happens when the class is invoked as a callable object, you need to fool with metaclasses. It might help if you told us what you really wanted to do with this construct. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From timothy at open-networks.net Tue May 3 00:42:30 2005 From: timothy at open-networks.net (Timothy Smith) Date: Tue, 03 May 2005 14:42:30 +1000 Subject: py2exe and library.zip Message-ID: <42770136.6090401@open-networks.net> is it possible instead of py2exe putting all library's in a zip file, to just put them in a sub dir? From bill.mill at gmail.com Mon May 9 13:16:00 2005 From: bill.mill at gmail.com (Bill Mill) Date: Mon, 9 May 2005 13:16:00 -0400 Subject: Listing of declared variables and functions In-Reply-To: <1115657899.543887.284720@f14g2000cwb.googlegroups.com> References: <1115657899.543887.284720@f14g2000cwb.googlegroups.com> Message-ID: <797fe3d40505091016572eecf8@mail.gmail.com> On 9 May 2005 09:58:19 -0700, ohms377 wrote: > Dear python users, > > In interactive mode, I was wondering if there is a way to list all > declared variables and functions (and from global workspace). > >>> x = 12 >>> z = 13 >>> import re >>> locals() {'__builtins__': , 're': , 'x': 12, '__name__': '__main__', 'z': 13, '__doc__': N one} >>> locals().keys() ['__builtins__', 're', 'x', '__name__', 'z', '__doc__'] >>> globals() {'__builtins__': , 're': , 'x': 12, '__name__': '__main__', 'z': 13, '__doc__': N one} Peace Bill Mill bill.mill at gmail.com From s_david_rose at hotmail.com Tue May 24 09:50:45 2005 From: s_david_rose at hotmail.com (GMane Python) Date: Tue, 24 May 2005 09:50:45 -0400 Subject: py2exe for WMI Message-ID: Hello All. I'm trying to 'compile-to-EXE' a python program which uses Win32 & WMI to pull system info. from the PC such as serial number, CPU speed, etc. I'm having problems with py2exe -- with regard to Win2000 & WinXP platforms. It seems that the program only works if I have one typelib for WinXP and a slightly different one for Win2000. Here is my relevent section from the py2exe setup.py: setup( options = {"py2exe": {"typelibs": ## # typelib for WMI - WinXP ## [('{565783C6-CB41-11D1-8B02-00600806D9B6}', 0, 1, 2)], # typelib for WMI - Win2000 [('{565783C6-CB41-11D1-8B02-00600806D9B6}', 0, 1, 1)], # create a compressed zip archive "compressed": 1, "optimize": 2, "packages": ["encodings"], "excludes": excludes}}, # The lib directory contains everything except the executables and the python dll. # Can include a subdirectory name. zipfile = "lib/shared.zip", Can anyone tell me how I might make one unified py2exe setup.py that'll 'compile' for both Win2000 & WinXP? If not, can someone give me a hint as to how I can have a python 'launcher' which can determine the difference between Win2000 & WinXP? Using the sys.platform, they both show as Win32. Thanks! Dave From fredrik at pythonware.com Mon May 2 16:28:37 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 2 May 2005 22:28:37 +0200 Subject: Can't get compression in Python zip script. References: <1115065046.071440.62630@z14g2000cwz.googlegroups.com> Message-ID: M.E.Farmer wrote: > I saw compression=0 and assumed that 1 would mean true, but no! > zipfile.ZIP_DEFLATED = 8, defies logic, it is the only compression type > why not accept any non zero as compression. "is the only compression type" ? quoting from the ZIP specification: compression method: (2 bytes) (see accompanying documentation for algorithm descriptions) 0 - The file is stored (no compression) 1 - The file is Shrunk 2 - The file is Reduced with compression factor 1 3 - The file is Reduced with compression factor 2 4 - The file is Reduced with compression factor 3 5 - The file is Reduced with compression factor 4 6 - The file is Imploded 7 - Reserved for Tokenizing compression algorithm 8 - The file is Deflated 9 - Enhanced Deflating using Deflate64(tm) 10 - PKWARE Data Compression Library Imploding 11 - Reserved by PKWARE 12 - File is compressed using BZIP2 algorithm ( http://www.pkware.com/company/standards/appnote/appnote.txt ) the current zipfile version only supports 0 and 8, but that doesn't mean that future versions won't support other ZIP compressions. From http Fri May 27 09:21:21 2005 From: http (Paul Rubin) Date: 27 May 2005 06:21:21 -0700 Subject: write to the same file from multiple processes at the same time? References: Message-ID: <7xacmgdctq.fsf@ruckus.brouhaha.com> Peter Hansen writes: > The OP was probably on the right track when he suggested that things > like SQLite (conveniently wrapped with PySQLite) had already solved > this problem. But they haven't. They depend on messy things like server processes constantly running, which goes against the idea of a cgi that only runs when someone calls it. From __peter__ at web.de Thu May 19 16:18:00 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 19 May 2005 22:18:00 +0200 Subject: Convert from numbers to letters References: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> <1116528750.285895.27720@f14g2000cwb.googlegroups.com> <1116530403.328825.216120@z14g2000cwz.googlegroups.com> Message-ID: Bill Mill wrote: >> By the way, sorted() can be removed from your original post. >> >> Code has no effect :-) > > I'm gonna go ahead and disagree with you: > >>>> sorted([''.join((x, y)) for x in alpha \ > ...????for?y?in?['']?+?[z?for?z?in?alpha]],?key=len)?==?\ > ... [''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]] > False > That's not your original code. You used the contents to modify the locals() (effectively globals()) dictionary: >>>> alpha = 'abcdefghijklmnopqrstuvwxyz' >>>> for i, digraph in enumerate(sorted([''.join((x, y)) for x in alpha \ > for?y?in?['']?+?[z?for?z?in?alpha]],?key=len)): > ...?????locals()[digraph]?=?i?+?i > ... > Of course you lose the order in that process. When you do care about order, I suggest that you swap the for clauses instead of sorting, e. g: >>> alpha = list("abc") >>> items = [x + y for x in [""] + alpha for y in alpha] >>> items == sorted(items, key=len) True Peter From phillip.watts at anvilcom.com Thu May 12 07:15:26 2005 From: phillip.watts at anvilcom.com (phil) Date: Thu, 12 May 2005 06:15:26 -0500 Subject: Destructor Woes, was Advice needed on __del__ References: <427FBAD4.3070004@anvilcom.com> <42800279.3B26FFF3@pauahtun.org> Message-ID: <42833ACE.4000901@anvilcom.com> > > do you (or whoever gave you the tip) have the slightest idea what atexit does? > Yeah, I got the tip on this group. researched and found it was for when program ends! I was trying to treat it like a destructor. darn. From mefjr75 at hotmail.com Sun May 15 13:03:11 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 15 May 2005 10:03:11 -0700 Subject: A new to Python question In-Reply-To: <2g7jl2-qf8.ln1@Bernd.Nawothnig.dialin.t-online.de> References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> <42866cb8.177725696@news.oz.net> <1116109657.494997.315650@o13g2000cwo.googlegroups.com> <2g7jl2-qf8.ln1@Bernd.Nawothnig.dialin.t-online.de> Message-ID: <1116176591.072516.71020@g43g2000cwa.googlegroups.com> >No. You claimed This will only create a tuple in memory That is not what I said please do not edit my words and call it a quote! >But we just learned that this is not the case. Yes it seems I was proven wrong and have learned much from the discussion ;) That is why I am here to learn from others and help if I can ( sometimes I am just plain wrong and I get the help ) >Reduced to this argument I have no objection. Glad to hear it. >Lisp is far from being ugly ;-) Your words not mine.I never said it was ugly. Lisp is beautiful but Python isn't Lisp, and the () *are* getting overloaded. M.E.Farmer From robin at reportlab.com Fri May 20 09:14:18 2005 From: robin at reportlab.com (Robin Becker) Date: Fri, 20 May 2005 14:14:18 +0100 Subject: python24.zip Message-ID: <428DE2AA.1070308@chamonix.reportlab.co.uk> Investigating a query about the python path I see that my win32 installation has c:/windows/system32/python24.zip (which is non existent) second on sys.path before the actual python24/lib etc etc. Firstly should python start up with non-existent entries on the path? Secondly is this entry be the default for some other kind of python installation? -- Robin Becker From avinashc at yahoo.com Sun May 8 09:44:27 2005 From: avinashc at yahoo.com (avinashc at yahoo.com) Date: 8 May 2005 06:44:27 -0700 Subject: Coding comments/suggestions - first python script - sshd/ftpd blocking Message-ID: <1115559867.855685.104520@g14g2000cwa.googlegroups.com> If anyone is interested in a /etc/hosts.deny automatic update script (Unix only) based on sshd/vsftpd attacks, here's a python script: http://www.aczoom.com/tools/blockhosts/ This is a beta release, and my first attempt at Python coding. Any comments, suggestions, pointers on using more common Python idioms or example coding snippets, etc, welcome! Thanks! From lsumnler at gmail.com Thu May 19 10:01:21 2005 From: lsumnler at gmail.com (len) Date: 19 May 2005 07:01:21 -0700 Subject: newbie file/DB processing In-Reply-To: References: <1116445969.381550.99280@f14g2000cwb.googlegroups.com> Message-ID: <1116511281.424349.138670@o13g2000cwo.googlegroups.com> Thanks for the reply Everyone seems to be saying the same thing which is jump into some RDBM. Len Sumnler From http Tue May 24 15:44:05 2005 From: http (Paul Rubin) Date: 24 May 2005 12:44:05 -0700 Subject: reference counting and file objects References: <7xoeb94r3j.fsf@ruckus.brouhaha.com> <428a40e1$0$29930$9b622d9e@news.freenet.de> <1116953438.844243.32800@f14g2000cwb.googlegroups.com> <42937FCA.6080800@v.loewis.de> Message-ID: <7xzmukjtoa.fsf@ruckus.brouhaha.com> "Martin v. L?wis" writes: > > lines = file("myfile","r").readlines() > > > > have any better guarantee of being closed automatically? > > Yes. The file object only lives on the evaluation stack, > and that is discarded in any case when the function terminates > (whether through a return or through an exception). In > addition, the object is released as soon as readlines > returns. It's released even if the exception is raised inside readlines? From http Wed May 11 02:41:40 2005 From: http (Paul Rubin) Date: 10 May 2005 23:41:40 -0700 Subject: pyvm -- faster python References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> Message-ID: <7xoebijmcb.fsf@ruckus.brouhaha.com> "Roger Binns" writes: > Some examples are gui toolkits (eg wxPython), SSL (eg M2Crypto, pyopenssl) > and database (pysqlite, APSW). These aren't in the shipped with Python > library but are widely used. M2Crypto is a straightforward SWIG wrapper around OpenSSL, I thought. I don't know about wxPython or pysqlite. It seems to me that some kind of SQL client should be part of the stdlib. But why isn't a SWIG wrapper enough? The CPython stdlib has for possibly good reasons avoided SWIG but a new implementation doesn't need to. > You don't have to stay backwards compatible. It is best to provide > some sort of way of using the old extensions even if it is suboptimal > (eg some sort of mapping shim). Yeah, there's something to be said for that, if it doesn't cause too much pain. > I already get burnt out on the matrix of CPython versions and different > platforms. Adding another interpretter would make life even harder > for extension authors. There's already Jython and Python.net is on its way. This is something Lisp users have dealt with for decades and they've developed workable machinery for it. Maybe Python can adopt some of those methods. From sxanth at ceid.upatras.gr Fri May 13 05:29:37 2005 From: sxanth at ceid.upatras.gr (Stelios Xanthakis) Date: Fri, 13 May 2005 12:29:37 +0300 Subject: pyvm -- faster python In-Reply-To: <1115925027.360010.183480@g49g2000cwa.googlegroups.com> References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> <1115791624.856252.247890@z14g2000cwz.googlegroups.com> <7x1x8el18e.fsf@ruckus.brouhaha.com> <1115876410.813839.222080@g43g2000cwa.googlegroups.com> <1115925027.360010.183480@g49g2000cwa.googlegroups.com> Message-ID: <42847381.9010800@ceid.upatras.gr> Hi, Kay Schluehr wrote: > > Why this? eval() consumes a string, produces a code object and executes > it. Wether the code-object is bytecode or a chunk of machine code makes > a difference in the runtime but does not alter the high level > behavioural description of eval(). In either way the compile() function > behind eval is a JIT. > It makes a difference because 1) You depend on a compiler. Especially if you want to optimize the machine code you depend on a big program (no tcc for example) 2) Optimizing machine code, needs a lot of code/time. 3) What about debugging info? Dwarf? 4) What if there's a new architecture? The bytecode compiler is *much* faster to produce the bytecode assembly. Also, for the other part of the thread, I think that bytecode may be in fact faster than machine code JIT. Here is a theory: Suppose that for each algorithm there is the "ideal implementation" which executes at the speed limit where it can't be done any faster. For small algorithms the speed limit may be known but for more complex programs, it's just a theoretical limit. Now for such very big programs bytecode has the advantage that it achieves very good code re-use; everything is those 400kB of the libpython core and that does not increase with the size of the program. In this case, bytecode is the driver that operates the buldozer (the buldozer being C). So the theory is that for very complex programs a bytecode+core-library is closer to the ideal implementation than a JIT which produces/compiles megabytes of machine code. Evidence for that may be that all those JIT efforts don't get any great speed ups (psyco is different as it exposes static-ness). Of course, if we care about speed we'll use Pyrex to convert some heavy routines to C. For example if we need FFT, it's madness to do it in the HLL. Make it part of the buldozer. Stelios From jepler at unpythonic.net Wed May 18 19:02:00 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 18 May 2005 18:02:00 -0500 Subject: iso_8859_1 mystery/tkinter In-Reply-To: <428BBAEA.4070806@anvilcom.com> References: <428BBAEA.4070806@anvilcom.com> Message-ID: <20050518230200.GB9427@unpythonic.net> this isn't about the "sign bit", it's about assumed encodings for byte strings.. In iso_8859_1 and unicode, the character with value 0xb0 is DEGREE SIGN. In other character sets, that may not be true---For instance, in the Windows "code page 437", it is u'\u2591' aka LIGHT SHADE (a half-tone pattern). When you write code like x = '%c' % (0xb0) and then pass x to a Tkinter call, Tkinter treats it as a string encoded in some system-default encoding, which could give DEGREE SIGN, could give LIGHT SHADE, or could give other characters (a thai user of Windows might see THAI CHARACTER THO THAN, for instance, and I would see a question mark because I use utf-8 and this is an invalid byte sequence). By using x = u'%c' % (0xb0) you get a unicode string, and there is no confusion about the meaning of the symbol---you always get DEGREE SIGN. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From sateeshkavuri at yahoo.com Tue May 24 04:56:56 2005 From: sateeshkavuri at yahoo.com (Sateesh) Date: Tue, 24 May 2005 08:56:56 GMT Subject: Access lotus notes using Python References: <1116921752.615735.187040@g47g2000cwa.googlegroups.com> Message-ID: Hi, Thanks very much for the input. Could you please tell me where I could get the API reference for these COM classes to access Lotus Notes? Thanks again Sateesh wrote in message news:1116921752.615735.187040 at g47g2000cwa.googlegroups.com... > try this > > import win32com.client > session = win32com.client.Dispatch('Lotus.NotesSession') > session.Initialize(r'pppppppp') > db = session.GetDatabase('',r'dddddddd.nsf') > view = db.GetView(r'vvvvvvvv') > doc = view.GetFirstDocument() > print doc.GetFirstItem('iiiiii').Values > > domino return string as unicode > From johnandsarah at estragon.freeserve.co.uk Sat May 28 06:48:07 2005 From: johnandsarah at estragon.freeserve.co.uk (John Perks and Sarah Mount) Date: Sat, 28 May 2005 11:48:07 +0100 Subject: UTF16 codec doesn't round-trip? Message-ID: (My Python uses UTF16 natively; can someone with UTF32 Python let me know if that behaves differently?) >>> import codecs >>> u'\ud800' # part of surrogate pair u'\ud800' codecs.utf_16_be_encode(_)[0] '\xd8\x00' codecs.utf_16_be_decode(_)[0] Traceback (most recent call last): File "", line 1, in ? UnicodeDecodeError: 'utf16' codec can't decode bytes in position 0-1: unexpected end of data If the ascii can't be recognized as UTF16, then surely the codec shouldn't have allowed it to be encoded in the first place? I could understand if it was trying to decode ascii into (native) UTF32. On a similar note, if you are using UTF32 natively, are you allowed to have raw surrogate escape sequences (paired or otherwise) in unicode literals? Thanks John From david.g.morgenthaler at comcast.net Mon May 23 01:12:10 2005 From: david.g.morgenthaler at comcast.net (david.g.morgenthaler at comcast.net) Date: Sun, 22 May 2005 23:12:10 -0600 Subject: GridCellEditor References: Message-ID: On Sun, 22 May 2005 10:29:50 +0300, "gralex" wrote: >Hi,all! > >How i can manually start CellEditor in wxGrid for spicified Cell in grid in >my programm: > >mygrid.SetGridCursor(2,3) >mygrid.MakeCellVisible(2,3) >#.... starting editing....... ?????????????? >mygrid.ShowCellEditControl() don't working... > >help me, please... > Try: mygrid..EnableCellEditControl(True) From Jan.Wienhausen at Physnet.uni-hamburg.de Wed May 18 08:39:43 2005 From: Jan.Wienhausen at Physnet.uni-hamburg.de (Jan Wienhausen) Date: Wed, 18 May 2005 14:39:43 +0200 Subject: soundcard readout on a windows system Message-ID: Hi, I would like to read out the soundcard with python on a win system. Is there any possibillity to do so? Thanks, Jan From none Wed May 11 11:56:56 2005 From: none (Hansan) Date: Wed, 11 May 2005 17:56:56 +0200 Subject: Problem combining python code and html Message-ID: <42822b3d$0$653$ba624c82@nntp02.dk.telia.net> Hi all, I hope you have time to help me out a little. My problem is that I want to combine some python code I have made with some html templates, I found a tutorial at dev shed: http://devshed.spunge.org/Server_Side/Python/CGI/page6.html and : http://devshed.spunge.org/Server_Side/Python/CGI/page5.html and tried to do it like they do, but it doesn't work. I used the same code they use for making the two display functions and the same template for the html form. I even tried using the form template they use too, but it still dosnt work. I will now show how the functions and templates look like. The two display functions are: def Display(Content): TemplateHandle = open(TemplateFile, "r") TemplateInput = TemplateHandle.read() TemplateHandle.close() BadTemplateException = "There was a problem with the HTML template." SubResult = re.subn("", Content,TemplateInput) if SubResult[1] == 0: raise BadTemplateException print "Content-Type: text/html\n\n" print SubResult[0] def DisplayForm(): FormHandle = open(FormFile, "r") FormInput = FormHandle.read() FormHandle.close() Display(FormInput) The html template form is: Title and the form template is:

Signin number:

Code:

A very simple code that should tjeck if the code works could be #!/pack/python-2.3.2/bin/python2.3 import re import cgi FormFile = "forma.html" TemplateFile = "template.html" def Display(Content): TemplateHandle = open(TemplateFile, "r") TemplateInput = TemplateHandle.read() TemplateHandle.close() BadTemplateException = "There was a problem with the HTML template." SubResult = re.subn("", Content,TemplateInput) if SubResult[1] == 0: raise BadTemplateException print "Content-Type: text/html\n\n" print SubResult[0] def DisplayForm(): FormHandle = open(FormFile, "r") FormInput = FormHandle.read() FormHandle.close() Display(FormInput) if not form.has_key('action'): DisplayForm() else: print "I had a key" The meaning of this little code is, that the first time the script is run, the form has to be displayed, and when the submit button is pressed the script reloades, now the script has the key "action" and something else is being done. But I get the error message: error: multiple repeat args = ('multiple repeat',) ", Content,TemplateInput) File "/home//Python-2.3.2//lib/python2.3/sre.py", line 151, in subn return _compile(pattern, 0).subn(repl, string, count) I tried making the templates global, but that dosnt help either. Is the code from dev shed wrong, or am I doing something wrong. And is there a nother way to combine python code and html templates? Thanks for your time From jaydonnell at gmail.com Wed May 4 19:35:51 2005 From: jaydonnell at gmail.com (jdonnell) Date: 4 May 2005 16:35:51 -0700 Subject: adodb, sql server, and last insert id In-Reply-To: References: <1115078248.036051.182310@l41g2000cwc.googlegroups.com> Message-ID: <1115249751.231713.97200@g14g2000cwa.googlegroups.com> Thanks for the reply. I found that before I posted, but that doesn't look thread safe and I haven't found anything that says it is or isn't. From sjmachin at lexicon.net Wed May 11 20:55:40 2005 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2005 10:55:40 +1000 Subject: Problems with csv module References: <17026.15830.303909.792010@montanaro.dyndns.org> Message-ID: <4n8581hlta0e1jbp0nidliuam6fmb08nv1@4ax.com> On Wed, 11 May 2005 20:02:25 +0200, "Fredrik Lundh" wrote: >Skip Montanaro wrote: > >> Fredrik> does the CSV format even support Unicode-encoded data streams? >> >> Based on the requests I've seen here and on the csv at mojam.com mailing list, >> it appears people are certainly generating CSV files which contain Unicode- >> encoded data. > >in what encodings? > >is the encoding specified inside the file? if so, how? > >(it should be noted that the phrase "Unicode-encoded data" that I >used doesn't make much sense, even in the original context. what >I meant to say was that CSV, as far as I know, isn't defined as a >stream of Unicode character, but rather as a stream of bytes in an >ASCII-compatible encoding. this means that you can use e.g. ISO- >8859-1 or UTF-8 for string values, but not that you can encode the >whole thing as, say UTF-16 or UCS-4). The CSV format is not defined at all, AFAIK. Empirically, writing CSV works more-or-less like this, for each row: # pseudocode, untested control_chars = '\r\n' # or maybe more or maybe just '\n' out_list = [] for each field: if field contains quote_char: out_field = quote_char + \ field.replace(quote_char, quote_char + quote_char) + \ quote_char elif field contains any one of delimiter or control_chars: out_field = quote_char + field + quote_char else: out_field = field out_list.append(out_field) then you write delimiter.join(out_list) followed by "\r\n" So there is no reason at all why a writer and a reader couldn't use the above quoting mechanism to transfer columnar data containing Unicode -- they just have to agree on the encoding, control characters, quote_char, delimiter, and line terminator. Excel (see my other post in this thread) provides a writing ("save as Unicode text") and reading mechanism which uses u'\t' as the delimiter, u'\r\n' as the line terminator, u'\"' as the quote_char, and utf-16 as the encoding. I haven't done an exhaustive check to see what its definition of control_chars would be. From steve at REMOVETHIScyber.com.au Sun May 29 07:42:54 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 29 May 2005 21:42:54 +1000 Subject: Is there a better way of doing this? References: Message-ID: On Sat, 28 May 2005 13:24:19 +0000, Michael wrote: > Hi, > I'm fairly new at Python, and have the following code that works but isn't > very concise, is there a better way of writing it?? It seems much more > lengthy than python code i have read..... :-) > (takes a C++ block and extracts the namespaces from it) Does it work? If Yes, then "if it works, don't fix it". Is it fast enough? If Yes, then "don't optimise prematurely". Does it do everything you need it to do? If Yes, then "know when to stop programming". Is it written in good Python style? If Yes, then "leave it alone". The last one is the most difficult, because nobody agrees what good Python style is. A lot of it depends on who is going to be reading your code. Personally, I worry about folks who try to turn every piece of code into a one-liner. If you want to write perl, write perl. Just because you can write something as a nested list comprehension doesn't mean you should. Having said that, I'll make some stylistic suggestions: > def ExtractNamespaces(data): > print("Extracting Namespaces") print is a statement, not a function. The brackets are syntactically correct, but pointless. Remove them. > p = re.compile( 'namespace (?P[\w]*)[\n\t ]*{') > > subNamespaces = [] > > newNS = p.search(data) > while( newNS ): Guido (our Benevolent Dictator For Life and creator of Python) hates seeing whitespace next to parentheses. I agree with him. while(newNS) good, while( newNS ) bad. See http://www.python.org/doc/essays/styleguide.html for Guido's suggestions. > print "\t" + newNS.group("name") > > OPCount = 1 > Offset = newNS.end() > while(OPCount > 0): > if( data[Offset] == "}" ): See above comment about whitespace inside brackets. More importantly, you don't need the brackets at all. You can write: if data[Offset] == "}": which is less visually confusing. The only time I use brackets in an if statement is to clarify complex Boolean expressions, eg if myFlag and ((somevalue == 3) or (num_fibberts != 1)): Otherwise, drop the brackets. > OPCount = OPCount -1; You aren't writing Pascal or C now, so you don't need the semi-colon. The semi-colon isn't wrong, as such, since Python allows you to put multiple statements on a single line separated with semi-colons, but it isn't recommended and will give away the fact that you are (1) a newbie and (2) not really comfortable with Python. In more recent versions of Python, you can also write that as OPCount -= 1 > elif( data[Offset] == "{" ): > OPCount = OPCount + 1; > Offset = Offset+1; Again, drop the brackets from the elif statement and the semi-colons. Not the colons, they are required! > #Extract Data: More comments! Comments are good. There are those who claim that you should write more comments than code. I don't quite agree with that, but more detailed comments would not go astray. > newNSData = data[newNS.end():Offset-1] > data = data[0:newNS.start()] + data[Offset:] > newNamespace = [newNS.group("name"), newNSData]; > subNamespaces.append(newNamespace) By now you should be sick of me telling you not to use semi-colons. > #Perform NewSearch > newNS = p.search(data) > return [subNamespaces,data] A single space after commas helps make the phrase more readable. Other than those stylistic comments, and the need for more comments, it looks good to me. -- Steven From bokr at oz.net Mon May 16 13:31:18 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 16 May 2005 17:31:18 GMT Subject: question about the id() References: <428809fc.62d7a08a.1cfe.ffffd7ef@mx.gmail.com> <873bsnxhe0.fsf@hector.domek> Message-ID: <4288d8a8.86909138@news.oz.net> On Mon, 16 May 2005 16:57:12 GMT, Andrew Dalke wrote: >Peter Dembinski wrote: >> So, the interpreter creates new 'point in address space' every time >> there is object-dot-method invocation in program? > >Yes. That's why some code hand-optimizes inner loops by hoisting >the bound objection creation, as > >data = [] >data_append = data.append >for x in some_other_data: > .... work with x to make y .... > data_append(y) > Sorry about the me-too. I hadn't seen your post. I should know better ;-) Regards, Bengt Richter From http Wed May 11 00:25:21 2005 From: http (Paul Rubin) Date: 10 May 2005 21:25:21 -0700 Subject: pyvm -- faster python References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> Message-ID: <7xpsvymlse.fsf@ruckus.brouhaha.com> "Roger Binns" writes: > Err, you proved my point! Prothon was fine at the VM level. The > author couldn't figure out how to get a decent sized "standard" > library, and ultimately ended up abandoning his VM for .Net since > that gets you a large standard library. Jython also gets a large > standard library from the Java ones. What kind of stuff is in the existing Python C library that couldn't be reimplemented or retargeted pretty easily? Most of it is either wrappers for standard C functions (system calls), stuff that shouldn't be in C in the first place (the Python compiler and interpreter), etc. I hope that PyPy will replace CPython once it's solid enough. Trying to stay backwards compatible with the legacy C API doesn't seem to me to be that important a goal. Redoing the library may take more work than the Prothon guy was willing to do for Prothon, but PyPy has more community interest and maybe can attract more resources. From teamuhlig at gmail.com Wed May 18 11:37:00 2005 From: teamuhlig at gmail.com (john67) Date: 18 May 2005 08:37:00 -0700 Subject: Is Python suitable for a huge, enterprise size app? Message-ID: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> The company I work for is about to embark on developing a commercial application that will cost us tens-of-millions to develop. When all is said and done it will have thousands of business objects/classes, some of which will have hundreds-of-thousands of instances stored in a DB. Our clients will probably have somewhere between 50-200 users working on the app during the day, possibly in mutiple offices, and then a large number of batch processes will have to run each night. It will also need to have a web interface for certain users. It needs to be robust, easy to maintain, and able to be customized for each client. Right now it looks like Java is the language of choice that the app will be developed in. However, I have been looking and reading a lot about Python recently and it seems to me that Python could handle it. The big attraction to me is the developer productivity. It seems that if Python can handle it, then we could gain a huge savings by using Python instead of Java from a productivity standpoint alone. So, given the very general requirements in the first paragraph, do you think that Python could handle it? If anyone has direct experience developing large apps in Python, I would appreciate your insight. Based on the responses I get, I am planning on writing a proposal to my management to consider Python instead of Java. Thanks, John From francescomoi at europe.com Fri May 13 09:56:02 2005 From: francescomoi at europe.com (francescomoi at europe.com) Date: 13 May 2005 06:56:02 -0700 Subject: MySQL: 'latin-1' codec can't encode character In-Reply-To: References: <1115990748.006171.96240@g49g2000cwa.googlegroups.com> Message-ID: <1115992562.777210.49050@o13g2000cwo.googlegroups.com> Hi Fredrik. Thank you very much for your quick answer. Do you suggest to change it by using regexp or must I encode the whole texto into a suitable one? Regards. Fredrik Lundh wrote: > "francescomoi at europe.com" > > > I'm trying to store a text within a MySQL field (v 3.23.58) by using > > MySQLdb > > (v 1.2.1c3). > > > > The text is: "telephone..." (note the last character) > > > > And I get this error message: > > ----------- > > File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line > > 33, in defaulterrorhandler > > raise errorclass, errorvalue > > UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2026' in > > position 288: ordinal not in range(256) > > ----------------------- > > > > Position 288 is the character I've mentioned. I suppose I must encode > > this caracter > > into a right one which MySQL could store, but I have no idea about how > > to perform > > it. Any suggestion? > > the character \u2026 is not part of the ISO-8859-1 character set. if you > insist on storing that in 8-bit string, you have to find an 8-bit encoding > that includes that character (UTF-8 is one such alternative). > > if MySQL is set to store ISO-8859-1 only, you can replace the character > with it with three periods, drop it (use the "ignore" encoding option) or > replace it with a suitable marker (use the "replace" encoding option). > > From luismgz at gmail.com Mon May 16 01:56:56 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 15 May 2005 22:56:56 -0700 Subject: installing mod_python with python 2.4 on Windows xp In-Reply-To: <1116221513.055871.238690@z14g2000cwz.googlegroups.com> References: <1116221513.055871.238690@z14g2000cwz.googlegroups.com> Message-ID: <1116223016.966152.259370@z14g2000cwz.googlegroups.com> Thanks for the suggestion. The reason I didn't post this question in mod_python's list is because somebody already asked this question there, but he got only one reply. Anyway I followed this advice but it didn't work, so I thought that maybe I could get the answer here. I'll try again though to see what happens... Thanks! Luis From claw at kanga.nu Sun May 8 18:59:40 2005 From: claw at kanga.nu (J C Lawrence) Date: Sun, 8 May 2005 15:59:40 -0700 Subject: How to implement multiple constructors References: <1115588999.677872.174250@z14g2000cwz.googlegroups.com> Message-ID: <20050508225938.29816.45261.XPN@kanga.nu> tron.thomas at verizon.net wrote: > I am a C++ developer with only a little experience using Python. I > want to create a Python class where by I can construct an instance from > that class based on one of two different object types. The approaches I've seen used are to use a new class method as an alternate ctor with a special name, and to use the types module for type comparison within such a ctor. -- J C Lawrence They said, "You have a blue guitar, ---------(*) You do not play things as they are." claw at kanga.nu The man replied, "Things as they are http://www.kanga.nu/~claw/ Are changed upon the blue guitar." From lists.munckfish at blueyonder.co.uk Sun May 22 11:01:26 2005 From: lists.munckfish at blueyonder.co.uk (Dan M) Date: Sun, 22 May 2005 15:01:26 GMT Subject: Parsing XML - Newbie help In-Reply-To: <1116701614.858127.105550@g47g2000cwa.googlegroups.com> References: <1116701614.858127.105550@g47g2000cwa.googlegroups.com> Message-ID: Hi rh0dium wrote: > I am relatively new to python and certainly new to XML parsing. Me too. However there are plenty of good docs/tutorials available to help with both XML and using it in Python. For XML you may wish to look at http://www.w3schools.com/. It has a very accessible set of tutorials on XML and related technologies, which I find make it very quick to get up and running. For what you are trying to do you may wish to look at XPath, or ideally XQuery although I'm not sure there is an XQuery implementation in Python. For Python and XML there is Mark Pilgrim's excellent chapter on Parsing XML with xml.dom.minidom (http://diveintopython.org/xml_processing/index.html). The is also the PyXML project at Sourceforge (http://pyxml.sourceforge.net/). A list of useful links is maintained there (http://pyxml.sourceforge.net/topics/). You may also wish to investigate resources at the Python XML SIG page (http://www.python.org/sigs/xml-sig/). These are just some of the sources of information I am using. Hope this helps. Cheers Dan From jaime.suarez at crossmatch.net Fri May 13 13:07:46 2005 From: jaime.suarez at crossmatch.net (jaime.suarez at crossmatch.net) Date: 13 May 2005 10:07:46 -0700 Subject: tkFileDialog question In-Reply-To: References: <1115937784.883303.131080@f14g2000cwb.googlegroups.com> Message-ID: <1116004066.138533.166560@g14g2000cwa.googlegroups.com> James, thank you very much for your answer. Jaime From john at castleamber.com Fri May 13 12:28:20 2005 From: john at castleamber.com (John Bokma) Date: 13 May 2005 16:28:20 GMT Subject: New Python regex Doc References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> <1115423751.016177.250650@o13g2000cwo.googlegroups.com> <1115444726.627426.172260@g14g2000cwa.googlegroups.com> <1115508491.462229.294020@o13g2000cwo.googlegroups.com> <1115972089.922875.108380@g14g2000cwa.googlegroups.com> Message-ID: wrote: > In comp.lang.perl.misc John Bokma wrote: [ @55, |@#~~|!! ] > Oh please let him use an ass... Ok, he is allowed to use ass in examples, e.g. (Perl) s/ass/domesticated donkey/g; (Maybe to explain \b ? ) -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From fredrik at pythonware.com Tue May 10 02:50:09 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 10 May 2005 08:50:09 +0200 Subject: Exception in Python 2.3.3 Interpreter References: <1114434259.853654.272420@z14g2000cwz.googlegroups.com> Message-ID: "Saravanan D" wrote: > > > 03 023ffaa4 1e013182 00000000 055b1250 00637470 python23!cmp_outcome(int > op > > > = 88026108, struct _object * v = 0x00000001, struct _object * w = > > > 0x00000000)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880] > > > 04 023ffb18 1e016ba4 014f3318 00000002 0099f170 > python23!eval_frame(struct > > > _frame * f = 0x053f2bfc)+0x542 > [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c > > > @ 1965] > > > 05 023ffb30 1e016a69 0099f170 023ffb7c 00000002 > > > python23!fast_function(struct _object * func = , > struct > > > _object *** pp_stack = , int n = error>, > > > int na = , int nk = )+0x94 > > > > the above doesn't look very healthy. does your application involve > > non-standard extensions (including extensions you've written your- > > self)? does the extensions contain callbacks into Python code? > > > > My application uses extension modules which devliers the callbacks to Python > Code. Im using SWIG 1.3.19 version to generate relevant python interfaces > for the C++ code. how are you accessing the callbacks? if you're doing that from threads created at the C++ level, you must make sure that the thread state is properly set up. see: do you keep track of the thread state, so that callbacks run in the same state as they were registered in? From compaq71127 at yahoo.com Mon May 30 16:03:57 2005 From: compaq71127 at yahoo.com (compaq71127 at yahoo.com) Date: 30 May 2005 13:03:57 -0700 Subject: (", ) Print This! Press [Ctrl][P] Keys To Print... >> http://www.phpbbserver.com/phpbb/viewtopic.php?t=2&mforum=anysubjectchat < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < Message-ID: <1117483437.158789.86320@o13g2000cwo.googlegroups.com> (",) Print This! Press [Ctrl][P] Keys To Print... >> http://www.phpbbserver.com/phpbb/viewtopic.php?t=2&mforum=anysubjectchat < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < From grante at visi.com Thu May 5 22:45:27 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 06 May 2005 02:45:27 -0000 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: <117lmi7r7etpd14@corp.supernews.com> On 2005-05-05, Erik Max Francis wrote: > Especially since all of his examples have the same number of > significant digits (3), as the term is usually meant. Zeroes > to the right are significant, not zeroes to the left. And only the person who performed the measurement knows how many of the zeros to the right are significant. -- Grant Edwards grante Yow! They don't hire at PERSONAL PINHEADS, visi.com Mr. Toad! From python at chrisli.org Thu May 26 10:29:18 2005 From: python at chrisli.org (Christopher Li) Date: Thu, 26 May 2005 10:29:18 -0400 Subject: [PATCH] add offset argument to mmap Message-ID: <20050526142918.GA1627@64m.dyndns.org> I am surprised to find out the mmap module in python always mmap from offset 0. So I just hack up some patch to allow it accept offset arguments. So here it is. Chris Add optional offset argument to mmap module. Test on linux with Python 2.4. The windows code is totally untested. Signed-Off-by: Christopher Li Index: Modules/mmapmodule.c =================================================================== --- Modules.orig/mmapmodule.c 2004-05-19 10:39:08.000000000 -0400 +++ Modules/mmapmodule.c 2005-05-26 10:01:51.000000000 -0400 @@ -853,14 +853,17 @@ mmap_object *m_obj; PyObject *map_size_obj = NULL; int map_size; + unsigned long offset = 0; int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ; access_mode access = ACCESS_DEFAULT; char *keywords[] = {"fileno", "length", "flags", "prot", - "access", NULL}; + "access", "offset", + NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|iii", keywords, - &fd, &map_size_obj, &flags, &prot, &access)) + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|iiil", keywords, + &fd, &map_size_obj, &flags, &prot, + &access, &offset)) return NULL; map_size = _GetMapSize(map_size_obj); if (map_size < 0) @@ -910,7 +913,7 @@ m_obj->fd = fd; m_obj->data = mmap(NULL, map_size, prot, flags, - fd, 0); + fd, offset); if (m_obj->data == (char *)-1) { m_obj->data = NULL; Py_DECREF(m_obj); @@ -929,6 +932,7 @@ mmap_object *m_obj; PyObject *map_size_obj = NULL; int map_size; + unsigned long offset = 0; char *tagname = ""; DWORD dwErr = 0; int fileno; @@ -939,9 +943,9 @@ "tagname", "access", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|zi", keywords, + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iO|zil", keywords, &fileno, &map_size_obj, - &tagname, &access)) { + &tagname, &access, &offset)) { return NULL; } @@ -1040,8 +1044,8 @@ if (m_obj->map_handle != NULL) { m_obj->data = (char *) MapViewOfFile (m_obj->map_handle, dwDesiredAccess, - 0, - 0, + offset>>32, + (unsigned int)offset, 0); if (m_obj->data != NULL) { return ((PyObject *) m_obj); From bill.mill at gmail.com Thu May 19 15:19:46 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 19 May 2005 15:19:46 -0400 Subject: Convert from numbers to letters In-Reply-To: <1116529140.470352.129690@z14g2000cwz.googlegroups.com> References: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> <1116519193.037429.93560@o13g2000cwo.googlegroups.com> <1116529140.470352.129690@z14g2000cwz.googlegroups.com> Message-ID: <797fe3d4050519121930a51b76@mail.gmail.com> On 19 May 2005 11:59:00 -0700, rh0dium wrote: > This is great but backwards... > > Ok because you all want to know why.. I need to convert Excel columns > A2 into , [1,0] and I need a simple way to do that.. > > ( The way this works is A->0 and 2->1 -- Yes they interchange -- So > B14 == [13,1] ) why didn't you say this in the first place? def coord2tuple(coord): row, col = '', '' alpha = 'abcdefghijklmnopqrstuvwxyz'.upper() pairs = [''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]] pairs = sorted(pairs, key=len) coord = coord.upper() for c in coord: if c in alpha: row += c else: col += c return (int(col)-1, pairs.index(row)) >>> coord2tuple('B14') (13, 1) >>> coord2tuple('ZZ14') (13, 701) >>> coord2tuple('ZZ175') (174, 701) >>> coord2tuple('A2') (1, 0) Are there cols greater than ZZ? I seem to remember that there are not, but I could be wrong. Hope this helps. Peace Bill Mill bill.mill at gmail.com From Amitpython5 at aol.com Fri May 20 16:05:59 2005 From: Amitpython5 at aol.com (Amitpython5 at aol.com) Date: Fri, 20 May 2005 16:05:59 EDT Subject: Difficulty installing PyXml. Message-ID: <219.1358c5b.2fbf9d27@aol.com> Hello, I have python installed under a different directory (/images/QA/QATools12/lib/python2.1), and I'm now trying to install PyXml. It gives me the following error: -> python setup.py build Traceback (most recent call last): File "setup.py", line 127, in ? config_h_vars = parse_config_h(open(config_h)) IOError: [Errno 2] No such file or directory: /images/QA/QATools12/include/python2.1/config.h' Is there any way to circumvent this? I guess, there is some error in my distutils package, but I really need a way to get around this. I need PyXml before I can use Soapy. Thanks, Amit. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffelkins at earthlink.net Sun May 22 01:46:44 2005 From: jeffelkins at earthlink.net (Jeff Elkins) Date: Sun, 22 May 2005 01:46:44 -0400 Subject: SQL Query via python In-Reply-To: <200505211500.06747.jeffelkins@earthlink.net> References: <200505211500.06747.jeffelkins@earthlink.net> Message-ID: <200505220146.44809.jeffelkins@earthlink.net> Just as an fyi: In one weekend I have gone from knowing zip about SQL/Python to implementing code on my personal server that emails info to family about birthdays and such. I know I could have installed other *nix programs that would do the same thing, but so what :) Thanks so much to the folks on this list who took the trouble to reply. I hope I can pay it forward in the future. Jeff Elkins From flamesrock at gmail.com Thu May 26 01:25:52 2005 From: flamesrock at gmail.com (flamesrock) Date: 25 May 2005 22:25:52 -0700 Subject: urllib2 and SSL In-Reply-To: References: Message-ID: <1117085151.968298.160740@f14g2000cwb.googlegroups.com> don't you need to install openSSL? I'm not sure. From superprad at gmail.com Fri May 13 14:12:48 2005 From: superprad at gmail.com (superprad at gmail.com) Date: 13 May 2005 11:12:48 -0700 Subject: create words of various lengths In-Reply-To: References: <1116002403.374232.210220@g49g2000cwa.googlegroups.com> <1116005453.047943.153790@g14g2000cwa.googlegroups.com> Message-ID: <1116007968.472411.300000@g44g2000cwa.googlegroups.com> :) the reason for me not upgrading my python is I am waiting for version of Numeric to be released for python 2.4 .The stable version of Numeric is only release for windows and not Linux I guess the last time i checked. which i use a lot . Anyway thanks From http Thu May 12 14:57:00 2005 From: http (Paul Rubin) Date: 12 May 2005 11:57:00 -0700 Subject: urllib download insanity References: <4282EE0E.1080100@open-networks.net> Message-ID: <7xsm0s8e83.fsf@ruckus.brouhaha.com> Skip Montanaro writes: > Timothy> downloading the OLD file i've deleted! if i download it via IE, > Timothy> i get the new file. SO, my only conculsion is that urllib is > Timothy> caching it some where. BUT i'm already calling urlcleanup(), so > Timothy> what else can i do? here is the code > > Is there a proxy between you and the web server? IE also caches extremely aggressively itself. There are a lot of different HTTP headers that affect caching. You have to set ALL of them to not cache. You have to set the cache control header AND set an expiration date in the past, and maybe a couple other things like that too. From mwm at mired.org Fri May 6 16:16:37 2005 From: mwm at mired.org (Mike Meyer) Date: Fri, 06 May 2005 15:16:37 -0500 Subject: Getting number of iteration References: Message-ID: <86ll6s5cuy.fsf@guru.mired.org> Bill Mill writes: > On 5/6/05, Florian Lindner wrote: >> Hello, >> when I'm iterating through a list with: >> >> for x in list: >> >> how can I get the number of the current iteration? > Earlier: > > n = 0 > for x in lst: > print "iteration %d on element %s" % (n, x) > n += 1 Just for the record, the old idiom was: for n in xrange(len(lst)): x = lst[n] print "iteration %d on element %s" % (n, x) http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lreder at worldnet.att.net Sun May 29 02:02:37 2005 From: lreder at worldnet.att.net (Leonard J. Reder) Date: Sun, 29 May 2005 06:02:37 GMT Subject: SWIG std::string& passing Message-ID: <1Wcme.850166$w62.249676@bgtnsc05-news.ops.worldnet.att.net> Hello, I have been trying to get this simple call to work with a SWIG interface. The problem is I do not know how to pass a const char * or a std::string & in python to SWIG wrapped code. I tried several of the *.i libraries at http://www.swig.org/Doc1.3/Library.html. Most notably the "std_string.i" And get the following: >>> w.SetDestFilename("test.bmp") Traceback (most recent call last): File "", line 1, in ? File "/home/soa/dev/users/reder/Dshell++Pkg-reder01/lib/PYTHON/Dspace/Dnoise_Py.py", line 1340, in SetDestFilename def SetDestFilename(*args): return _Dnoise_Py.WriterBMP_SetDestFilename(*args) TypeError: argument number 2: a 'std::string *' is expected, 'str(test.bmp)' is received The C++ method is: void WriterBMP::SetDestFilename (const std::string& filename) This should be easy to pass the filename to? Do you have an example? What do I add to the *.i file? Thanks for any and all replies, Len -- =================================== Leonard J. Reder Home office email : reder at ieee.org Lab email : reder at jpl.nasa.gov Lab web page : http://reder.jpl.nasa.gov =================================== -- =================================== Leonard J. Reder Home office email : reder at ieee.org Lab email : reder at jpl.nasa.gov Lab web page : http://reder.jpl.nasa.gov =================================== From gh at ghaering.de Mon May 23 12:33:40 2005 From: gh at ghaering.de (Gerhard Haering) Date: Mon, 23 May 2005 18:33:40 +0200 Subject: SQL Query via python In-Reply-To: References: Message-ID: <20050523163340.GB13539@mylene.ghaering.de> On Mon, May 23, 2005 at 04:12:31PM +0000, Austyn Bontrager wrote: > How about: > > cursor.execute(""" > SELECT name, month, day ,category, city FROM bday > WHERE %(col_name)s = %%s > """ % dict(col_name=arg1), > (arg2) > ) > > The "%(col_name)s" will be replaced by normal Python string > substitution, while the "%%s" will be quoted by the db module. > > Watch out for SQL injection in arg1, though! Maybe check beforehand that > it is a string containing only word characters... Maybe what you really need is the ability to search for two fields, or both fields? Here's an approach that I usually use: - Write a search function accepting the parameters you search for. - If you fill one of the parameters with None (in SQL: NULL), you don't care for its value - This way, you can narrow your search as much as you like Here's a quick test script, using pysqlite2 to demonstrate the approach. It's also not meant as production code, but at least it only works with SQL parameter binding. - SQLite uses :name for named parameters instead of %(name)s. - locals() is a neat hack to access the local variables as a dictionary #v+ from pysqlite2 import dbapi2 as sqlite con = sqlite.connect(":memory:") cur = con.cursor() cur.execute("create table test(a, b)") cur.execute("insert into test(a, b) values (1, 2)") cur.execute("insert into test(a, b) values (1, 3)") cur.execute("insert into test(a, b) values (2, 3)") def search(a, b): global cur cur.execute(""" select a, b from test where (:a is null or a=:a) and (:b is null or b=:b) """, locals()) return cur.fetchall() print search(2, None) print "-" * 50 print search(None, 3) print "-" * 50 print search(2, 3) #v- -- Gerhard -- Gerhard H?ring - gh at ghaering.de - Python, web & database development -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From steve at holdenweb.com Sun May 22 09:14:43 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 22 May 2005 09:14:43 -0400 Subject: python24.zip In-Reply-To: <428F8901.5000300@jessikat.fsnet.co.uk> References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> <428F8901.5000300@jessikat.fsnet.co.uk> Message-ID: <429085C3.8040805@holdenweb.com> Robin Becker wrote: > Dieter Maurer wrote: [...] > > I think this was my intention, but also I think I have some concern over > having two possible locations for the standard library. It seems non pythonic > and liable to cause confusion if some package should manage to install > python24.zip while I believe that python24\lib is being used. > > >>I recently analysed excessive import times and >>saw thousands of costly and unneccesary filesystem operations due to: >> >> * long "sys.path", especially containing non-existing objects >> >> Although non-existent, about 5 filesystem operations are >> tried on them for any module not yet located. >> >> * a severe weakness in Python's import hook treatment >> >> When there is an importer "i" for a path "p" and >> this importer cannot find module "m", then "p" is >> treated as a directory and 5 file system operations >> are tried to locate "p/m". Of course, all of them fail >> when "p" happens to be a zip archive. >> >> >>Dieter > > > I suppose that's a reason for eliminating duplicates and non-existent entries. > There are some aspects of Python's initialization that are IMHO a bit too filesystem-dependent. I mentioned one in http://sourceforge.net/tracker/index.php?func=detail&aid=1116520&group_id=5470&atid=105470 but I'd appreciate further support. Ideally there should be some means for hooked import mechanisms to provide answers that are currently sought from the filestore. regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From http Tue May 10 13:42:37 2005 From: http (Paul Rubin) Date: 10 May 2005 10:42:37 -0700 Subject: Unique Elements in a List References: <1115676903.432187.294910@z14g2000cwz.googlegroups.com> <7xbr7jq3gb.fsf@ruckus.brouhaha.com> Message-ID: <7xu0lb0ygi.fsf@ruckus.brouhaha.com> "Fredrik Lundh" writes: > you forgot enumerate() Oh, oops. > and if you fix that, you'll notice that the output doesn't quite match > the OP's spec: > > > what I am looking for is the unique elements 0.4 and 0.9 with their > > index from the list. Oh, I see, he wanted the elements that only occur once. I misunderstood. From http Thu May 5 16:56:27 2005 From: http (Paul Rubin) Date: 05 May 2005 13:56:27 -0700 Subject: Encryption with Python? References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com> Message-ID: <7xoebpie84.fsf@ruckus.brouhaha.com> "Blake T. Garretson" writes: > I want to save some sensitive data (passwords, PIN numbers, etc.) to > disk in a secure manner in one of my programs. What is the > easiest/best way to accomplish strong file encryption in Python? Any > modern block cipher will do: AES, Blowfish, etc. I'm not looking for > public key stuff; I just want to provide a pass-phrase. http://www.nightsong.com/phr/crypto/p3.py It uses SHA1 in OFB mode and is fairly fast for a pure Python function. > I found a few modules out there, but they seem to be all but abandoned. > Most seem to have died several years ago. The most promising package > is A.M. Kuchling's Python Cryptography Toolkit > (http://www.amk.ca/python/code/crypto.html). Nice toolkit, more flexible and powerful than p3.py, but also more complicated. From exarkun at divmod.com Wed May 4 17:54:20 2005 From: exarkun at divmod.com (Jp Calderone) Date: Wed, 04 May 2005 21:54:20 GMT Subject: Bandwith Shaping In-Reply-To: 0 Message-ID: <20050504215420.15422.1240405332.divmod.quotient.18686@ohm> On 4 May 2005 10:48:41 -0700, flamesrock wrote: >Just curious - is there an easy way to shape bandwith in python. If I >wanted to have a max download speed for instance > Twisted includes an HTB implementation. http://twistedmatrix.com/documents/current/api/twisted.protocols.htb.html Jp From dave at pythonapocrypha.com Mon May 16 11:28:05 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Mon, 16 May 2005 09:28:05 -0600 Subject: Structuring larger applications - ideas In-Reply-To: <1116255787.625276.221670@g14g2000cwa.googlegroups.com> References: <1116255787.625276.221670@g14g2000cwa.googlegroups.com> Message-ID: <4288BC05.9010008@pythonapocrypha.com> iv at lantic.net wrote: > I'm busy with a large application and feel it would eas my work if I > can specify dependencies on the granularity of packages, rather than > modules and classes. Eg: > > - By convention I do the one class per file thing. SO in python this > means one class per module - naming classes after their modules. (this > helps with version control, and several other little irritations, for > example) > - I'd like to specify once for a _package_ that it depends upon another > _package_. > - The following should then also be true for a module A in package X > (which depends upon package Y): > 1) X should be available in the namespaces of module A (in fact for > all modules in X) > 2) X.B should refer to X.B.B (I name classes after their modules). > > (2) Can be done easily by, eg putting the following in X.__init__.py: > from B import B > > What's the feeling in this group about the idea & plans to get closer > to accimplishing it? My two cents: one of the advantages of a language like Python is that the project reaches an unmanageable size more slowly than in many other languages. As such, be wary of "importing" conventions you have used in other languages. Many will apply, some will not. IMO, the one-class-per-module is a convention that in and of itself doesn't add much value (it drove me crazy in Java), and only accelerates your project towards being tough to manage - you don't want to artificially introduce complexity. If two classes are inherently tied together and closely related, is there an advantage to forcing them to live in separate files? The costs of doing so include manually tracking a relationship that would normally be implied and obvious, keeping file versions in synch (seems like this makes version control harder), and some extra code to bring them into each others' namespaces. Much like a class encapsulates many details and pieces of functionality into a larger, more powerful building block, a module often does the same thing on a larger scale (and a package on an even larger one). So if it makes sense in a few cases to restrict yourself to a single class per module, go for it, but I don't see the value in adopting it as a convention (maybe I'm missing something?). As for inter-package dependencies, what problem are you trying to solve? If you are trying to track dependencies for documentation purposes, you could just write a script to walk the source tree and detect the dependencies - it is information contained in the code itself, so rather than tracking it manually, you could just "ask" it. If you are trying to organize the overall structure of the project, then the consumer of that info is likely to be a person, so a piece of paper, a whiteboard, or a big fat docstring might be a better suited home for it. -Dave From removethis.kartic.krishnamurthy at gmail.com Mon May 2 18:29:38 2005 From: removethis.kartic.krishnamurthy at gmail.com (Kartic) Date: Mon, 02 May 2005 22:29:38 GMT Subject: How close program in the wxPython? In-Reply-To: <1115056835.472334.163220@z14g2000cwz.googlegroups.com> References: <1115056835.472334.163220@z14g2000cwz.googlegroups.com> Message-ID: The Great 'Tian' uttered these words on 5/2/2005 2:00 PM: > I have made a program in wxpython, but how could i exit the program? I > am using wxFrame for my window, what is the function to close the > program? > > Thanks!! > Tian, See below: --- CloseDemo.pyw ---- import wx class MainFrame(wx.Frame): def __init__(self, parent, id, title, size, pos,\ style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE): wx.Frame.__init__(self, parent, id, title, size, pos, style) # Bind close event here self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) self.Show(True) #OnCloseWindow is executed when EVT_CLOSE is received def OnCloseWindow(self, evt): print 'OnCloseWindow() called' #Do other clean up action #and destroy frame self.Destroy() app = wx.PySimpleApp() frame = MainFrame(None, -1, "Test Close Event", (-1,-1), (-1,-1)) app.MainLoop() ---------------------- Hope that helped. Thanks, -Kartic From stephane.bronsart at teledisnet.be Wed May 11 13:23:25 2005 From: stephane.bronsart at teledisnet.be (StepH) Date: Wed, 11 May 2005 19:23:25 +0200 Subject: Python 2.4 & BLT ? In-Reply-To: References: <4280f791$0$344$4d4efb8e@read.news.be.uu.net> Message-ID: <42823F8D.6010705@teledisnet.be> Ron Adam a ?crit : > StepH wrote: > >> Hi, >> >> I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) >> distibution... >> >> I'v try to download btlz-for-8.3.exe, but when i try to install it, >> i've a msgbox saying to the file is corrupt... >> >> Any idea ? >> >> Thanks. >> >> StepH. > > > Have you tried blt2.4z-for-8.4exe? > > http://blt.sourceforge.net yes. When i try to execute it, a small msgbox apprea with the msg: Corrupt installation detected! Any idea ? > > > _Ron > > From http Thu May 12 17:51:57 2005 From: http (Paul Rubin) Date: 12 May 2005 14:51:57 -0700 Subject: pyvm -- faster python References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> <1115791624.856252.247890@z14g2000cwz.googlegroups.com> <7x1x8el18e.fsf@ruckus.brouhaha.com> <3eg2vnF2psplU1@individual.net> <7xis1pqdt0.fsf@ruckus.brouhaha.com> <7xbr7g8cni.fsf@ruckus.brouhaha.com> Message-ID: <7xwtq4i03m.fsf@ruckus.brouhaha.com> Rocco Moretti writes: > Python, as a procedural language, makes extensive use of globals & > mutable variables.... IIUC, in Lisp, as a functional language, "all > politics is local." Global-like variables are much rarer, and > mutability is severely limited. Some people write Lisp code in a functional style, but not everyone. Lisp provides mutable objects as much as Python does--maybe more, for example, Lisp strings are mutable. Overall I'd say there's not much difference between Lisp and Python in this regard. Lisp lets the programmer supply static type declarations that the compiler can use, but those are optional. When you use them, you get faster output code. From steve at holdenweb.com Tue May 10 07:34:54 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 10 May 2005 07:34:54 -0400 Subject: sync dir's In-Reply-To: <42809AA3.9080100@open-networks.net> References: <428043D7.8030203@open-networks.net> <428094F9.4050007@open-networks.net> <42809671.3000506@holdenweb.com> <42809AA3.9080100@open-networks.net> Message-ID: <42809C5E.7080706@holdenweb.com> Timothy Smith wrote: > Steve Holden wrote: > >> Timothy Smith wrote: >> >>> Steve Holden wrote: >>> >>>> Timothy Smith wrote: >>>> >>>> >>>>> what would be the best tool to use to sync my local dir with a >>>>> remote one, say off a http resorce (although i'm open to other >>>>> options there) i haven't gotten any feed back on my problems with >>>>> loading pysvn on win98, and i can apprechiate if the dev's are too >>>>> busy/can't be bothered with win98. but i still need to find a >>>>> solution that can achieve the same result, and i'm starting to look >>>>> for other options. >>>>> >>>>> >>>> >>>> >>>> >>>> You could always take a look at the ftpmirror code in the Tools >>>> subdirectory of your source distro. I've used that several times >>>> with great satisfaction, and it's fairly low-end - all you need is >>>> an FTP server at the other end. >>>> >>>> regards >>>> Steve >>>> >>>> >>> this has to work on both windows and nix's >>> >> >> Indeed. Did I suggest anywhere that it wouldn't? The client can be any >> type of machine that you want, and the server can be most FTP servers. >> >> regards >> Steve > > > oic source distro = python, i assumed you were making a linuxism > Well that's because for everything but Windows (?) you only get Tools if you download the source. IIRC the Tools directory comes in the binary installer (or, at least, I have it somehow in my Windows Python 2.4, but not in my Cygwin Python 2.4. So I mentioned source, but the bottom line is that the code is accessible, even if you have to poke around for it. Generally speaking I try to remain platform agnostic. Since you are looking for a "low tech" solution (i.e. broadly available on most platforms) FTP might just do the job. regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From rkern at ucsd.edu Tue May 10 04:08:47 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 10 May 2005 01:08:47 -0700 Subject: extra a column from a 2-D array? In-Reply-To: <04ab01c55536$8a24a720$7f00a8c0@scl01.siliconcreation.com> References: <04ab01c55536$8a24a720$7f00a8c0@scl01.siliconcreation.com> Message-ID: Joe Wong wrote: > Hello, > > Suppose I have a python array as follow: > > s=[ [1,3,5], > [2,4,6], > [9,8,7]] > > what is the quickest way to extract the second colum from all rows? That > is: [3,4,8] in this example. Use Numeric. http://numeric.scipy.org from Numeric import * s = array([[1,3,5], [2,4,6], [9,8,7]]) print s[:,1] -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From alet at unice.fr Mon May 9 08:13:41 2005 From: alet at unice.fr (Jerome Alet) Date: Mon, 09 May 2005 14:13:41 +0200 Subject: [ANNOUNCE] PyKota v1.22 is out ! Message-ID: I'm pleased to announce the availability of PyKota v1.22 Final. PyKota is a 100% Python written Print Quota and Accounting solution for CUPS and LPRng, published under the terms of the GNU General Public License of the Free Software Foundation, and is available from : http://www.librelogiciel.com/software/PyKota/action_Presentation PyKota's original distribution method consists in providing Official tarballs, DEB and RPM packages for a yearly fee of 20 US$ (minimum), while letting everyone download Unofficial versions of this software free of charge by using Subversion (aka svn). Free subscriptions to Official packages and complete paper documentation are now included for people who prefer to purchase a technical support contract. Finally, single Official packages (without subscription for new releases), can now be purchased directly and anonymously for a one time 9.99 US$ fee. This release is a minor update, and no database changes are necessary if you already use 1.21, so installing it should be really easy. List of changes since 1.21 : ============================ - Introduction of the web-enabled print quote generator : Install it on a web server, and people will be allowed to remotely know in advance how much a print job will cost to them. - The job's billing code, if present, is now saved into the database, and can serve as a filter for both the standalone data dumper, and the web-enabled print quota monitor and data dumper. Provided your printer driver allows you to enter this code, you'll now be able to produce invoices based on its value. This billing code is also made available to your pre and post hooks through an additionnal environment variable. - Printer's internal page counter retrieval was greatly improved with regard to both power saving mode and buggy printers. - The integrated banner generator now allows the admin to put additionnal informations dynamically onto the banner pages. - Diagnostic messages were greatly improved when something went wrong at startup time. - Portability was improved wrt LDAP. - Several stability improvements and bug fixes. - Greatly improved documentation. The full list of changes is available from : http://www.librelogiciel.com/software/PyKota/action_News Thank you for reading ! Jerome Alet From flamesrock at gmail.com Mon May 16 17:43:32 2005 From: flamesrock at gmail.com (flamesrock) Date: 16 May 2005 14:43:32 -0700 Subject: Python RPM and CentOS In-Reply-To: References: Message-ID: <1116279812.024163.168630@g49g2000cwa.googlegroups.com> I know that gentoo has support for local repositories, and emerge is built on python so...this would make sense. But there is a difference between rpms and ebuilds.. From morton at lsupcaemnt.com Wed May 18 23:37:21 2005 From: morton at lsupcaemnt.com (Ed Morton) Date: Wed, 18 May 2005 22:37:21 -0500 Subject: Comparing 2 similar strings? In-Reply-To: References: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> <428BA05D.1010600@lsupcaemnt.com> <3d9n815cpmavos1fl6ts712h9qogdv3fur@4ax.com> Message-ID: John Machin wrote: > On Wed, 18 May 2005 20:03:53 -0500, Ed Morton > wrote: >>I assume you were actually being facetious >>and trying to make the point >>that names that don't look the same on paper can have the same soundex >>encoding and that's obviously countered with the fact that soundex is >>just a cheap and cheerful way to find names that probably sound similair >>which can vary tremendously based on ethnicity or accent. > > > *If* you want phonetic similarity, there are methods that much better > than soundex, in the sense of fewer false positives and fewer false > negatives. Google for NYSIIS, dolby, metaphone, caverphone. And I assume I'd find they all have pros and cons too, otherwise you'd be referring to THE best one rather than a selection. It seems a bit pointless to go browsing through the documentation on them when someone who presumably already has can't just state the best one for the job. > Cheap? You get what you pay for. > > Cheerful? What's the relevance? "Cheap and cheerful" is a colloquial expression meaning cost-effective. > Someone who types "Mousaferiadis" into a customer search screen and > gets back several lines of McPherson and MacPherson is unlikely to be > cheerful -- even before we factor in the speed [soundex divides the > universe into a relative small number of buckets]. > > Someone who's looking for Erin when they should be looking for Aaron > (or vice versa) won't get much cheer out of soundex, either. That goes back to accent. In [some parts at least of] the USA Erin sounds very much like Aaron wheras in the UK the 2 are very dissimilar. I assume since you apparently consider them similair that you live in the USA and so would consider soundex as providing a "false negative" by saying they don't match. Perhaps one of the other approaches you suggest would report that they do match but that wouldn't make it clearly a better choice to everyone. > >>It's a reasonable approach to consider given the very loose requirements >>presented. > > > Soundex is *NEVER* a reasonable approach to consider. Phonetic > variation is only one consideration. In any case, the OP didn't appear > to be concerned with phonetic variations. The OP didn't say what the application was at all, but you're right that from his example he does SEEM more interested in character matches than phonetic ones so he'd presumably quickly discard phonetic comparisons if that's really not what he wants. Ed. From scrimp212 at yahoo.com Thu May 5 16:13:26 2005 From: scrimp212 at yahoo.com (scrimp) Date: 5 May 2005 13:13:26 -0700 Subject: FTP/TLS connection using python In-Reply-To: <7xfyx2akqu.fsf@ruckus.brouhaha.com> References: <1115225185.951540.128460@z14g2000cwz.googlegroups.com> <4278FFD7.3060200@syscononline.com> <1115226327.793691.252410@o13g2000cwo.googlegroups.com> <7xfyx2akqu.fsf@ruckus.brouhaha.com> Message-ID: <1115324006.067292.139930@o13g2000cwo.googlegroups.com> Does anyone know how I can get m2crypto installed on a windows box w/o paying for the installer? I think thats dumb to charge for the windows version and the unix version is free...o well --Barry From percivall at gmail.com Sat May 28 11:12:23 2005 From: percivall at gmail.com (Simon Percivall) Date: 28 May 2005 08:12:23 -0700 Subject: __call__ References: <42987f9a$0$26432$9b622d9e@news.freenet.de> Message-ID: <1117293143.679768.286600@g43g2000cwa.googlegroups.com> Look at http://docs.python.org/ref/callable-types.html >>> class Test(object): ... def __call__(self): ... print "the instance was called" ... >>> t = Test() >>> t() the instance was called Is this what you wanted? From listserver at tdw.net Thu May 12 11:42:34 2005 From: listserver at tdw.net (Tim Williams) Date: Thu, 12 May 2005 16:42:34 +0100 Subject: How "return" no return ? References: <1115839271.271071.32710@z14g2000cwz.googlegroups.com> <1115841659.470657.33320@o13g2000cwo.googlegroups.com> Message-ID: <00fd01c55709$385df110$5aeda8c0@twilliams> "Ximo" wrote in message news:3ehaurF34ak0U1 at individual.net... > Hello, I want that the return sentence don't return anything, how can I do > it?. If i do only return it returns None, and pass don't run too. > > Can anyone help me?, thanks. > XIMO > Just don't use a return statement at all, or do something like [function body] if not val = None: return val [end of function] From simon.brunning at gmail.com Fri May 27 09:40:11 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Fri, 27 May 2005 14:40:11 +0100 Subject: __init__() not called automatically In-Reply-To: References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> <4295f081$0$19214$626a14ce@news.free.fr> Message-ID: <8c7f10c6050527064067944f89@mail.gmail.com> On 26 May 2005 11:54:33 -0400, Roy Smith wrote: > And the correlary wart in Python is that the first argument to a > method is not required to be called "self". The vast majority of > people use "self", but every once in a great while you run into some > yahoo who feels this is the right place to express his creativity and > call it "this", or "obj", or some other obfuscation. To be fair, it's easy to use 'this' by accident if you've recently been working with Java. I've done it myself. It takes me an hour or to reset my brain, and for a short while, there are bloody 'this'es, braces and semi-colons everywhere. Sanity soon returns, though. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From Florian.Lindner at xgm.de Wed May 4 07:39:27 2005 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Wed, 04 May 2005 13:39:27 +0200 Subject: Problem with pyXML DOM References: Message-ID: Maniac wrote: > Florian Lindner wrote: > >>Traceback (most recent call last): >> File "ConfigReader.py", line 40, in ? >> c = ConfigReader(f) >> File "ConfigReader.py", line 32, in __init__ >> print sourceNode.getElementsByTagName("filename")[0].nodeValue() >>TypeError: 'NoneType' object is not callable >> >> > This is because nodeValue here is 'None' and 'None()' doesn't make > sense. Looks like you want the thing between and . > This is not a nodeValue, this is nodeValue of firstChild of element > 'filename'. So this should work: > > print sourceNode.getElementsByTagName("filename")[0].firstChild.nodeValue Ok, works perfect. Thanks! But I don't really understand the logic: given I have the node A path A.firstChild.nodeValue == path How would the second child of A look like? (ok, None in this case) How would a XML fragment look like that has a second child? What would be the nodeValue of A? for me a child of a node is something like Thanks, Florian From brian at sweetapp.com Wed May 11 10:21:19 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 11 May 2005 16:21:19 +0200 Subject: Interactive shell for demonstration purposes In-Reply-To: References: <1115814028.259365.98710@g49g2000cwa.googlegroups.com> Message-ID: <428214DF.7080304@sweetapp.com> Ville Vainio wrote: > Hmm, do you consider the fonts in a console window unreadable? In fullscreen mode, yes (you get no choice of font size in Windows XP). In Windowed mode you still only get a limited font selection (only two fonts and only a few type sizes [most of which are small]). > I've > given a few presentations using ipython on win32 and it worked alright > - but I suppose the projector quality is a factor here... I'll get by but I was hoping for something better. Cheers, Brian From __peter__ at web.de Wed May 4 15:40:50 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 May 2005 21:40:50 +0200 Subject: properties vs. eval() References: <1115235178.971840.248160@o13g2000cwo.googlegroups.com> Message-ID: Bob Rogers wrote: > Given this class: > > class C(object): > def set_x(self, x): > self._x = x > > def get_x(self): > return self._x > > x = property(get_x, set_x) > > > This use of compile() and eval() works as I expected it to: > > c = C() > c.x = 5000 > n = '\'five thousand\'' > code = compile('c.x = ' + n, '', 'exec') > print 'before ', c.x > eval(code) > print 'after ', c.x I believe it is an implementation accident that this works. > > But this, using eval() without compile(), does not: > > c = C() > c.x = 5000 > n = '\'five thousand\'' > print 'before ', c.x > eval('c.x = ' + n) > print 'after ', c.x > > It gives: > > before 5000 > Traceback (most recent call last): > File "./r.py", line 16, in ? > eval('c.x = ' + n) > File "", line 1 > c.x = 'five thousand' > ^ > SyntaxError: invalid syntax > > Could someone please explain just what is going on here, and whether it > is possible to dispense with the compile step and use eval() alone > while setting a property? Use eval(s) to evaluate an expression and exec s to execute a statement. Peter From danny at nnu-dot-com.no-spam.invalid Tue May 31 12:28:26 2005 From: danny at nnu-dot-com.no-spam.invalid (dannyguindi) Date: Tue, 31 May 2005 16:28:26 +0000 (UTC) Subject: COM+, Javascript and Python References: <1114609311.916761.272980@f14g2000cwb.googlegroups.com> Message-ID: Do you guys know if there is a way to do this in Linux? Thanks. Danny From peter at engcorp.com Sun May 15 21:35:30 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 15 May 2005 21:35:30 -0400 Subject: The world is really unstable these days...... In-Reply-To: <8RRhe.2094$M36.91@newsread1.news.atl.earthlink.net> References: <49B3F3B1.646A6FE6@elsewhere.com> <8RRhe.2094$M36.91@newsread1.news.atl.earthlink.net> Message-ID: Lucas Raab wrote: > [...] > Y'know, I really do love these random word spam messages. They're quite > entertaining to read. Although, when posting in reply to them it apparently helps those who read this through the mailing list, and who have Bayesian filtering of spam happening, if you would snip the entire content. Otherwise it can confuse the spam blockers since they have your name generally associated with useful messages (I presume ;-) ) instead of with spam. You're messin' with their statistics, man! ;-) -Peter From glauco.silva at cenpra.gov.br Tue May 3 11:19:06 2005 From: glauco.silva at cenpra.gov.br (Glauco Silva) Date: Tue, 3 May 2005 12:19:06 -0300 Subject: problem in the compiler ? References: <338366A6D2E2CA4C9DAEAE652E12A1DE025204C3@au3010avexu1.global.avaya.com> <427782e9$1@nntp0.pdx.net> Message-ID: <01a401c54ff3$72f4a4d0$e87290c8@piau> The call of MyClass isn?t in this order... i only want to explain that i?m calling the class 'MyClass' and when i do this the function "Function" is call when the compiler pass for the RadioButton. The same happened when i used Pmw.RadioSelect. I solve this problem now using this: radio = Pmw.RadioSelect() radio.bind('', self.Function) if i use : Pmw.RadioSelect(command = self.Function) the 'Function' is call. And i think that this is wrong and i only want to tell to help solve this bug. so, my code is this: file : MyClass.py import Pmw class MyClass: def __init__(self): radio = Pmw.RadioSelect() radio.bind('', self.Function) #Pmw.RadioSelect(command = self.Function) def Funciton(self): print "Enter in the Function" if __name__ == '__main__' : MyClass() when i call in the console like this: C:\python MyClass.py if i using in the __init__ this : Pmw.RadioSelect(command = self.Function) so the string "Enter in the Function" is print Thank you Glauco ----- Original Message ----- From: "Scott David Daniels" To: Sent: Tuesday, May 03, 2005 11:21 AM Subject: Re: problem in the compiler ? Glauco Silva wrote: > python : 2.3.5 > os: win 2K This part is good enough (though sometimes it helps to mention the service pack number on windows systems). > My code is like this: > > MyClass() > > class MyClass: > def __init__(self): > btn = RadioButton(command=self.Function) > def Function(self): > print "Enter in the function" This is not good enough. Show us a small actual example that exhibits the problem behavior on your machine. Often in the course of doing this distillation, the original problem will become clear to you. The code above fails with: Traceback (most recent call last): File "", line 1, in -toplevel- MyClass() NameError: name 'MyClass' is not defined on the initial call to MyClass(). I suspect this is not what you care about. Don't make people trying to help you do any work you cannot do yourself. Imagine yourself browsing the newsgroup and trying to decide whether to spend some time trying to help someone with a problem. Would _you_ want to spend time trying to guess what the code was with the problem as well as what the problem was, or would you decide to help someone else out? --Scott David Daniels Scott.Daniels at Acm.Org -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.11.2 - Release Date: 2/5/2005 From alexander.fillips at telefonica.de Tue May 10 02:20:30 2005 From: alexander.fillips at telefonica.de (Alexander Fillips) Date: Tue, 10 May 2005 08:20:30 +0200 Subject: is there a python object which can interpret java-script? In-Reply-To: References: <427f4ae5$0$11234$750803fa@corp.news.telefonica.de> Message-ID: <428052ae$0$11220$750803fa@corp.news.telefonica.de> Kartic wrote: > The Great 'Alexander Fillips' uttered these words on 5/9/2005 7:34 AM: > >> Hi, >> >> my short question: >> >> is there a python object which can interpret java-script? >> >> the whole story ;-) >> >> I wrote some streaming-scripts for the xbox mediaplayer which supports >> python. for a new script i tried to filter the stream-url from an >> website. it seems, that the site ist using java-script and the url is >> only visible if the java-script was interpreted. i am using urllib to >> retrieve the page.. but it seems that urllib is not ready for >> java-script... > > > http://wwwsearch.sourceforge.net/python-spidermonkey/ is a > Python-Javascript bridge. > > To do what you are trying, you will have to execute the Javascript in > that web page in the context of the page you are downloading...I am not > quite sure how you will go about doing that without re-inventing what a > Javascript-enabled browser does. > > Knowing nothing about the Xbox environment, here is a suggestion that I > feel will make your task easier. Can you not use javascript-enabled > links text browser to access the page and capture the output HTML source > from links into Python? (Or if you can use win32all, you can automate IE > to view source and process that source in Python to get your URL) > if the xbox media player is active there is only support for python. it is possible to run linux on the xbox, but not at the same time as xbmc is active. i found a browser for the xbox (linksboks) but here still the same problem. thank for your tips... Alex From ryan at ryankaskel.com Mon May 16 19:41:53 2005 From: ryan at ryankaskel.com (ryan at ryankaskel.com) Date: 16 May 2005 16:41:53 -0700 Subject: query progress bar References: Message-ID: <1116286913.207477.219180@g44g2000cwa.googlegroups.com> What type of UI is this for? The Python Cookbook, 2nd Ed. has a nice textual solution. I'm not sure if this is the same one, but here is one from ASPN. Here is one for wxPython. From wuwei23 at gmail.com Thu May 5 20:47:17 2005 From: wuwei23 at gmail.com (alex23) Date: 5 May 2005 17:47:17 -0700 Subject: New Python regex Doc (was: Python documentation moronicities) In-Reply-To: <1115328523.852744.110390@f14g2000cwb.googlegroups.com> References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113856843.023012.165500@l41g2000cwc.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> Message-ID: <1115340437.139748.291890@z14g2000cwz.googlegroups.com> Xah Lee wrote: > 99% of programers really don't need to give a flying fuck about the > history of a language. Ironically, I'm pretty confident that the same percentage of readers on this group feel _exactly the same way_ about your 'improvements'. -alex23 From dfreem3 at nospam.shaw.ca Sat May 14 19:04:04 2005 From: dfreem3 at nospam.shaw.ca (don freeman) Date: Sat, 14 May 2005 23:04:04 GMT Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever separated from the love of God in a place called Hell. The Holy Bible descibes Hell as a place of eternal torment, suffering, pain and agony for all those who have rejected Jesus Christ. The good news is that you can be sure you are going to Heaven when this life is over if you allow Jesus Christ to save you today. Do not wait until later to be saved because you do not know exactly when you will die. [ Posted by: RonaldGrossi3848@yahoo.com on May 14, 2005 ] [ 2:52:09 pm ] In-Reply-To: <1116096706.696830.275140@g44g2000cwa.googlegroups.com> References: <1116096706.696830.275140@g44g2000cwa.googlegroups.com> Message-ID: > http://www.gotquestions.org/sinners-prayer.html << I saw this site on a > search directory. Great Resource! > C'mon, this is the 21st century. Nobody believes that silly story about God having a son anymore. Think about it. The original story is always the best. The sequel is always a commercial rip-off. Frankenstein was literature. Son of Frankenstein was silly. God impregnates a virgin woman and gives birth to a half man/half god, who can walk on water and turn water into wine, but who can't defend himself very well at all from the Romans. This story may have sold in the past, but not now. We've become too sophisticated for this kind of fantasy. From yamadora1999 at naver.com Mon May 23 23:45:08 2005 From: yamadora1999 at naver.com (yamadora1999) Date: 23 May 2005 20:45:08 -0700 Subject: How to use protocols.msn.FileSend and protocols.msnFileReceive Message-ID: <97627ec1.0505231945.79a90eaf@posting.google.com> How to use protocols.msn.FileSend and FileReceive? Please show me a example. From dfreem3 at nospam.shaw.ca Wed May 11 15:25:19 2005 From: dfreem3 at nospam.shaw.ca (don freeman) Date: Wed, 11 May 2005 19:25:19 GMT Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever sepa In-Reply-To: <3eevb8F2pac7U1@individual.net> References: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> <3eeta6F2m45kU1@individual.net> <1115832484.237918.53830@o13g2000cwo.googlegroups.com> <3eevb8F2pac7U1@individual.net> Message-ID: > > I suppose he could point at what he saw and wither it. > Jesus would then give a sermon from the mount: Let the Puritans wear fig leaves over their eyes! From jonasmg at softhome.net Wed May 18 06:11:19 2005 From: jonasmg at softhome.net (Jonas Melian) Date: Wed, 18 May 2005 11:11:19 +0100 Subject: Python forum In-Reply-To: <17033.60162.412060.528218@montanaro.dyndns.org> References: <4289B462.10804@softhome.net> <4289E7D2.80303@acm.org> <17033.60162.412060.528218@montanaro.dyndns.org> Message-ID: <428B14C7.3090206@softhome.net> Skip Montanaro wrote: > I wonder if there's a way to gateway the tutor list to the > python-forum.org forum, probably to the beginner's forum. > > Skip > > Totally in agreement with this. Thus each one chooses if wants to posting from forum or mailing list From b.ghose at gmail.com Sun May 1 17:32:26 2005 From: b.ghose at gmail.com (Baishampayan) Date: 1 May 2005 14:32:26 -0700 Subject: Whats the best Python Book for me References: Message-ID: <1114983146.710093.254820@f14g2000cwb.googlegroups.com> Hi, In my opinion, Mark Pilgrim's great book Dive Into Python is the best suited for somebody who already knows some programming. The book is a truly free book and is available in a wide range of formats. You can get it here http://diveintopython.org/ Enjoy! -bg- From magicmas at spymac.com Sun May 29 04:14:00 2005 From: magicmas at spymac.com (cheng) Date: 29 May 2005 01:14:00 -0700 Subject: need help of RE In-Reply-To: <42997871$0$27689$636a15ce@news.free.fr> References: <1117352350.179209.206930@z14g2000cwz.googlegroups.com> <1117353427.242568.47010@g43g2000cwa.googlegroups.com> <42997871$0$27689$636a15ce@news.free.fr> Message-ID: <1117354440.939645.177790@f14g2000cwb.googlegroups.com> thx for help..i got it now :) From littlejohn.75 at news.free.fr Sat May 7 13:21:17 2005 From: littlejohn.75 at news.free.fr (F. Petitjean) Date: 07 May 2005 17:21:17 GMT Subject: Shell Commands in Python Code References: Message-ID: <427cf90d$0$287$626a14ce@news.free.fr> Le Sat, 7 May 2005 08:55:35 -0700 (PDT), Sara Khalatbari a ?crit : > There are a lot of commands that I need to use in my > code & I don't know how to do it > > Is there a way to use shell commands in Python code? Python is a scrpting language. So you can substitute most shell scripts idioms with pythonic ones. A large number of shell scripts can be replaced with python scripts without any semantic loss. > From jonasmg at softhome.net Thu May 19 18:46:40 2005 From: jonasmg at softhome.net (Jonas Melian) Date: Thu, 19 May 2005 23:46:40 +0100 Subject: [Tutor] kernel serie In-Reply-To: References: <428D131E.3010000@softhome.net> Message-ID: <428D1750.10404@softhome.net> Max Noel wrote: > > The [:2] is unnecessary, as you're limiting the number of splits to > 2, so the resulting list from split() can't have more than 3 elements. > Without the [:2], it fails > Also, note that this code will likely cause the program to crash on > any system that isn't Linux. On my box (OS X 10.4.1), for example, > sys.platform returns 'darwin'. > Thanks, but it's for a linux program only From jason.mobarak at gmail.com Wed May 4 23:46:44 2005 From: jason.mobarak at gmail.com (Jason Mobarak) Date: 4 May 2005 20:46:44 -0700 Subject: annonymous functions -- how to In-Reply-To: <42795acb.685370470@news.oz.net> References: <1115239458.776800.240080@g14g2000cwa.googlegroups.com> <42795acb.685370470@news.oz.net> Message-ID: <1115264804.625020.203800@f14g2000cwb.googlegroups.com> What's wrong with: def blah(): def _ (a, b, c): a = a + 2 print "stmt 2" return a+b/c return doSomethingWith(_) It's basically "anonymous", it just uses a name that you don't care about. AFAIK, it can be immediately clobbered later if need be. Otherwise, the function shouldn't be anonymous. From powderkeg at snow.email.ne.jp Tue May 31 03:05:29 2005 From: powderkeg at snow.email.ne.jp (Mark Sargent) Date: Tue, 31 May 2005 16:05:29 +0900 Subject: [ANN] IPython 0.6.14. In-Reply-To: References: Message-ID: <429C0CB9.10201@snow.email.ne.jp> Fernando Perez wrote: >Hi all, > >I've just made the 0.6.14 release of IPython, mostly to fix the >inevitable bugs reported after the .13 one (though one big improvement >sneaked by). > >IPython's homepage is at: > >http://ipython.scipy.org > >and downloads are at: > >http://ipython.scipy.org/dist > >I've provided RPMs (for Python 2.3 and 2.4, built under Fedora Core 3), >plus source downloads (.tar.gz). Fedora users should note that IPython >is now officially part of the Extras repository, so they can get the >update from there as well (though it may lag by a few days). > >There is also a native win32 installer which should work correctly for >both Python 2.3 and 2.4. > >Debian, Fink and BSD packages for this version should be coming soon, as >the respective maintainers (many thanks to Jack Moffit, Andrea Riciputi >and Dryice Liu) have the time to follow their packaging procedures. > >Many thanks to Enthought for their continued hosting support for >IPython, and to all the users who contributed ideas, fixes and reports. > >I'd like to add a special thanks to Denis Rivi?re, Yann Cointepas and >Benjamin Thyreau for their hard work on the Qt improvements, and for >their overall hospitality. Python really seems to have a remarkably >friendly community, worldwide! > > >WHAT is IPython? >---------------- > >1. An interactive shell superior to Python's default. IPython has many >features for object introspection, system shell access, and its own >special command system for adding functionality when working interactively. > >2. An embeddable, ready to use interpreter for your own programs. >IPython can be started with a single call from inside another program, >providing access to the current namespace. > >3. A flexible framework which can be used as the base environment for >other systems with Python as the underlying language. > > >Release notes >------------- > >As always, the NEWS file can be found at http://ipython.scipy.org/NEWS, >and the full ChangeLog at http://ipython.scipy.org/ChangeLog. The >highlights of this release follow. > >This is mainly a bugfix release, to clean up the problems reported in >0.6.13. As I said at the time, I intend to start new development now >(more details on that in a separate email). As always, however, a few >new goodies managed to sneak by. > >* A new -qthread option to support controlling Qt apps from within >ipython, similar to what -gthread and -wthread do for GTK/WX. This was >contributed by Denis Rivi?re , Yann Cointepas > and Benjamin Thyreau . > Many thanks to them! The lack of Qt support was a glaring omission of >ipython's gui features, so I'm extremely happy to have their contribution. > > For those of you who may be matplotlib users as well, I should note >that as of mpl 0.81 (the next release, or use current CVS), the -pylab >option will also support interactive matplotlib use with the Qt backend. > This is also thanks to work done by Denis, Yann and Benjamin against >the matplotlib Qt backend, in conjunction with the IPython improvements. > >* New -e option to %run to suppress tracebacks from sys.exit() calls. >This can be very useful to silence all the noise generated when running >unittests from within ipython. > >* New ';' escape to autoquote a line without splitting: > >In [6]: ,foo a b c >------> foo("a", "b", "c") > >In [7]: ;foo a b c >------> foo("a b c") > >In the process, I fixed ',' quoting, which I'd broken in .13. > >* Fix -wthread to work with WXPython 2.6 (this also impacts matplotlib >users who run the WX backend). > >* Added new matcher (it goes at the end of the priority list) to do >tab-completion on named function arguments. Submitted by George Sakkis >. See the thread at > >http://www.scipy.net/pipermail/ipython-dev/2005-April/000436.html > >for more details. > >* Various other fixes for obscure bugs, but all of which caused reported >IPython crashes. Details in Changelog. > > >Enjoy, and as usual please report any problems. > >Regards, > >Fernando. > > > Hi All, Fernando, if I may ask, as I'm a Fedora3 user. You mention that there are RPMs for FC3, for Python2.3, 2.4. I'm new to Python. Is IPython built into FC3s Python or is it a stand-alone program.? Sorry for troubling you with this. Cheers. Mark Sargent. From Bernd.Nawothnig at t-online.de Mon May 16 12:47:25 2005 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Mon, 16 May 2005 18:47:25 +0200 Subject: newbie - variable "buried in quotes" References: <1116260476.332975.87680@g49g2000cwa.googlegroups.com> Message-ID: On 2005-05-16, plsullivan wrote: > I've got a variable deep inside some quotes needed by the application I > am using. I can't figure out how to make this work. (Also, is there a > line continuation character?) > luser = win32api.GetUserName() > gp.FeatureclassToCoverage_conversion("'Database > Connections\\%s at GIS_srv-earth.sde\\GIS.GIS.Cadastral\\GIS.GIS.Parcels' > POLYGON", prcl83, "", "DOUBLE") % luser You poosibly meant something like that: #v+ gp.FeatureclassToCoverage_conversion("'Database" "Connections\\%s at GIS_srv-earth.sde\\GIS.GIS.Cadastral\\GIS.GIS.Parcels'" "POLYGON" % luser, prcl83, "", "DOUBLE") #v- Bernd -- Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. [T. Jefferson] From mario at nospam.noext Wed May 11 07:57:55 2005 From: mario at nospam.noext (Mario) Date: Wed, 11 May 2005 13:57:55 +0200 Subject: HELP Printing with wxPython Message-ID: Hello all, I'm trying hard to make possible to print some simple text from python to the default printer using wxPython, after days of internet searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but is impossible to use this script even if I do exactly as said there. I think the script is buggy or I am not able to use it, even if seems very simple to use... Anyone can give me an hint on how to easily and simply print some text? Is there a library ready to download and use? Something like SendPrinter("some text\n")? Thanks in advance if anyone can give any help. Mario From kaerbuhez at yahoo.fr Thu May 12 17:01:47 2005 From: kaerbuhez at yahoo.fr (kaerbuhez) Date: Thu, 12 May 2005 23:01:47 +0200 Subject: How "return" no return ? In-Reply-To: <3ehkh2F366o4U1@individual.net> References: <3ehaurF34ak0U1@individual.net><3ehc5tF35eo3U1@individual.net> <3ehkh2F366o4U1@individual.net> Message-ID: <4283c442$0$26083$ba620e4c@news.skynet.be> Ximo a ?crit : > I am doing my own interpreter with the Python languaje. > > Do you understand me? > I will do my best : I guess that you are about to write your own non python interpreter (I mean, it will interpret some language that is not Python) and your interpreter sadly writes "None" when there is none to write. Is that correct ? If yes, I suggest that you replace somewhere in your code: print result by if result is not None: print result I know that this is not the question but if it is right that your interpreter is not a python interpreter and that you build a console on top of it (I know many assumptions, ...), I would like to kindly suggest you to use something else that the Python prompt (">>>") - at least on this NG - I am afraid that _this_ didn't help anybody to understand what you meant. If by pure coincidence, this helped you, it would unexpectingly enlight my day ... and please don't tell me that my english is perfect, I know it perfectly well. From robin at reportlab.com Mon May 23 10:52:25 2005 From: robin at reportlab.com (Robin Becker) Date: Mon, 23 May 2005 15:52:25 +0100 Subject: detached subprocess Message-ID: <4291EE29.4000508@chamonix.reportlab.co.uk> After struggling with os.spawnxxx to get a detached process I tried using Pyhton2.4's new subprocess module. I struggled with that as well even when trying to use the creation flags for DETACHED_PROCESS 0x8 and CREATE_NEW_PROCESS_GROUP = 0x200 I am using the following cgi script parent.cgi #!c:/python24/python.exe -u print 'content-type: text/plain' print print 'DONE' import subprocess pid = subprocess.Popen(['c:/python24/pythonw.exe', 'c:\\tmp\\child.py', 'arg1', 'arg2'], creationflags=0x208).pid print pid #end of parent script child is a simple time delay #child.py import time, sys, os time.sleep(10) print 'stdout IN THE CHILD' print >>sys.stderr, 'stderr IN THE CHILD' #end of child When I run the parent.cgi script through apache I see no output in the browser for 10 seconds; when the child dies (as observed using procexp) I see the expected DONE 3256 In other words it seems impossible to get standard subprocess.py to detach the child process properly. However, if I hack subprocess.py to alter the bInheritHandles flag passed into CreateProcess (line 718) from the constant 1 to not (creationflags & 0x8) and 1 or 0 Is this a buglet or a feature request? It seems subprocess punts on closefds for mswindows, but setting bInheritHandles to 0 seems to work fine ie when it is 0 my test seems to indicate that the parent has finished and gone to heaven long before the child ends its sleep. Of course it may be that it's just the handles that are being held. -- Robin Becker From kyoguan at gmail.com Sun May 15 23:28:31 2005 From: kyoguan at gmail.com (kyo guan) Date: Mon, 16 May 2005 11:28:31 +0800 Subject: question about the id() In-Reply-To: <17032.3806.583757.806221@montanaro.dyndns.org> Message-ID: <42881364.3ee9c850.394e.ffff9990@mx.gmail.com> HI Skip: I want to check is there any change in the instance 's methods. >>> a=A() >>> a2=A() >>> a.f == a2.f False >>> a.f is a2.f False >>> a.f is a.f False >>> If the instance methods are create on-the-fly, how to do that? Thanks. Kyo > -----Original Message----- > From: Skip Montanaro [mailto:skip at pobox.com] > Sent: Monday, May 16, 2005 11:09 AM > To: kyo guan > Cc: python-list at python.org > Subject: Re: question about the id() > > > kyo> Can someone explain why the id() return the same > value, and why > kyo> these values are changing? > > Instance methods are created on-the-fly. In your example the > memory associated with the a.f bound method (not the same as > the unbound method > A.f) is freed before you reference a.g. That chunk of memory > just happens to get reused for the bound method associated > with a.g. Here's a > demonstration: > > % python > Python 2.5a0 (#77, May 14 2005, 14:47:06) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1671)] on darwin > Type "help", "copyright", "credits" or "license" for more > information. > >>> class A(object): > ... def f(): pass > ... def g(): pass > ... > >>> a = A() > >>> x = a.f > >>> y = a.g > >>> id(x) > 17969240 > >>> id(y) > 17969440 > >>> id(a.f) > 17969400 > >>> id(a.g) > 17969400 > > Skip From grante at visi.com Tue May 10 21:51:15 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 11 May 2005 01:51:15 -0000 Subject: Python Args By Reference References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> Message-ID: <1182p8j1oa0oc86@corp.supernews.com> On 2005-05-10, Joseph Garvin wrote: > ncf wrote: > >>Hello all, I was wondering if there was any way to pass arguments >>(integer and such) by reference (address of), rather than by value. > > All mutable types in python are passed by reference automatically. So are immutable ones. It just doesn't matter in that case. -- Grant Edwards grante Yow! "DARK SHADOWS" at is on!! Hey, I think visi.com the VAMPIRE forgot his UMBRELLA!! From __peter__ at web.de Wed May 18 11:54:51 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 18 May 2005 17:54:51 +0200 Subject: Sorting x lists based on one list ... maybe an example would make sense: References: <_Nnie.1050$5Z1.166@newssvr30.news.prodigy.com> Message-ID: Philippe C. Martin wrote: > :-) Thanks, the lists will evolve and are also stored in 'csv' format in > external files at one point. I cannot use dictionaries because I need to > control the sorting (hash). > > In this specific case, list 1 represents students with their information, > list 2 represents assignments with information such as weight, term, max > grade ... and list 3 the actual grades. This sounds like you should seriously consider using a database. Peter From waqer at yahoo.com Sun May 8 03:21:51 2005 From: waqer at yahoo.com (waqer at yahoo.com) Date: 8 May 2005 00:21:51 -0700 Subject: Python features Message-ID: <1115536911.106882.166230@z14g2000cwz.googlegroups.com> To which degree python language support features of following langauage categories? Imperative, Object Oriented, Scriptig or Functional. From mahs at telcopartners.com Wed May 4 22:48:47 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Wed, 04 May 2005 19:48:47 -0700 Subject: News/mail gateway problem? (was Re: UnicodeDecodeError ) In-Reply-To: References: Message-ID: John Machin wrote: > On Thu, 5 May 2005 13:00:32 +1200, Thomas Thomas > wrote: > > >>Hi all, >> >>Forgot to mention I am using python 2.3 on windows. >> >> > > > This message (sent to python_list) would seem to be referencing a > previous posting/message -- but it's not showing up in the newsgroup. > I've noticed a few cases in the last day or so where the first item in > a thread on the newsgroup was a reply to a message/posting that was > not in the thread. > > Is there blockage/leakage in the pipe somewhere? > > > I received the previous posting via the gmane news server. But it is dated 5/5/2005 5.15a PDT (i.e., tomorrow). Perhaps this has something to do with the 'blockage/leakage' Michael From pdemb at gazeta.pl Wed May 18 07:44:24 2005 From: pdemb at gazeta.pl (Peter Dembinski) Date: Wed, 18 May 2005 13:44:24 +0200 Subject: How to learn OO of python? References: Message-ID: <8764xg69nr.fsf@hector.domek> could ildg writes: > I have learned python for over a month. > I heard that it was very easy to learn, but when I tried to know OO > of python, > I found it really weird, some expressions seem very hard to understand, > and I can't find enough doc to know any more about it. These may be hard to understand because you haven't understood OOP. Python syntax is very similar to p-code used in computer science books. Try to think like a computer scientist :> > So, I wonder how did you master python? And where to find some cool > docs? Go to the nearest library and get some OO design book. -- http://www.peter.dembinski.prv.pl From rschroev_nospam_ml at fastmail.fm Thu May 12 04:11:40 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 12 May 2005 08:11:40 GMT Subject: Python Documentation (vs PHP stuff) In-Reply-To: References: Message-ID: <0dEge.88616$nT4.5317732@phobos.telenet-ops.be> Terry Reedy wrote: > Because of these two posts (and a few others) extolling the PHP > documentation, I decided to take a look for myself to see what the > fuss was about and whether I could get any ideas on how to improve > Python's docs. > > [...] > > Finally, 80% of the chapter/page consists of a thrown-together > mish-mash of unsorted. unedited comments and questions. In my experience, the user comments in many cases are almost useless. Sometimes just confusing, sometimes contradicting each other, sometimes even incorrect. Sometimes correct and useful too, but IMO that gets drown between all the others. > [...] > Sorry, PHP doc fans: to me, this sort of inflated, noisey bloatware > is wretched, not outstanding. Thank you. I thought I was the only one in the world who doesn't like the PHP documentation. > Conclusion 1: if PHP is anything as awful as the manual, it is not > for me. I'm fairly sure you won't like PHP :) Some time ago I used to do some programming in PHP on the side. In the beginning, I thought PHP was quite a nice language. I even used it to write some small non-web programs that I would otherwise haven written in C or C++ (I didn't know Python at the time, nor any other decent scripting language(*) ). Then I discovered Python, which caused my dislike of PHP to grow even more. PHP tries to make everything as simple as possible but that doesn't always work out very well, as explained in the section 'Oversimplification Leading to Excessive Complexity' of this paper: http://www.ukuug.org/events/linux2002/papers/html/php/#section_5. Python OTOH makes things as simple as possible but not any simpler, and that turns out to work much better. (Disclaimer: I haven't done any web programming in the meantime, so I don't know from own experience how Python fares in that area. But I'm fairly confident that it would work out just nice.) (Sorry for this off-topic rant) (*) I know Python is not just a scripting language, but the things I used PHP for at the time really were nothing more than scripts, despite me thinking about writing them in C or C++. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From jepler at unpythonic.net Thu May 5 09:27:08 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 5 May 2005 08:27:08 -0500 Subject: Best way to convert a list into function call arguments? In-Reply-To: <1115299220.736781.54810@o13g2000cwo.googlegroups.com> References: <1115299220.736781.54810@o13g2000cwo.googlegroups.com> Message-ID: <20050505132707.GA19971@unpythonic.net> Your question is answered in the tutorial: http://docs.python.org/tut/node6.html#SECTION006740000000000000000 4.7.4 Unpacking Argument Lists The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments. For instance, the built-in range() function expects separate start and stop arguments. If they are not available separately, write the function call with the *-operator to unpack the arguments out of a list or tuple: >>> range(3, 6) # normal call with separate arguments [3, 4, 5] >>> args = [3, 6] >>> range(*args) # call with arguments unpacked from a list [3, 4, 5] Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From kay.schluehr at gmx.net Sun May 8 10:11:23 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 8 May 2005 07:11:23 -0700 Subject: pyvm -- faster python In-Reply-To: References: Message-ID: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> Stelios Xanthakis wrote: > Hi. > > pyvm is a program which can run python 2.4 bytecode (the .pyc files). > A demo pre-release is available at: > http://students.ceid.upatras.gr/~sxanth/pyvm/ > > > Facts about pyvm: > - It's FAST. According to the "cooked-bench" benchmark suite it finishes > in 55% of the time python takes;) > - It's SMALL. Currently the source code is under 15k lines with the > builtin modules. > - It's new. Uses no code from CPython. > - It's incomplete. Not even near the stability and quality of python. > It needs A LOT of work before it can be compared to CPython. > Moreover, at the time it lacks many things like closures, long numbers > new style classes, etc. > - It's incompatible with CPython. Not all programs run. > - The C API is incompatible. You can't run C modules (a thin wrapper to > make pyvm appear as libpython *could* be possible but not a goal > AFAIC) > - The demo is an x86/linux binary only. You shouldn't trust binaries, > run it in a chrooted environment not as root! > > Hope it works! > > Cheers, > > Stelios Hi Stelios, could You tell us a bit more about Your motivation to create an alternative C-Python interpreter? There is AFAIK no such ambitious project that has ever survived. The last one I remember died shortly after it was born: http://www.python.org/pycon/papers/pymite/ This is sad because it is still challenging to offer a tiny interpreter of a dynamic language for glue code/RAD on tiny hardware. A lot of effort was spent to provide Java for microcontrollers especially for SmartCards. I think a lot of people would show interest in Your project if it gets somehow focussed and does not seem to be redundant. Ciao, Kay From peter at engcorp.com Sat May 14 19:43:29 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 14 May 2005 19:43:29 -0400 Subject: Multiple "cmp"s chained one after another In-Reply-To: References: Message-ID: Volker Grabsch wrote: > Peter Hansen wrote: > >>Or just use the .timetuple() method on datetime objects and sort on the >>8th element of the 9-element tuple, which is the day-of-the-year. > > An interesting idea. But wouldn't sorting by (dd.month,dd.day) be more > effective? Depending on the meaning of "effective", I suppose so. > In other words: Does .timetuple() create a tuple, or does it just return > a tuple which is present anyway? I don't know what it does. Normally one shouldn't care about that kind of thing. In this case, you seem to be assuming that .month and .day are values that are "present anyway", but we don't really know that either, since they could just as well be properties. If someone who knows or someone who checks the source (for a given implementation of course... it could change) cares to share, we'd know more. What good that would do us is still a mystery to me. ;-) -Peter From BluWater0523 at yahoo.com Wed May 11 11:16:03 2005 From: BluWater0523 at yahoo.com (BluWater0523 at yahoo.com) Date: 11 May 2005 08:16:03 -0700 Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever separated from the love of God in a place called Hell. The Holy Bible descibes Hell as a place of eternal torment, suffering, pain and agony for all those who have rejected Jesus Christ. The good news is that you can avoid Hell by allowing Jesus Christ to save you today. Only then will you have true peace in your life knowing that no matter what happens you are on your way to Heaven. by BluWater0523@yahoo.com Message-ID: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> http://hypershrink.com/SinnersPrayer << I saw this website on a search directory. Great Resource! From bob at passcal.nmt.edu Wed May 18 19:33:00 2005 From: bob at passcal.nmt.edu (Bob Greschke) Date: Wed, 18 May 2005 17:33:00 -0600 Subject: Tkinter Return/Enter key handling Message-ID: I have a Tkinter Text() widget in a program that the user can type stuff into. Most of our keyboards have the regular keys with a "Return" key, and a numeric keypad with an "Enter" key. The Return key generates events with "" for the keysym, and the Enter key generates events with "" as the keysym. The Text() widget does a carriage return/linefeed when the Return key is pressed, but does nothing when the Enter key is pressed. So I did a Text.bind(" References: <2Ifje.100148$hu5.2601@tornado.texas.rr.com> Message-ID: <428daf6b$0$24052$db0fefd9@news.zen.co.uk> J. W. McCall wrote: > I'm not sure if this is off-topic, since it doesn't deal with Python > itself, but here goes: > > I'm messing around with writing a simple "game" where the player (a > crudely drawn smiley face) moves by rotating and moving back or forward > (think Resident Evil, but from an always-above view). After much > hacking, I have it working where left and right rotate the player sprite > and up always moves the sprite whichever direction it's facing, while > down is reverse. I'm using pygame.transform.RotoZoom(). > > My problem is that it doesn't rotate smoothly. When it rotates, the > corners of the image (just a plain white background) look like they're > hitting some barrier and making it move around. Think of an empty box > turned diagonally (so that it looks like a diamond, with its open end > facing you), and a cube in that box being turned while it's resting in > the bottom corner. I want it to rotate smoothly around its center, it's > it's not doing that. > > I'm guessing that it has something to do with me not setting up a Rect > right, but I'm not sure. Maybe this is a limitation of Rotozoom/Rotate? > > Any advice would be greatly appreciated. And yes, I'm a rank PyGame > newbie. > I'm not sure - haven't actually used rotozoom, but from the docs it returns a surface containing the rotated images. The problem with that is that a rotated surface wont fit in to the same area, so what you get back will be bigger than the original. If you want to draw it at the same position, move the rotated surface so that the centre point is the same as the original unrotated image. Creating a new sprite each time is probably quite inefficient. You might want to look at OpenGL, which is excellent for 2D and 3D games. HTH, Will McGugan -- http://www.willmcgugan.com "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz" ] ) From Servatius.Brandt at fujitsu-siemens.com Tue May 24 11:00:56 2005 From: Servatius.Brandt at fujitsu-siemens.com (Servatius.Brandt at fujitsu-siemens.com) Date: Tue, 24 May 2005 17:00:56 +0200 Subject: Build error Python 2.4.1 - stat problem? Message-ID: Hello, I tried to build Python 2.4.1 on a Reliant Unix system. Just after the python executable program has been built, I get the following error: ==== begin make output === CC -W1 -Blargedynsym -o python \ Modules/python.o \ libpython2.4.a -lresolv -lsocket -lnsl -ldl -lm case $MAKEFLAGS in \ *-s*) CC='cc' LDSHARED='ld' OPT='-DNDEBUG -O' ./python -E ./setup.py -q build;; \ *) CC='cc' LDSHARED='ld' OPT='-DNDEBUG -O' ./python -E ./setup.py build;; \ esac Traceback (most recent call last): File "./setup.py", line 1088, in ? class PyBuildInstallLib(install_lib): File "./setup.py", line 1094, in PyBuildInstallLib so_ext = sysconfig.get_config_var("SO") File "/build_dir/Python-2.4.1/Lib/distutils/sysconfig.py", line 511, in get_config_var return get_config_vars().get(name) File "/build_dir/Python-2.4.1/Lib/distutils/sysconfig.py", line 488, in get_config_vars func() File "/build_dir/Python-2.4.1/Lib/distutils/sysconfig.py", line 358, in _init_posix raise DistutilsPlatformError(my_msg) distutils.errors.DistutilsPlatformError: invalid Python installation: unable to open /usr/local/lib/python2.4/config/Makefile (No such file or directory) make: *** Error code 1 make: Fatal error. ==== end make output === It is strange that the Makefile complains about /usr/local/lib/python2.4 since this is still the build phase, far away from the installation into /usr/local. I used the python executable from the build directory to run the following program: import os def main(): if not (os.path.exists("/")): print "/ does not exist" else: print "/ exists" if not (os.path.isdir("/")): print "/ is not a directory" else: print "/ ok" if __name__ == "__main__": main() The output is: / exists / is not a directory It's the same for every (existing) directory name I try: os.path.isdir() always returns false. It looks as if the stat results are not recognised: os.path.exists() works, but all the functions os.path.isdir(), os.path.isfile() etc. don't. Could anyone help me to solve the problem? - Servatius ------------------------------------------------------------------------ Servatius Brandt Phone: +49 89 636-41504 Fujitsu Siemens Computers Fax: +49 89 636-48716 EP SW AD C++ Email: Servatius.Brandt at fujitsu-siemens.com From sxanth at ceid.upatras.gr Wed May 11 06:02:59 2005 From: sxanth at ceid.upatras.gr (Stelios Xanthakis) Date: Wed, 11 May 2005 13:02:59 +0300 Subject: pyvm -- faster python In-Reply-To: References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> Message-ID: <4281D853.9000600@ceid.upatras.gr> Roger Binns wrote: >>I am not very interested on C compatibility. > > > That will rule out all the gui frameworks, SSL, cryptography > and numerous other packages. Have a look at what happened to > Prothon. What ultimately killed it was the problem of having > a decent library. You don't have to make the C library > compatibility totally high performance, but having any form of > it there will make adoption by others easier. > There are two kinds of C modules: those that do have a knowledge of the C API (like sre, tkinter, etc) and those that are just C/C++ libraries which are simply wrapped as modules. For the latter there are two solutions besides adding a wrapper which makes pyvm appear as libpython: - an advanced ctypes module which will make dlopening libraries and wrapping their symbols behind python functions, a matter of python code. I'm considering this approach to provide things like 'raw_input'. - hacking SWIG. Shouldn't be too hard and will instantly give us access to wx, qt, etc. The thing is that the C API of pyvm is IMHO superior and much more fun. You can wrap the entire sockets module in a couple of hours and also enjoy it. I wish I could clone myself to port the entire std library to pyvm -- so much fun it is:) thanks, Stelios From curi at curi.us Fri May 27 02:36:30 2005 From: curi at curi.us (Elliot Temple) Date: Thu, 26 May 2005 23:36:30 -0700 Subject: Strange Execution Times In-Reply-To: <42964C28.8070400@lexicon.net> References: <3A252A14-E6A4-4F9B-AB49-B6B012A0BC12@curi.us> <42964C28.8070400@lexicon.net> Message-ID: On May 26, 2005, at 3:22 PM, John Machin wrote: > > Then post your summarised results back to the newsgroup for the > benefit of all -- there's this vague hope that folk actually read > other peoples' posts before firing off questions :-) Here is my new version. It runs in about .65 seconds. The trick? Reading lines one at a time. Please let me know if there's any bad coding practices in it! def main(): import md5 import time f = open("data.xml", "rU") out = open("out.xml", "w") p1 = "" p2 = "" adjust = len(p1) t1 = time.clock() for line in f: start, end = line.find(p1) + adjust, line.find(p2) if end != -1: digest = md5.new(line[start:end]).hexdigest() out.write(line[:start] + digest + line[end:]) else: out.write(line) t2 = time.clock() print round(t2-t1, 5) f.close() out.close() if __name__ == '__main__': main() -- Elliot Temple http://www.curi.us/ --- [This E-mail scanned for viruses by Declude Virus] From fredrik at pythonware.com Thu May 12 06:45:36 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 May 2005 12:45:36 +0200 Subject: Destructor Woes, was Advice needed on __del__ References: <427FBAD4.3070004@anvilcom.com> <42800279.3B26FFF3@pauahtun.org> <4280EDA3.1090104@anvilcom.com> Message-ID: "phil" wrote: >> Then i got a tip that you can register a function that needs to be >> called when the object is going to be deleted. >> For instance to register a function __exit, you do this: > > Here is the complete line class with your suggestion: > > Below is the output. > > Nice idea, maybe I did something wrong? > > class line: > def __init__(s,glob,argl,color=''): > atexit.register(s.__exit) atexit is used to clean up when the *interpreter* shuts down, not when any object is going to be deleted. > File "/usr/local/lib/python2.3/lib-tk/Tkinter.py", line 2085, in delete > self.tk.call((self._w, 'delete') + args) > _tkinter.TclError: invalid command name ".1076354284" this usually means that you're trying to execute Tkinter methods on a widget that no longer exists (probably because Tkinter has been shut down, at this point). From fredrik at pythonware.com Thu May 5 16:40:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 5 May 2005 22:40:18 +0200 Subject: Encryption with Python? References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com> Message-ID: Blake T. Garretson wrote: > I found a few modules out there, but they seem to be all but abandoned. > Most seem to have died several years ago. a lack of recent releases can also mean that they just work... > Is this the defacto Python encryption solution? What does everyone > else use? Any other suggestions? http://sandbox.rulemaker.net/ngps/m2/ is actively maintained, as far as I can tell. you might also be able to find some useful stuff inside: http://trevp.net/tlslite/ (see the utils package for a pure-python AES implementation) From vegeta.z at gmail.com Mon May 2 22:04:40 2005 From: vegeta.z at gmail.com (vegetax) Date: Mon, 02 May 2005 22:04:40 -0400 Subject: cgi "print statement" in multithreaded enviroment? References: <20050503013716.GA3367@unpythonic.net> Message-ID: Jeff Epler wrote: > You could write something like > class ThreadSpecificFile: > def set_stdout(f): > self.files[thread_id] = f > def write(data): > self.files[thread_id].write(data) > sys.stdout = ThreadSpecificFile() > where you'll have to fill out a few more things like thread_id, > __init__, and a way to clean up items from self.files when a thread > passes away. > > Jeff Thats what i was looking for,Thanks =) From luismgz at gmail.com Sun May 1 19:52:12 2005 From: luismgz at gmail.com (Luis M. Gonzalez) Date: 1 May 2005 16:52:12 -0700 Subject: Whats the best Python Book for me In-Reply-To: References: Message-ID: <1114991532.372691.177740@z14g2000cwz.googlegroups.com> For someone expereinced like you, I recommend "Dive into Python". It is available online. There's also a very good tutorial which is aimed to both, beginners and experienced programmers, that can give you a very complete and high level overview of the python language: "A byte of Python". Also available online. From Sebastien.Boisgerault at gmail.com Sun May 29 07:54:54 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 29 May 2005 04:54:54 -0700 Subject: ControlDesk Automation in dSpace In-Reply-To: <1117357685.430456.257870@g43g2000cwa.googlegroups.com> References: <1117357685.430456.257870@g43g2000cwa.googlegroups.com> Message-ID: <1117367694.056936.85110@f14g2000cwb.googlegroups.com> Crispen a ?crit : > I am having trouble using the ControlDesk automation libraries in > python. In particluiar running the automation in a thread. My code is > as follows, is keeps coming up with this strange error. Any help would > be great. > > Crispen > > import cdacon > from time import sleep > from cdautomationlib import * > > def Auto(): > [... skip ...] > thread.start_new_thread(Auto,()) Crispen, I am afraid that you won't find many dspace users on comp.lang.python. The code you produced is quite hard to read, we lack some info about the context of your app and you didn't provide what the error you encounter is ... Maybe you should provide a minimal python code that does not work, and give us the corresponding error message. If it is Python related, I guess that you'll probably get a reply. If it is related to dspace, maybe you should try comp.soft-sys.matlab (?), or any other group that may discuss dspace issues. Regards, Seb From newsgroups at jhrothjr.com Mon May 16 12:13:55 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Mon, 16 May 2005 10:13:55 -0600 Subject: Structuring larger applications - ideas References: <1116255787.625276.221670@g14g2000cwa.googlegroups.com> <1116259236.861818.127170@g14g2000cwa.googlegroups.com> Message-ID: <118hhm6jf40oue6@news.supernews.com> "Iwan Vosloo" wrote in message news:1116259236.861818.127170 at g14g2000cwa.googlegroups.com... > > I know my foreign (to python) one class per module idea is what makes > life more difficult for me here. And there is an argument to be made > out that it is a stupid remnant I stick to from having used it in other > programming languages (do I have to admit C++ in my background?) Two > small examples of where it it useful for me: my development > environment is run by make to a large extent. Many standard UNIX tools > have the intelligence to deal with filenames, and if you know a file > corresponds to a class, you have a lot more info available in your > makefile. Have you looked at using scons (http://www.scons.org/) instead of make? > Also, if I use my version control software (currently gnu > arch) to see what's changed, for example, I get a list of changes files > which again gives me more info because I know a file corresponds to a > class. > So, I can do a number of such small things using that convention that > works well with standard old UNIX tools. And I find that valuable. Sometimes little conveniences lead to great big tar pits. > As for the dependencies- I'm trying to keep the specification of them > simple. From a design point of view, it makes sense to me to only > specify ONCE that largeish-collection-of-classes-A depends on > largeish-collection-of-classes-B. As another simple small example: say > I change the name of large-collection-of-classes-B - this way I only > need to do it once, else I need to grep and sed all over in order to do > it. > > It just feels cleaner and easier. This is what packages are for. As far as refactoring package alignments, a little bit of scripting goes a long way. Sometimes trying to make an existing tool do something that it's not really right for distorts the entire process, rather than simplifies it. John Roth > > -i > From duncan.booth at invalid.invalid Mon May 2 11:16:39 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 2 May 2005 15:16:39 GMT Subject: Setting win32 console title from Python References: <1114684215.236448.212970@g14g2000cwa.googlegroups.com> <1114696780.653849.220080@o13g2000cwo.googlegroups.com> <1114698836.708809.32780@o13g2000cwo.googlegroups.com> <1114717354.209028.30270@z14g2000cwz.googlegroups.com> Message-ID: runes wrote: > Hi Duncan, sorry, I was unprecise. I'm thinking of a script, called > t.py that can be used in the console like an ordinary command. Som if > I change directory from S:\scripts to d:\projects and execute the > script the title changes to "projects" etc. > > I have that functionality today with a combination of a python script > and a batch file. I just wondered if I could use python all the way. > Apparently I cannot. > I think not, although you probably can do it with only the batch file. :) From Scott.Daniels at Acm.Org Thu May 19 00:18:29 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 18 May 2005 21:18:29 -0700 Subject: Comparing 2 similar strings? In-Reply-To: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> References: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> Message-ID: <428c0d21$1@nntp0.pdx.net> William Park wrote: > How do you compare 2 strings, and determine how much they are "close" to > each other? Here's a really weird idea: Measure the size difference between the pair of strings compressed together and compressed separately. --Scott David Daniels Scott.Daniels at Acm.Org From jrastrick at student.usyd.edu.au Wed May 18 02:11:21 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 17 May 2005 23:11:21 -0700 Subject: "End Of Line" Confusion In-Reply-To: <1116370499.324399.8920@z14g2000cwz.googlegroups.com> References: <1116370499.324399.8920@z14g2000cwz.googlegroups.com> Message-ID: <1116396681.298692.289380@g43g2000cwa.googlegroups.com> Well, copying and pasting this text, and changing <<>> to Foo so that its a legal Python identifier (why did you not want to name your class, out of curiosity), I get no problems with this. class Foo: def digest(): ''' char[28] digest ( ) Return the digest of the strings passed to the update() method so far. This is a 28-byte string which may contain non-ASCII characters, including null bytes. ''' raise NotImplementedError, 'digest() is not yet implemented.' >>> foo = Foo() >>> foo <__main__.Foo instance at 0x00B30C38> So all I can suggest is that you have accidentally mixed double and single quotes, or there is a quote mark somewhere in the docstring in your copy of the code, or some strange, platform/system/text editor/etc specific bug is causing this, or i don't know what else. Oh and btw, I suspect, form the lack of @staticmethod on the line above def digest():, that you perhaps meant def digest(self): ? From me at privacy.net Fri May 13 06:57:53 2005 From: me at privacy.net (Dan Sommers) Date: 13 May 2005 06:57:53 -0400 Subject: function with variable arguments References: <1115977954.266898.141150@g49g2000cwa.googlegroups.com> Message-ID: On 13 May 2005 02:52:34 -0700, "Xah Lee" wrote: > i wanted to define a function where the number of argument matters. > Example: > def Range(n): > return range(n+1) > def Range(n,m): > return range(n,m+1) > def Range(n,m,step): > return range(n,m+1,step) > this obvious doesn't work. The default argument like > Range(n=1,m,step=1) obviously isn't a solution. > can this be done in Python? Assuming you're doing something more interesting than wrapping range: def Range( start, stop = None, step = 1 ): if stop == None: # i,e., we only got one argument stop = start start = 1 # rest of function goes here.... HTH, Dan -- Dan Sommers From rrr at ronadam.com Tue May 10 20:01:41 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 10 May 2005 20:01:41 -0400 Subject: Python 2.4 & BLT ? In-Reply-To: <4280f791$0$344$4d4efb8e@read.news.be.uu.net> References: <4280f791$0$344$4d4efb8e@read.news.be.uu.net> Message-ID: <42814B65.10300@ronadam.com> StepH wrote: > Hi, > > I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) > distibution... > > I'v try to download btlz-for-8.3.exe, but when i try to install it, i've > a msgbox saying to the file is corrupt... > > Any idea ? > > Thanks. > > StepH. Have you tried blt2.4z-for-8.4exe? http://blt.sourceforge.net _Ron From kent37 at tds.net Tue May 31 08:44:23 2005 From: kent37 at tds.net (Kent Johnson) Date: Tue, 31 May 2005 08:44:23 -0400 Subject: regular expression problem In-Reply-To: <1117527562.055872.93830@o13g2000cwo.googlegroups.com> References: <1117527562.055872.93830@o13g2000cwo.googlegroups.com> Message-ID: <429c5c02$1_2@newspeer2.tds.net> borges2003xx at yahoo.it wrote: > hi everyone > there is a way, using re, to test (for es) in > a=[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14] if a list b is > composed by three "sublists" of a separated or not by elements. > > if b=[a2,a3,a4,a7,a8,a12,a13] gives true because in a > we have [....,a2,a3,a3,...,a7,a8,...,a12,a13,...] > or b=[a1,a2,a5,a14] gives true because in a we have > [a1,a2,....,a5,...,a14] and so on... difflib.SequenceMatcher can do this for you: >>> a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14] >>> b = [2,3,4,7,8,12,13] >>> import difflib >>> sm = difflib.SequenceMatcher(None, a, b) >>> sm.get_matching_blocks() [(1, 0, 3), (6, 3, 2), (11, 5, 2), (14, 7, 0)] >>> b = [1, 2, 5, 14] >>> sm = difflib.SequenceMatcher(None, a, b) >>> sm.get_matching_blocks() [(0, 0, 2), (4, 2, 1), (13, 3, 1), (14, 4, 0)] You should test for len(sm.get_matching_blocks()) == 4 (the last element is a dummy) Kent From ionel.mc at gmail.com Tue May 24 14:07:50 2005 From: ionel.mc at gmail.com (ionel) Date: Tue, 24 May 2005 20:07:50 +0200 Subject: first release of PyPy In-Reply-To: <42934634.5060105@gmx.de> References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116880764.260884.286720@g49g2000cwa.googlegroups.com> <42934634.5060105@gmx.de> Message-ID: so what could this PyPy do in the future ? .. concretely ... hope this is not a stupid question -- ionel. From Bernd.Nawothnig at t-online.de Sun May 15 02:40:34 2005 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sun, 15 May 2005 08:40:34 +0200 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> <42866cb8.177725696@news.oz.net> <1116109657.494997.315650@o13g2000cwo.googlegroups.com> Message-ID: <2g7jl2-qf8.ln1@Bernd.Nawothnig.dialin.t-online.de> On 2005-05-14, M.E.Farmer wrote: > I explained what i meant in previous post there was nothing more than > just a discussion No. You claimed This will only create a tuple in memory But we just learned that this is not the case. > I have no real problem here just more of a sore point in style for > me. I feel that parens are quite overloaded and it can be confusing > to newbies. But if the parens are just fluff then get rid of them, it > is clearer * at least to me * ;) Reduced to this argument I have no objection. > There are enough things wrapped in parens nowadays it is starting to > look like lisp. Lisp is far from being ugly ;-) Bernd -- Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. [T. Jefferson] From rupole at hotmail.com Fri May 13 07:18:18 2005 From: rupole at hotmail.com (Roger Upole) Date: Fri, 13 May 2005 07:18:18 -0400 Subject: working directory for debugging in pythonwin References: <3eem0kF2ngvjU1@individual.net> <4283A2DE.7030503@sympatico.ca> <3ejeq4F3di4bU1@individual.net> Message-ID: <42848dd5$1_1@spool9-west.superfeed.net> You could pass the directory in as an optional extra argument to the script. Alternately, you might accept either a bare file name or a full path. Roger -- This signature was intentionally left blank. (except it's not, wtf ??????) "Thomas Pfaff" wrote in message news:3ejeq4F3di4bU1 at individual.net... > Colin J. Williams schrieb: >> Thomas Pfaff wrote: >> >>> Hello all, >>> >>> I started using the nice Pythonwin IDE together with Python 2.3 (I have >>> come to prefer its editor to IDLE). >>> My problem is, that when I want to run a script in the debugger, I can >>> give the script name and arguments, but I can't tell it in which >>> directory it should run. >>> >>> I googled this group but didn't find anything helpful so far. >>> >>> I could use some os.chdir in my code, but that's ugly and I neither want >>> to copy the script around to the places where I would like to test it. >>> >>> Any suggestions? >>> >>> Thanks in advance >>> >>> >>> Thomas >> >> Thomas, >> >> When you have initiated PythonWin, try opening (^O) the file you wish to >> debug. By selecting the file directory and file you have chosen the >> current working directory for the file. >> >> Alternatively, in the Windows Explorer, try right clicking on the py >> file you wish to debug. One of the options given is likely to be >> PythonWin. >> >> Colin W. > > Well this is what I do not want to do. > I want to have the script in some folder /source/myscript.py but run it > on data in e.g. /path/to/data/ like I would do on the commandline with > > $ cd /path/to/data > $ pypthon /source/myscript.py local-file.dat > > > Cheers, > > > Thomas ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From rrr at ronadam.com Wed May 11 18:31:53 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 11 May 2005 18:31:53 -0400 Subject: Python 2.4 & BLT ? In-Reply-To: <42823F8D.6010705@teledisnet.be> References: <4280f791$0$344$4d4efb8e@read.news.be.uu.net> <42823F8D.6010705@teledisnet.be> Message-ID: <428287D9.3080902@ronadam.com> StepH wrote: > Ron Adam a ?crit : > >>StepH wrote: >> >> >>>Hi, >>> >>>I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) >>>distibution... >>> >>>I'v try to download btlz-for-8.3.exe, but when i try to install it, >>>i've a msgbox saying to the file is corrupt... >>> >>>Any idea ? >>> >>>Thanks. >>> >>>StepH. >> >> >>Have you tried blt2.4z-for-8.4exe? >> >>http://blt.sourceforge.net > > > yes. When i try to execute it, a small msgbox apprea with the msg: > Corrupt installation detected! > > Any idea ? Sounds like it might not be a corrupted install exe file, but a previously installed version that is corrupted. Does the message box say anything else? With just "Corrupt installation detected!", it could also be a support file or missing dll that the installer needs. _Ron From tassilo.von.parseval at rwth-aachen.de Tue May 24 03:16:02 2005 From: tassilo.von.parseval at rwth-aachen.de (Tassilo v. Parseval) Date: Tue, 24 May 2005 09:16:02 +0200 Subject: What are OOP's Jargons and Complexities? References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> <3584469.Aerji1NdQr@yahoo.com> Message-ID: Also sprach John W. Kennedy: > alex goldman wrote: >> John W. Kennedy wrote: >> >> >>>Strong typing has been a feature of mainstream programming languages >>>since the late 1950's. >> >> I'm just curious, what do you mean by /strong/ typing, and which strongly >> typed languages do you know? > > Unfortunately, I have seen the meaning shift with the context. In Ada > '83, it means it is not possible to have the equivalent of a C > unprototyped function, and that mixed-type expressions tend to need > explicit casting. In other contexts (as here), I've seen it used to mean > simply that variables have definite types, and it is not possible > (except by the use of polymorphic classes) for a variable to change from > an integer to a float to a character string in the course of execution. > In this sense, compile-to-machine-code languages (ee.g., Fortran, COBOL, > C, C++, or Pascal), are generally strongly typed These are statically typed. The extent to which they are also strongly typed differs: C++ is probably a little more strongly typed than C, but by and large their typing is still fairly weak. Most often, languages with strong typing can be found on the functional front (such as ML and Haskell). These languages have a dynamic typing system. I haven't yet come across a language that is both statically and strongly typed, in the strictest sense of the words. I wonder whether such a language would be usable at all. Tassilo -- use bigint; $n=71423350343770280161397026330337371139054411854220053437565440; $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200); From a at b.c Thu May 5 11:17:52 2005 From: a at b.c (D H) Date: Thu, 05 May 2005 10:17:52 -0500 Subject: How to write this regular expression? In-Reply-To: References: Message-ID: Peter Hansen wrote: > could ildg wrote: > >> I need a regular expression to check if a string matches it. > > > Why do you think you need a regular expression? > > If another approach that involved no regular expressions worked much > better, would you reject it for some reason? > > -Peter A regular expression will work fine for his problem. Just match the digits separated by underscores using a regular expression, then afterward check if the values are valid. From skip at pobox.com Thu May 12 10:55:45 2005 From: skip at pobox.com (Skip Montanaro) Date: Thu, 12 May 2005 09:55:45 -0500 Subject: Sleepycat Bsdbd 4.3.27 and Python 2.4.1 In-Reply-To: <52DC70C1C1575C418CB033523A29CF1403AD5395@exchange2000.manord.com> References: <52DC70C1C1575C418CB033523A29CF1403AD5395@exchange2000.manord.com> Message-ID: <17027.28273.363262.337516@montanaro.dyndns.org> Marco> I've just compiled Python 2.4.1 on a linux box (RHEL 3AS) after Marco> having installed Berkeley DB 4.3.27 from sleepycat Software. Marco> During the configure/build process python correctly found the Marco> BSBDB library. ... Marco> File "/usr/local/lib/python2.4/bsddb/__init__.py", line 339, in _openDBEnv Marco> e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL) Marco> DBError: (156471272, 'Unknown error 156471272') Marco> Any hint or suggestion is welcom Was your shelve file created with an earlier version of Berkeley DB? If so, you probably have to update the file so it can be read by the new version. As part of the Berkeley DB install/upgrade you should probably have a db_upgrade command. Check it out. Skip From jhylton at gmail.com Sun May 22 13:12:35 2005 From: jhylton at gmail.com (Jeremy Hylton) Date: Sun, 22 May 2005 13:12:35 -0400 Subject: [ZODB-Dev] ZODB memory problems (was: processing a Very Large file) In-Reply-To: <200505211300.09563.usenet@terabytemusic.cjb.net> References: <200505211300.09563.usenet@terabytemusic.cjb.net> Message-ID: On 5/21/05, DJTB wrote: > [posted to comp.lang.python, mailed to zodb-dev at zope.org] [Following up to both places.] > I'm having problems storing large amounts of objects in a ZODB. > After committing changes to the database, elements are not cleared from > memory. Since the number of objects I'd like to store in the ZODB is too > large to fit in RAM, my program gets killed with signal 11 or signal 9... The problem here is a common one with a first attempt at using ZODB. The problem is that ZODB manages memory at the granularity of first-class persistent objects -- that is, instances of classes that inherit from Persistent. ZODB can move such objects in and out of memory at transaction boundaries, which allows your application to use many more objects than it has physical memory for. It looks like your application has a single persistent instance -- the root ExtendedTupleTable -- so there's no way for ZODB to manage the memory. That object and everything reachable from it must be in memory at all times. You need to re-structure the program so that is has more first-class persistent objects. If, for example, the ExtendedTuple objects inherited from Persistent, then they could reside on disk except when you are manipulating them. The ObjectInterning instance is another source of problem, because it's a dictionary that has an entry for every object you touch. The various other dictionaries in your program will also be memory hogs in they have very many entries. The typical way to structure a ZODB program is to use one of the BTrees implementation types instead of a dictionary, because the BTree does not keep all its keys and values in memory at one time. (Its internal organization is a large collection of first-class persistent objects representing the BTree buckets and internal tree nodes.) You must use some care with BTrees, because the data structure maintains a total ordering on the keys. (And a dictionary does not.) The ZODB/ZEO programming guide has a good section on BTrees here: http://www.zope.org/Wikis/ZODB/guide/node6.html Jeremy From steven.bethard at gmail.com Sun May 29 16:13:50 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 29 May 2005 14:13:50 -0600 Subject: how to convert string to list or tuple In-Reply-To: References: <1117383768.099922.308760@o13g2000cwo.googlegroups.com> Message-ID: Duncan Booth wrote: > Dan Bishop wrote: >> Or if you do use eval, don't give it access to any names. [snip] >> os.system("rm -rf *") >> Traceback (most recent call last): >> File "", line 1, in ? >> File "", line 0, in ? >> NameError: name 'os' is not defined > > Have you tried giving it the string '__import__("os").system("rm -rf *")'? > [Don't try that at home children!] But you can try it at home if you set __builtins__ to something other than the default: py> eval("""__import__("os").system('echo "hello"')""", dict(__builtins__=None)) Traceback (most recent call last): File "", line 1, in ? File "", line 0, in ? NameError: name '__import__' is not defined If you're just doing work with constants, the lack of access to any builtins is ok: py> eval("(1,2,3)", dict(__builtins__=None)) (1, 2, 3) I know there have been security holes in this technique before, but I looked at the archives, and all the old ones I found have been patched. (Or at least I wasn't able to reproduce them.) STeVe From grante at visi.com Thu May 5 22:44:43 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 06 May 2005 02:44:43 -0000 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: <117lmgrjssnlf04@corp.supernews.com> On 2005-05-05, Jeremy Bowers wrote: > Since I think he mentioned something about predicting how much > space it will take to print out, my suggestion is to run > through whatever printing routines there are and get a string > out, A step which will require him to tell the printing routine how many digits he wants printed. -- Grant Edwards grante Yow! FUN is never having at to say you're SUSHI!! visi.com From sarapythonlist at yahoo.com Sat May 7 12:07:11 2005 From: sarapythonlist at yahoo.com (Sara Khalatbari) Date: Sat, 7 May 2005 09:07:11 -0700 (PDT) Subject: path(file) Message-ID: <20050507160712.96547.qmail@web61105.mail.yahoo.com> Suppose I have a list of files & I wanna know their path. is there a command that helps me do so in python? Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html From ajikoe at gmail.com Mon May 9 14:13:44 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 9 May 2005 11:13:44 -0700 Subject: replace string patern with different value In-Reply-To: <1115653794.833258.236170@z14g2000cwz.googlegroups.com> References: <1115645021.903836.262590@z14g2000cwz.googlegroups.com> <1115653794.833258.236170@z14g2000cwz.googlegroups.com> Message-ID: <1115662424.641801.62960@f14g2000cwb.googlegroups.com> Thank you. From bwooster47 at gmail.com Thu May 5 09:20:20 2005 From: bwooster47 at gmail.com (bwooster47 at gmail.com) Date: 5 May 2005 06:20:20 -0700 Subject: Best way to convert a list into function call arguments? Message-ID: <1115299220.736781.54810@o13g2000cwo.googlegroups.com> I'm a newcomer to python - what is the best way to convert a list into a function call agruments? For example: list = (2005, 5, 5) date = datetime.date( list ) fails with: TypeError: function takes exactly 3 arguments (1 given) I assumed that since Python allows multiple assignments per statement, such as a, b, c = list the date call above should work... So, what is the best way to call date? This works, but looks clunky: date = datetime.date( list[0], list[1], list[2 ) Thanks! From sjuranic at gmail.com Thu May 5 10:39:34 2005 From: sjuranic at gmail.com (Steve Juranich) Date: Thu, 5 May 2005 07:39:34 -0700 Subject: SWIG and Python incompatibilities? In-Reply-To: <1115302774.850678.317130@g14g2000cwa.googlegroups.com> References: <1115302774.850678.317130@g14g2000cwa.googlegroups.com> Message-ID: <56190b6c0505050739e450b99@mail.gmail.com> On 5 May 2005 07:19:34 -0700, adsheehan at eircom.net wrote: > Hi all, > > Has anyone experienced issues incompatible versions of the above? > On solaris, we are experiencing suspect crashes & memory leaks? > > How do I determine which versions are proven to be > compatible/incompatible etc? We've used Swig 1.3.21 with a couple version of Python now (2.3.3, 2.3.4, 2.4, and now 2.4.1) without any problems. You might want to take a look at the code that Swig generates to see if that's really where your problems are coming from. Good luck. -- Steve Juranich Tucson, AZ USA From jbellis at gmail.com Wed May 4 19:07:28 2005 From: jbellis at gmail.com (Jonathan Ellis) Date: 4 May 2005 16:07:28 -0700 Subject: postgresql plpython bug References: Message-ID: <1115248048.454641.263020@f14g2000cwb.googlegroups.com> Mage wrote: > create or replace function trigger_keywords_maintain() returns trigger as $$ > return 'MODIFY' > $$ language plpythonu; > > update table set id = id where id = 7; > > ERROR: invalid input syntax for type timestamp: "2005-05-03 > 14:07:33,279213" > > I see that Python's timestamp format is not accepted by postgresql. First, you don't give enough context to see where your python code generates a timestamp, but in any case it's more of a limitation than a bug that plpython doesn't try to autoconvert certain datatypes. (Are you even returning a datetime class, or a string?) You could play around with strftime to try to get something postgresql will recognize, but it's probably easier to just return an epoch value which you can turn into a postgresql timestamp with the abstime function. -Jonathan From nothingcanfulfill at gmail.com Wed May 11 00:55:30 2005 From: nothingcanfulfill at gmail.com (ncf) Date: 10 May 2005 21:55:30 -0700 Subject: Python Args By Reference In-Reply-To: <1182j1daaepv6f4@corp.supernews.com> References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> <1182j1daaepv6f4@corp.supernews.com> Message-ID: <1115787330.723188.295610@f14g2000cwb.googlegroups.com> Ok, I'm relatively new to python (< 1 year experiance), yet I have had much experiance with other languages. I never really looked that deeply in the FAQ -- temporary lapse of stupidity(?). Thanks for the link, the concept seems to help. The two issues I am having in grasping all of this are as follows: 1) Being new to Python, terms like mutable and immutable. Although I have probably dealt with them in other languages, the terms by themselves are a little confusing, but managable overall, so this issue isn't so big. 2) LARGELY, my issue is as demonstrated by the following code. I was trying to accomplish an effect similar to what is possible in C. (Trying to make a pure-python FIPS-180-2 compliant implementation of the SHA-256 algorithm for more Python practice and to put into some code for a *trial* secure protocol.) Example C Code: #define P(a,b,c,d,e,f,g,h,x,K) \ { \ temp1 = h + S3(e) + F1(e,f,g) + K + x; \ temp2 = S2(a) + F0(a,b,c); \ d += temp1; h = temp1 + temp2; \ } Python Code: def P(a,b,c,d,e,f,g,h,x,K): temp1 = h + S3(e) + F1(e,f,g) + K + x temp2 = S2(a) + F0(a,b,c) d += temp1; h = temp1 + temp2 The reason why it'd be a pain to implement this by any of the methods provided in the Python FAQs is that SHA-256 rotates the variable order in the calls. Example code: P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 ); P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 ); P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF ); P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 ); P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B ); P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 ); P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 ); P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 ); P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 ); Since I cannot simply do it the way I had originally seen it, would there be an alternative method to proforming the operations that I am missing? Once again, many thanks for your time. -Wes From fuzzyman at gmail.com Thu May 5 06:42:54 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 5 May 2005 03:42:54 -0700 Subject: [ANN] Voidspace Guestbook 1.4.2 Message-ID: Oops, embarrasing bugix release time. Guestbook 1.4.1 worked fine (wonderfully even) with Python 2.4, but not with Python 2.3. This release fixes that, and also another Python 2.2 compatibility problem (yes I'm testing now...). Homepage : http://www.voidspace.org.uk/python/guestbook.html Example : http://www.voidspace.org.uk/cgi-bin/voidspace/guestbook2.py Quick Download : http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=guestbook.zip I might even have spelt my domain name right this time... Best Regards, Fuzzyman http://www.voidspace.org.uk/python From modelnine at ceosg.de Fri May 27 09:38:32 2005 From: modelnine at ceosg.de (Heiko Wundram) Date: Fri, 27 May 2005 15:38:32 +0200 Subject: Incrementing letters In-Reply-To: References: Message-ID: <200505271538.36838.modelnine@ceosg.de> Am Freitag, 27. Mai 2005 13:31 schrieb Michael: > if(C == 'z') C='a'; > else C++; if C == "z": C = "a" else: C = chr(ord(C)+1) -- --- Heiko. see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From peter at engcorp.com Mon May 16 12:54:16 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 May 2005 12:54:16 -0400 Subject: newbie - variable "buried in quotes" In-Reply-To: <1116260476.332975.87680@g49g2000cwa.googlegroups.com> References: <1116260476.332975.87680@g49g2000cwa.googlegroups.com> Message-ID: <7pmdnSlf65zMTRXfRVn-2A@powergate.ca> plsullivan wrote: > I've got a variable deep inside some quotes needed by the application I > am using. I can't figure out how to make this work. (Also, is there a > line continuation character?) > Thanks in advance, > Phil > > luser = win32api.GetUserName() > > gp.FeatureclassToCoverage_conversion("'Database > Connections\\%s at GIS_srv-earth.sde\\GIS.GIS.Cadastral\\GIS.GIS.Parcels' > POLYGON", prcl83, "", "DOUBLE") % luser The % operator goes immediately after the string on which it operates: gp.FeatureclassToCoverage_conversion("'Database Connections\\%s at GIS_srv-earth.sde\\GIS.GIS.Cadastral\\GIS.GIS.Parcels' POLYGON" % luser, prcl83, "", "DOUBLE") -Peter From ruses at users.snip.snip.ch Fri May 27 05:11:46 2005 From: ruses at users.snip.snip.ch (d'yeux le pair) Date: Fri, 27 May 2005 11:11:46 +0200 Subject: [OT] Re: Python analog of Ruby on Rails? In-Reply-To: References: <4294adc3$0$2526$626a14ce@news.free.fr> <1117073580.063476.125140@g14g2000cwa.googlegroups.com> Message-ID: <4296e3fc$1_1@news.bluewin.ch> Shane Hathaway a ?crit : > > BTW, here's the proper response to that religious thread that keeps > invading this list: > > python -c 'print sum([ord(c) for c in "HOLYBIBLE"])' > > I'm Christian and I think it's funny. ;-) Aha. Notice that the Original Sin story admits a defensible reading while equating the Holy Bible to the (in)famous tree. Some background: > > http://scriptures.lds.org/rev/13/16-18#16 Given context(s), I particularly like the solution (in .sig format) : 666?? -- 666 ~ .666 ~ 2/3 ~ 1-1/3 ~ tertium non datur ~ the excluded middle ~ "either you are with us, or you are against us" From eee at nmt.edu Mon May 16 09:52:54 2005 From: eee at nmt.edu (Earl Eiland) Date: Mon, 16 May 2005 07:52:54 -0600 Subject: command string good in subprocess.Popen(string) fails in process.Process(string) In-Reply-To: <9YSdnavxIbdvAhXfRVn-1w@powergate.ca> References: <9YSdnavxIbdvAhXfRVn-1w@powergate.ca> Message-ID: <1116251573.27141.634.camel@dulcevida> from Trent Mick trentm at ActiveState.com: "You might be able to use or borrow code from my process.py module. process.py is very similar to Python 2.4's subprocess. It provides a ProcessOpen class (similar to subprocess' Popen). A ProcessOpen instance has wait() and kill() methods that work fine on Windows. Under the hood they are using the Win32 API WaitForSingleObject() and TerminateProcess() functions." http://starship.python.net/~tmick/" On Mon, 2005-05-16 at 07:27, Peter Hansen wrote: > Earl Eiland wrote: > > The command string consists of "filename.exe instruction1 instruction2 > > ..." It works in subprocess, but in process, returns the error "can't > > find the file instruction1". > > > > How do I pass command line instructions in process.Process? I tried a > > list ['filename.exe', 'instruction1 instruction2 ...'] with the same > > result. > > Where are you getting this "process" module from? It's not standard: > > c:\>python > Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 > >>> import process > Traceback (most recent call last): > File "", line 1, in ? > ImportError: No module named process > > > -Peter From johnandsarah at estragon.freeserve.co.uk Sun May 1 18:05:04 2005 From: johnandsarah at estragon.freeserve.co.uk (John Perks and Sarah Mount) Date: Sun, 1 May 2005 23:05:04 +0100 Subject: MRO problems with diamond inheritance? Message-ID: Trying to create the "lopsided diamond" inheritance below: >>> class B(object):pass >>> class D1(B):pass >>> class D2(D1):pass >>> class D(D1, D2):pass Traceback (most recent call last): File "", line 1, in ? TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases D1, D2 Is this as intended? Especially since reversing the order makes it OK: >>> class D(D2, D1):pass >>> D.__mro__ (, , , , ) Why should order of base classes matter? This only affects types, old-style classes are unaffected. The workaround to this problem (if it is a problem and not a feature that I'm misunderstanding) is to put more-derived classes at the front of the list. I ran into this with dynamically-created classes, and sorting the bases list with the following comparator put them right: def cmpMRO(x,y): if x == y: return 0 elif issubclass(x, y): return -1 elif issubclass(y, x): return +1 else: return cmp(id(x), id(y)) Incidentally, is it safe to have an mro() method in a class, or is this as reserved as the usual __reserved_words__? Does Python use mro() (as opposed to __mro__) internally or anything? Thanks John From sjmachin at lexicon.net Fri May 20 07:24:10 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 20 May 2005 21:24:10 +1000 Subject: Comparing 2 similar strings? References: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> <153o811mt7uhqa3aojb5101sd7qo4jrgps@4ax.com> <3f567mF62qlfU1@uni-berlin.de> Message-ID: On 20 May 2005 04:09:26 GMT, ptjm at interlog.com (Patrick TJ McPhee) wrote: >In article <153o811mt7uhqa3aojb5101sd7qo4jrgps at 4ax.com>, >John Machin wrote: > >% None of the other approaches make the mistake of preserving the first >% letter -- this alone is almost enough reason for jettisoning soundex. > >Metaphone does, at least in the case of Aaron and Erin. You're quite correct; moreover NYSIIS does that too. Dunno what came over me, must be gamma rays or something :-) From bvande at po-box.mcgill.ca Thu May 12 09:54:44 2005 From: bvande at po-box.mcgill.ca (Brian van den Broek) Date: Thu, 12 May 2005 09:54:44 -0400 Subject: Launch file in Notepad In-Reply-To: <42835db6$0$1334$5fc3050@dreader2.news.tiscali.nl> References: <42835db6$0$1334$5fc3050@dreader2.news.tiscali.nl> Message-ID: <42836024.1040102@po-box.mcgill.ca> George said unto the world upon 2005-05-12 09:41: > Newbie question: > > I'm trying to lauch Notepad from Python to open a textfile: > > import os > b1="c:\test.txt" > os.system('notepad.exe ' + b1) > > However, the t of test is escaped by the \, resulting in Notepad trying > to open "c: est.txt". > > How do I solve this? There are several ways, but the preferred solution is to switch the slash direction: "c:/test.txt". Python's smart enough to notice its running on Windows and do the right thing with the slash. (Other choice include using raw strings: r"c:\test.txt", and explicitly escaping the backslash: "c:\\test.txt".) Best, Brian vdB From flupke at nonexistingdomain.com Tue May 10 08:33:39 2005 From: flupke at nonexistingdomain.com (flupke) Date: Tue, 10 May 2005 12:33:39 GMT Subject: Advice needed on __del__ In-Reply-To: References: <427FBAD4.3070004@anvilcom.com> <42800279.3B26FFF3@pauahtun.org> Message-ID: phil wrote: > A class instance based language doesn't have to BE C++ to have a > destructor method. > > All I wanted to know is: is the apparent treatment of __del__ > which SEEMS to work fine for me in 2.3.4 deprecated or mangled > in some later release or future plans. > If someone doesn't know the answer to this question or if noone > knows the answer to this question, I will still love and > respect the Python Community. In large part cause it ain't C++> I like to use destructors to and find the way __del__ works a bit strange. For instance if you want to use a class variable in the __del__ function it's possible that it's not reachable via . and then you have to call it via self.__class__.. I find this non intuitive. I heard the explanations why but that doens't make it more intuitive. Then i got a tip that you can register a function that needs to be called when the object is going to be deleted. For instance to register a function __exit, you do this: import atexit ... class Bla: def __init__(self) ... atexit.register(self.__exit) ... def __exit(self): It still doesn't feel right to me as i would rather use __del__ but since the behaviour can't be predicted, using atext is the next best thing Benedict From mefjr75 at hotmail.com Mon May 2 01:10:04 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 1 May 2005 22:10:04 -0700 Subject: Webbrowser On Windows In-Reply-To: <1115008759.797584.24510@f14g2000cwb.googlegroups.com> References: <1115008759.797584.24510@f14g2000cwb.googlegroups.com> Message-ID: <1115010604.189459.146210@o13g2000cwo.googlegroups.com> I played around with it. ############################################################################ import pythoncom from win32com.client import Dispatch ############################################################################ def webbrowser(url=None): ie = pythoncom.CoCreateInstance("InternetExplorer.Application", None, pythoncom.CLSCTX_SERVER, pythoncom.IID_IDispatch) ie = Dispatch(ie) ie.Navigate if url: ie.Navigate(url) ie.Visible = 1 return ie ############################################################################# import time w = webbrowser() w.Navigate('http://www.google.com') time.sleep(2) w.Navigate('http://dir.gmane.org/gmane.comp.python.general') time.sleep(2) webbrowser('http://groups-beta.google.com/group/comp.lang.python?hl=en&lr=') webbrowser('http://python.org') ############################################################################# M.E.Farmer From tjreedy at udel.edu Tue May 3 02:41:59 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 3 May 2005 02:41:59 -0400 Subject: WordPress Python Library 1.0 References: Message-ID: "Michele Ferretti" wrote in message news:VKwde.1322130$35.49403624 at news4.tin.it... Fran?ois Pinard wrote: > [Michele Ferretti] > >>http://www.blackbirdblog.it/programmazione/progetti/28 > > > Quoted above, the full content of your article. Is it a message? It > surely does not look like an English sentence. > > Should we start a browser each time we see an URL? Many of us are not > in such an Internet starvation. If you want to raise our appetite, > maybe a few words of introduction or explanation would be welcome. :-) > ok, sorry, but subject is very explicit! Michele, it is both polite and and uncontroversial standard practice in Pythonland for announcements to include a sentence or two or a short paragraph (in English) explaining what is being announced so people quickly know whether it is of any interest or not. Just watch here and you will see many examples. Terry J. Reedy From ladasky at my-deja.com Mon May 16 15:02:31 2005 From: ladasky at my-deja.com (ladasky at my-deja.com) Date: 16 May 2005 12:02:31 -0700 Subject: trouble with copy/deepcopy In-Reply-To: References: Message-ID: <1116270151.153816.195420@g47g2000cwa.googlegroups.com> Alexander Zatvornitskiy wrote: > Hello! > > I have trouble with copy/deepcopy. It seems, I just don't understand something. > Please explain where things goes wrong and how to do it the right way. > > I have one class: > > class Distribution: > __gr_on_transp=dict() > __ostatok_m=dict() > and so on > > And, I want to make full copy of it: > d1=Distribution() > d2=copy.deepcopy(d1) > > But, members-dictionaries are don't copied. For example if I will write: > d1.clear() > which clears all two dictionaries, I will find that d2's dictionaries are also > empty!!! > > Now I'am using the quick-hack: > > class Distribution: > __gr_on_transp=dict() > __ostatok_m=dict() > ... > def my_copy(self): > d2=copy.deepcopy(self) > d2.__gr_on_transp=self.__gr_on_transp.copy() > d2.__ostatok_m=self.__ostatok_m.copy() > return d2 > > It's work well, but I don't understand why previous is wrong and how to do it > in right way. > > Alexander, zatv at bk.ru Hello, Alexander, I just asked about deepcopy here in comp.lang.python a few weeks ago. Here is a link to that discussion: http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/41269228e1827a87 You have the right idea when you create a special method inside your class to handle the deepcopy operation. But if you call that method __deepcopy__, then copy.deepcopy() can find it and call it. In my code, it was also important that I declare my class as a new-style class, so that I could use the __new__ method. __new__ constructs a new instance of the class without initializing it. To make your class into a new-style class, you would write "class Distribution(object):" instead of just "class Distribution:". There are more details in the discussion that I referenced above. Hope that helps! -- Rainforest laid low. "Wake up and smell the ozone," Says man with chainsaw. John J. Ladasky Jr., Ph.D. From __peter__ at web.de Wed May 4 15:54:25 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 May 2005 21:54:25 +0200 Subject: How do you convert a string obj to a file obj? References: <42790d0c$0$79465$14726298@news.sunsite.dk> Message-ID: Matthew Thorley wrote: > Esben Pedersen wrote: >> Matthew Thorley wrote: >> >>> I'm writing a web app whereby a user uploads a tar acrhive which is then >>> opened and processed. My web form reads the file like this: >>> >>> while 1: >>> data = value.file.read(1024 * 8) # Read blocks of 8KB at a time >>> if not data: break >>> >>> which leaves me with data as a string obj. The problem that I have is >>> that the function that processes the archive expects a file object. So >>> far the only solution I have found it to write the file to disk and then >>> read it back. >>> >>> Is there an easy way to convert data, in the example above into a file >>> object? >>> >>> Thanks >>> -Matthew >> >> >> value.file is a file object. Why don't you give that as an argument? >> >> /Esben > > Ok I tried that but I still get this error. Any clue what I need to do? > > AttributeError: 'file' object has no attribute 'rfind' str has an rfind() method while file has not: >>> file.rfind Traceback (most recent call last): File "", line 1, in ? AttributeError: type object 'file' has no attribute 'rfind' >>> str.rfind So "the function" seems to expect a string rather than a file. Or perhaps there's an (evil) isinstance(param, file) check somewhere that triggers param to be treated as a filename. Absent further information, only you can find out. Peter From jepler at unpythonic.net Fri May 6 15:44:22 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 6 May 2005 14:44:22 -0500 Subject: New Python regex Doc (was: Python documentation moronicities) In-Reply-To: <1115328523.852744.110390@f14g2000cwb.googlegroups.com> References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113856843.023012.165500@l41g2000cwc.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> Message-ID: <20050506194422.GB27403@unpythonic.net> To add to what others have said: * Typos and lack of spell-checking, such as "occurances" vs "occurrences" * Poor grammar, such as "Other characters that has special meaning includes:" * You dropped version-related notes like "New in version 2.4" * You seem to love the use of
s, while docs.python.org uses them sparingly * The category names you created, "Wildcards", "Repetition Qualifiers", and so forth, don't help me understand regular expressions any better than the original document * Your document dropped some basic explanations of how regular expressions work, without a replacement text: Regular expressions can be concatenated to form new regular expressions; if A and B are both regular expressions, then AB is also a regular expression. In general, if a string p matches A and another string q matches B, the string pq will match AB. [...] Thus, complex expressions can easily be constructed from simpler primitive expressions like the ones described here. Instead, you start off with one unclear example ("a+" matching "aaaahh!") and one misleading example (a regular expression that matches some tiny subset of valid e-mail addresses) * You write Characters that have special meanings in regex do not have special meanings when used inside []. For example, '[b+]' does not mean one or more b; It just matches 'b' or '+'. and then go on to explain that backslash still has special meaning; I see that the original documentation has a similar problem, but this just goes to show that you aren't improving the accuracy or clarity of the documentation in most cases, just rewriting it to suit your own style. Or maybe just as an excuse to write offensive things like "[a] fucking toy whose max use is as a simplest calculator" I can't see anything to make me recommend this documentation over the existing documentation. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From rschroev_nospam_ml at fastmail.fm Thu May 12 16:17:23 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 12 May 2005 20:17:23 GMT Subject: Python Polymorphism In-Reply-To: References: Message-ID: Carlos Moreira wrote: > So, let's try again. > Supose that I want to create two methos (inside a > class) with exactly same name, but number of > parameters different: > > class myClass: > myAttribute = 0 > def myMethod(self): > self.myAttribute += 1 > def myMethod(self, myValue): > self.myAttribute += myValue > > Both method hold same identifier, the only difference > in them signture are parameters. > How could I simulate the situation above, using the > language dynamic link (or polymorphism, as you > prefer)? Ah, that's not polymorphism; it's method overloading. And AFAIK it is not possible in Python. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From dave at pythonapocrypha.com Thu May 19 10:42:55 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Thu, 19 May 2005 08:42:55 -0600 Subject: Is Python suitable for a huge, enterprise size app? In-Reply-To: <7xd5rn93zi.fsf@ruckus.brouhaha.com> References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116443474.565264.176640@g44g2000cwa.googlegroups.com> <7xd5rn93zi.fsf@ruckus.brouhaha.com> Message-ID: <428CA5EF.5020306@pythonapocrypha.com> Paul Rubin wrote: > "Kay Schluehr" writes: >>To answer Your initial question: there is probably no technical reason >>against Python as a language or the CPython runtime. Both are very >>stable and mature. > > > I'd like to agree with this but I just can't. Python is a great > language for prototyping and trying stuff out. It's fast and pleasant > to write. But you're right when you say that constant testing and > integration is absolutely necessary to develop anything substantial in > Python. [snip] > I'm in the middle of prototyping something in Python and it's going > pretty well despite occasional snags like those mentioned above. But > at the end of the day I don't think what we get will be solid enough > for use in production. We're planning to use the Python prototype to > get the feature set and protocols figured out, then reimplement in Java. > The OP might consider that approach. You bring up some good points and I imagine the bugs you've encountered are pretty frustrating, but I'm surprised at how different our experience has been. I know my comments about Python probably come across a "total fan boy" - but for us Python has been extremely positive. We currently use Python, in production, in the following ways: - custom HTTP web servers - custom HTTP proxies - behind-the-scenes log processors and other operational tools - several Zope-based applications, both internally and externally facing - both the client and server sides of a distributed work cluster - the client side of a media encoding farm (server is a Zope app) - a downloadable Windows client that our customer's customers use, that includes a Windows COM server (an ActiveX control we implemented using ctypes). Most of these have been in production for a year or more, with the oldest being about 4 years (not a long time, but certainly long enough to be considered stable). The toughest pieces initially were the Zope apps and the Windows COM stuff - Zope because of documentation and COM because, well, it's COM. During that time, the biggest problem we had with Python and its standard libraries was one issue with socket.recv and memory allocation when doing lots of receives. That lost us a few days of hunting for a memory leak, but we were able to resolve it by looking at the C source. Another problem was the need to call unlink (or something like that) on XML minidom elements in some circumstances. Apart from that, we haven't encountered much of anything in terms of bugs in the language or the standard library in *years*. In fact, I don't recall encountering a bug in the language itself. We've generally trailed the standard Python releases by about a year (although this week I moved the encoding farm to Python 2.4.1, which is half a year early). We don't use Tkinter. We don't use much outside the standard library: we make heavy use of ctypes, psycopg (Postgres), and lately CherryPy, but that's about it. So for us, the number of bugs in Python + stdlib has been really low. One thing from your experience that did resonate with me is that, except for ftplib and occasionally urllib (for basic, one-shot GETs), we don't use any of the standard library's "protocol" modules - partly because we had to implement our own HTTP libraries for performance and scalability reasons anyway, and partly because we had trouble figuring out e.g. all the ins and outs of urllib/urllib2/httplib. Overall it's been such a positive experience for us that nobody in the company - from grunt testers up to the CTO - has any reservations about using Python in production anymore (even though initially they all did). All of the developers have previous experience with using Java in production systems, and none seriously consider it for new projects at all. -Dave From ognjen at mailshack.com Mon May 30 12:09:02 2005 From: ognjen at mailshack.com (Ognjen Bezanov) Date: Mon, 30 May 2005 17:09:02 +0100 Subject: How to run functions in the background? Message-ID: <429B3A9E.9060201@mailshack.com> Hello I need to find a way to 'fork' a function into the background yet still be able to send commands to it. I am writing a media player, and I have a function which plays the media. I want to be able to run this function but to (at the same time) be able to send commands from it (e.g. pause, play etc...) How could I do this? any help appreciated. From ken.boss at dnr.state.mn.us Tue May 31 09:58:59 2005 From: ken.boss at dnr.state.mn.us (ken.boss at dnr.state.mn.us) Date: 31 May 2005 06:58:59 -0700 Subject: change vars in place w/loop or list comprehension Message-ID: <1117547939.650578.316090@g47g2000cwa.googlegroups.com> I am a python newbie, and am grappling with a fundamental concept. I want to modify a bunch of variables in place. Consider the following: >>> a = 'one' >>> b = 'two' >>> c = 'three' >>> list = [a, b, c] >>> for i in range(len(list)): ... list[i] = list[i].upper() ... >>> [a, b, c] = list >>> a 'ONE' or, better: >>> a = 'one' >>> b = 'two' >>> c = 'three' >>> [a, b, c] = [s.upper() for s in [a, b, c]] >>> a 'ONE' Both of these accomplish what I'm after; I prefer the second for its brevity. But either approach requires that I spell out my list of vars-to-alter [a, b, c] twice. This strikes me as awkward, and would be difficult with longer lists. Any suggestions for a better way to do this? --Ken From bram at geenspam.sara.nl Tue May 24 07:20:01 2005 From: bram at geenspam.sara.nl (Bram Stolk) Date: Tue, 24 May 2005 13:20:01 +0200 Subject: IRIX MipsPro compiler chokes on Python.h Message-ID: <1116933601.457261@blaat.sara.nl> Hi there, I just built and installed Python-2.4.1 on my Irix machine. My compiler, the MipsPro compiler, chokes on the Python.h include file, as demonstrated here: $ CC -v MIPSpro Compilers: Version 7.41 $ python -V Python 2.4.1 $ cat l.cxx #include int main() { return 0; } $ CC -I $HOME/include/python2.4 l.cxx cc-1311 CC: ERROR File = /usr/include/sys/time.h, Line = 186 The indicated linkage specification is incompatible with previous "select" (declared at line 479 of "/usr/include/unistd.h"). static int select( ^ 1 error detected in the compilation of "l.cxx". Has anyone experienced the same? How do I solve this? Thanks, Bram Stolk From python at rcn.com Thu May 26 01:39:10 2005 From: python at rcn.com (Raymond Hettinger) Date: 25 May 2005 22:39:10 -0700 Subject: Checking for a full house References: <1117071824.882035.250710@g49g2000cwa.googlegroups.com> Message-ID: <1117085950.739186.14240@z14g2000cwz.googlegroups.com> [mwdsmith] > Below is my code for checking for a full house (when rolling > with 5 dice). There are many ways to do this. Here's one: .def isfullHouse(hand): . counts = [hand.count(card) for card in set(hand)] . return (3 in counts) and (2 in counts) and len(hand)==5 And here's a one-liner: .def isfullHouse(hand): . return sorted(hand.count(card) for card in set(hand)) == [2,3] Raymond Hettinger From andrew.markebo at comhem.se Wed May 18 11:00:10 2005 From: andrew.markebo at comhem.se (Andrew Markebo) Date: Wed, 18 May 2005 15:00:10 GMT Subject: Debugging from within emacs! Message-ID: Argh.. How do I debug my python-code from the inside of emacs, throw some breakpoints? and fire up the session, check backtraces and so on? /Andy Experimenting I have come this far: I have put a pdb.bat in my path, containing: "c:\Program Files\Python23\python.exe" -u "c:\Program Files\Python23\Lib\pdb.py" %1 %2 %3 %4 %5 %6 %7 %8 %9 In emacs I do M-x pdb , I get the Current directory is h:/WorkingWith/PyLabView/ h:\WorkingWith\PyLabView>"c:\Program Files\Python23\python.exe" -u "c:\Program Files\Python23\Lib\pdb.py" PyLVcomms.py > (1)?() (Pdb) Whatever I try to do now, like doing a step, I get (Pdb) step --Call-- and nothing happens.. restart, doing a "n" (pdb) n twenty;20;abc;3;abc {'twenty': ('int', 20), 'abc': ('string', 'abc')} --Return-- > (1)?()->None (pdb) -- "I [..] am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand." -- Douglas Adams, "Last Chance to See" -= May he rest in peace! =- From martijn at gamecreators.nl Mon May 9 11:28:26 2005 From: martijn at gamecreators.nl (martijn at gamecreators.nl) Date: 9 May 2005 08:28:26 -0700 Subject: include "apythonscript.py" In-Reply-To: <1115651334.811250.60520@o13g2000cwo.googlegroups.com> References: <1115648730.390588.158760@z14g2000cwz.googlegroups.com> <1115651334.811250.60520@o13g2000cwo.googlegroups.com> Message-ID: <1115652506.460144.173870@o13g2000cwo.googlegroups.com> Ah damn , that's the way. And what if you have a very big class and want to include some class functions ? class ThisIsAClass: def __init__(self): Here I want to import a class def From andrewm at object-craft.com.au Tue May 31 03:40:50 2005 From: andrewm at object-craft.com.au (Andrew McNamara) Date: Tue, 31 May 2005 17:40:50 +1000 Subject: Albatross 1.30 released Message-ID: <20050531074050.B44F57940DC@longblack.object-craft.com.au> OVERVIEW Albatross is a small toolkit for developing highly stateful web applications. The toolkit has been designed to take a lot of the pain out of constructing intranet applications although you can also use Albatross for deploying publicly accessed web applications. In slightly more than 4500 lines of Python (according to pycount) you get the following: * An extensible HTML templating system similar to DTML including tags for: - Conditional processing. - Macro definition and expansion. - Sequence iteration and pagination. - Tree browsing. - Lookup tables to translate Python values to arbitrary template text. * Application classes which offer the following features: - Optional server side or browser side sessions. - The ability to place Python code for each page in a dynamically loaded module, or to place all page processing code in a single mainline. * The ability to deploy applications as CGI, FastCGI, mod_python or a pure python HTTP server by changing less than 10 lines of code. The toolkit application functionality is defined by a collection of fine grained mixin classes. Nine different application types and six different execution contexts are prepackaged, you are able to define your own drop in replacements for any of the mixins to alter any aspect of the toolkit semantics. Application deployment is controlled by your choice of either cgi, FastCGI, mod_python, or BaseHTTPServer Request class. It should be possible to develop a Request class for Medusa or Twisted to allow applications to be deployed on those platforms with minimal changes. Albatross comes with over 170 pages of documentation. HTML, PDF and PostScript formatted documentation is available from the toolkit homepage. The toolkit homepage: http://www.object-craft.com.au/projects/albatross/ The Albatross mailing list subscription and archives: http://object-craft.com.au/cgi-bin/mailman/listinfo/albatross-users CHANGES SINCE 1.20 * Any HTML tag can now be prefixed with "al-" allowing any attribute to be the result of python evaluation. For example: could produce and: could produce * Since macros and lookups are an application global resource, they can only be defined once per application, however this was not previously checked. Redefinition of macros or lookups will now result in an ApplicationError exception. * an in-line version of the tag has been introduced, which is expanded in place if the tag has an expr= attribute. * a new tag has been added to allow templates to assert that specific Albatross features are available, or templating scheme version number is high enough. * "Cache-Control: no-cache" is now set in addition to "Pragma: no-cache" - the former is defined for HTTP/1.1, the later for HTTP/1.0. * Simplified session cookie handling. BUGFIXES SINCE 1.20: * FastCGI apps were not being explicitly finalised, relying instead on their object destructor, with the result that writing application output (or errors) would be indefinitely deferred if object cycles existed. We now call "fcgi.Finish()" from the fcgiapp Request.return_code() method. * When handling exceptions, the traceback is now explicitly deleted from the local namespace to prevent cycles (otherwise the garbage collection of other objects in the local namespace will be delayed). * Two fixes to the tag: the albatross-specific "list" attribute was leaking into resulting markup, and the use of the "expr" attribute would result in invalid markup being emitted. * Thanks to Robert Fendt for picking this up: the Albatross-generated hidden field input element must not appear naked inside a form element for strict HTML conformance. The solution is to wrap the input elements in div. * BranchingSession sessions could not be "deleted" - the solution is to add a dummy "session" shared by all branches, which is deleted when one branch "logs out". -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ From ken.miller at entouch.net Tue May 10 21:45:56 2005 From: ken.miller at entouch.net (Kenneth Miller) Date: Tue, 10 May 2005 20:45:56 -0500 Subject: Python Graphing Utilities. References: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> Message-ID: <74GdnUgFNZNK_hzfRVn-3Q@entouch.net> Unix, not windows >< "Ron Adam" wrote in message news:mailman.319.1115770687.29826.python-list at python.org... > Kenneth Miller wrote: > > > Hello All, > > > > I am new to Python and i was wondering what graphing utlities would be > > available to me. I have already tried BLT and after weeks of unsuccesful > > installs i'd like to find something else. Anything someone would recommend? > > > > Regards, > > Ken > > > BLT doesn't install in the correct directories on Windows. I found this > helpful. > > 1. Install BLT 2.4u into C:/Python23/tcl, using BLT's installer > (the one for Tcl/Tk 8.3). This gives you bin, include, and lib > subdirectories of C:/Python23/tcl, with all the BLT stuff in them. > 2. Copy C:/Python23/tcl/lib/blt2.4 into C:/Python23/tcl/tcl8.3. > 3. Put the BLT DLLs in a directory on your PATH (not necessarily a > system directory, it just has to be on your PATH) > > Clipped from: http://heim.ifi.uio.no/~hpl/scripting/software.html > > > Cheers, > _Ron > > > > > > > From kay.schluehr at gmx.net Mon May 9 14:18:10 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 9 May 2005 11:18:10 -0700 Subject: __brace__ (PEP?) In-Reply-To: References: <1115617678.841460.294970@z14g2000cwz.googlegroups.com> Message-ID: <1115662690.004315.163360@f14g2000cwb.googlegroups.com> Roy Smith wrote: > "Kay Schluehr" wrote: > > > Roy Smith wrote: > > > > > foo->bar ==> foo.__arrrow__(bar) > > > foo$bar ==> foo.__dollar__(bar) > > > foo#bar ==> foo.__hash__(bar) > > > foo::bar ==> foo.__scope__(bar) > > > > I'm strongly in favor for the arrow ( but with two "r" only ). The > > question is simply: for what? > > I'm confused. You're strongly in favor of a piece of punctuation even > though you don't have any idea what it might be used for? Shurely I was joking. I could imagine a few purposes most likely arrows of some category. That's what You depicted using the "==>" arrow, that translates some infix operator expression into it's method description. Arrows are some kind of 2-tuples that express a transition and which are "left-exact" i.e. there must be at most a right value to some left value. Example: (foo->bar) -> foo.__arrow__(bar) This is a recursive definition of the arrow which could be further expanded: ((foo->bar) -> foo.__arrow__(bar)) -> foo.__arrow__(bar).__arrow__(foo.__arrow__(bar)) etc. But something intrigues me and that is the prevalence of "foo" above "bar" i.e. the preimage above the image. I would like to see that one starts with the binary relation as the primary concept. A relation should be instantiated by two classes. Let be Rel(A,B) some relation created from classes A and B. The instances of Rel(A,B) would be arrows from A to B depicted as arrow diagrams: foo->bar -> rel.__arrow__(foo,bar) There is no absolute meaning of the arrow foo->bar, because it reflects only the particular relation instance rel. Besides this I guess Guido wants to use the arrow in the context of "optional static type declarations" for declaring the return type. I don't like this optional static stuff but the arrow is playing a role also in this proposal. Ciao, Kay From stephane.bronsart at teledisnet.be Tue May 10 14:04:02 2005 From: stephane.bronsart at teledisnet.be (StepH) Date: Tue, 10 May 2005 20:04:02 +0200 Subject: Python 2.4 & BLT ? Message-ID: <4280f791$0$344$4d4efb8e@read.news.be.uu.net> Hi, I'm not able to install BLT on my Python 2.4 (upgraded to 2.4.1) distibution... I'v try to download btlz-for-8.3.exe, but when i try to install it, i've a msgbox saying to the file is corrupt... Any idea ? Thanks. StepH. From peter at engcorp.com Sun May 8 14:14:16 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 08 May 2005 14:14:16 -0400 Subject: pyvm -- faster python In-Reply-To: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> Message-ID: Kay Schluehr wrote: > Stelios Xanthakis wrote: >>pyvm is a program which can run python 2.4 bytecode (the .pyc files). >>A demo pre-release is available at: >> http://students.ceid.upatras.gr/~sxanth/pyvm/ > > could You tell us a bit more about Your motivation to create an > alternative C-Python interpreter? There is AFAIK no such ambitious > project that has ever survived. .. If you check the URL more closely, you'll notice that this is a university site. It seem likely this being done at least partly as a school project, which is certainly motivation enough for such a thing, *even* if it doesn't survive (since it will pay for itself in learning). -Peter From ccurvey at gmail.com Wed May 11 14:59:41 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 11 May 2005 11:59:41 -0700 Subject: win32com and ADO In-Reply-To: <6Pidnf5ZQfVlzx_fRVn-pg@powergate.ca> References: <1115833669.142021.294080@g44g2000cwa.googlegroups.com> <6Pidnf5ZQfVlzx_fRVn-pg@powergate.ca> Message-ID: <1115837981.463733.117320@g43g2000cwa.googlegroups.com> Thanks Peter. I found the files that makepy generated (in $PYTHON_HOME/Lib/site-packages/win32com/gen_py). I've tried deleting the individual files, and the entire directory, and I'm still getting the error. (Maybe something was changed in the registry?) [Fun side note -- after deleting the files, I thought I would look in them for the EOF, but they stubbornly refused to regenerate, giving an error about "This file has already been processed". The only way I could regenerate the files was by deleting the win32com package via the control panel and re-installing.] In the generated files, I did find a reference to "EOF" (all caps) in something called _prop_map_get_. (I had tried a few different variations on Eof, but none of them worked.) At this point, the only way that I can get to the EOF property is to force the dynamic dispatch by importing from com.win32.client.dynamic, AND coding like this: rs = Dispatch("ADODB.RecordSet") rs.ActiveConnection = conn rs.Open("select * from foo") while not rs.EOF: doSomething() rs.MoveNext() I hope someone can lend me a clue before I edit all of these query instances... From martin at v.loewis.de Mon May 16 17:58:41 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 16 May 2005 23:58:41 +0200 Subject: Extracting pickle from Python In-Reply-To: References: Message-ID: <42891791$0$1827$9b622d9e@news.freenet.de> Philippe C. Martin wrote: > How would one go about extracting the pickle module from Python (ex: to make > a .a or a .dll) ? Pickle relies heavily on Python, so you most likely have to take the rest of Python as well when trying to integrate pickle elsewhere? Are you looking for pickle or cPickle? pickle.py is written in Python, so you need a full Python interpreter to run it. cPickle is written in C, so you could go away with less than a full interpreter, but it still calls a lot of Python interpreter functions. To integrate a Python interpreter, see the "Embedding and Extending" manual, in particular the "embedding" part. Essentially, you need to link with pythonxy.dll/libpythonxy.a. If you want a Python-free implementation of pickle, you best rewrite it yourself. The core of pickle is fairly easy. The tricky part is the extensibility: During unpickling, arbitrary Python functions can be invoked to reconstruct objects, and arbitrary classes can be instantiated, so you need to emulate constructors for all types that may be present in your pickle files. Regards, Martin From rogerb at rogerbinns.com Tue May 10 21:28:19 2005 From: rogerb at rogerbinns.com (Roger Binns) Date: Tue, 10 May 2005 18:28:19 -0700 Subject: pyvm -- faster python References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> Message-ID: > I am not very interested on C compatibility. That will rule out all the gui frameworks, SSL, cryptography and numerous other packages. Have a look at what happened to Prothon. What ultimately killed it was the problem of having a decent library. You don't have to make the C library compatibility totally high performance, but having any form of it there will make adoption by others easier. Roger From ssmith579 at aol.com Fri May 27 15:17:08 2005 From: ssmith579 at aol.com (ssmith579 at aol.com) Date: 27 May 2005 12:17:08 -0700 Subject: Get number of lines in file Message-ID: <1117221428.788567.10060@f14g2000cwb.googlegroups.com> I have read in a file and need to get the number of lines. cpn_file = open('Central Part number list.txt') cpn_version = cpn_file.read().split('\n') I want to know the number of elements in cpn_version. From domma at procoders.net Fri May 20 03:36:11 2005 From: domma at procoders.net (Achim Domma (Procoders)) Date: Fri, 20 May 2005 09:36:11 +0200 Subject: MySQLdb and Unicode Message-ID: Hi, I try to write unicode strings to a MySQL database via MySQLdb. According to the documentation I should pass 'utf-8' as keyword parameter to the connect method. But then I get the following error: Traceback (most recent call last): File "C:\develop\SyynX\unicode_test.py", line 7, in ? con=MySQLdb.connect(host='localhost',db='unicode_test',unicode='utf-8') File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 66, in Connect return Connection(*args, **kwargs) File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 134, in __init__ super(Connection, self).__init__(*args, **kwargs2) TypeError: 'unicode' is an invalid keyword argument for this function I'm using version 1.2 of MySQLdb. Any hint what I'm doing wrong? regards, Achim From mwm at mired.org Fri May 6 00:09:41 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 05 May 2005 23:09:41 -0500 Subject: So many things that need to be decided.... References: <86sm1584l4.fsf@guru.mired.org> <873bt1h3b6.fsf@localhost.localdomain> Message-ID: <86zmv95722.fsf@guru.mired.org> Nick Vargish writes: > Mage writes: > >> - identing with tabs > > Indenting with tabs is pretty much frowned upon in Python, as Guido > relates in PEP 8: > > http://www.python.org/peps/pep-0008.html > > I guess it doesn't matter much if you are the only person who will > ever touch your code, and you never, ever, accidentally mix spaces and > tabs... What the OP probably meant was that the development environment inserts the appropriate number of spaces when you hit the tab key. I'd hate to work on Python - or in any group development environment - where that wasn't the case. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From brian at mirror.org Sun May 8 15:38:30 2005 From: brian at mirror.org (brian at mirror.org) Date: 8 May 2005 12:38:30 -0700 Subject: py2exe and library.zip In-Reply-To: References: <5uadnUTTqv6Iw-rfRVn-qw@powergate.ca> <4277EF15.2030605@open-networks.net> <8c7f10c6050504032010d9920@mail.gmail.com> <4278A377.3000504@open-networks.net> <8c7f10c605050403363c34f97c@mail.gmail.com> Message-ID: <1115581109.965038.154880@z14g2000cwz.googlegroups.com> > > >The zip file essentially contains the whole system in on lump. Change > >the system, and naturally your users will have to download the whole > >lump again. [...] > > > but if it was just a dir, when they update from the svn at log in, all > they do is download the extra\changed files. much much quicker then > downloading a 4 meg uncompressed zip file. Not clear what you are really asking for, but maybe this will help. I have a application that is 95% normal code, packaged up via py2exe. Other 5% is a few .py files in a separate directory, modified regularly by the users (report specifications in some lists/dicts). These files are *excluded* from the py2exe build, and I manually add this directory to sys.path during the application startup. A change to one of the spec files is picked up like any normal python session, and I don't need to rebuild the entire app. Could you do the same type of thing? Brian. From greg.steffensen at gmail.com Sun May 29 17:23:21 2005 From: greg.steffensen at gmail.com (gsteff) Date: 29 May 2005 14:23:21 -0700 Subject: Process monitoring In-Reply-To: References: <1116543944.348711.11910@g43g2000cwa.googlegroups.com> Message-ID: <1117401801.340936.20350@f14g2000cwb.googlegroups.com> Thanks- subprocess was exactly what I needed. For anyone else that reads this, I just launched a new subprocess via subprocess.Popen, did what I needed to do in a while look, while calling the poll method of the Popen object to check whether it was finished, and if so, what its error code was. Pretty simple. From pdemb at gazeta.pl Thu May 12 15:06:31 2005 From: pdemb at gazeta.pl (Peter Dembinski) Date: Thu, 12 May 2005 21:06:31 +0200 Subject: Python features References: <1115536911.106882.166230@z14g2000cwz.googlegroups.com> Message-ID: On Sun, 08 May 2005 10:02:42 +0200, Andr? Roberge wrote: [...] > google for "python" and "functional"; first link: > http://www-106.ibm.com/developerworks/linux/library/l-prog.html [...] > Imperative programming languages are the most commonly used languages. > Examples of this type of language are C, C++, Ada, Fortran, Algol, Java, > Python, Perl, and so on. How about lambda construction? Isn't Python imperative language that includes some functional mixins? I mean -- can you say Python is fully imperative language? If you want to redirect me to Google, don't bother. IMO ninety percent of writings found on WWW is just a garbage. -- http://www.peter.dembinski.prv.pl From kent37 at tds.net Thu May 26 16:37:28 2005 From: kent37 at tds.net (Kent Johnson) Date: Thu, 26 May 2005 16:37:28 -0400 Subject: Access from one class to methode of other class In-Reply-To: <3fmd51F8j4sfU1@news.dfncis.de> References: <3flu22F8g4u4U1@news.dfncis.de> <3fmd51F8j4sfU1@news.dfncis.de> Message-ID: <42963377$1_2@newspeer2.tds.net> VK wrote: >> On Thu, 26 May 2005 14:33:45 +0200, VK <"myname"@example.invalid> >> declaimed the following in comp.lang.python: >> >> >>> Hi, all! >>> >>> In my programm i have to insert a variable from class 2 to class 1 >>> and I get error NameError: global name 'd' is not defined. How do I >>> get access to d.entry.insert() method of class 1 > > from Tkinter import * > > class First: > def __init__(self): > self.root = Tk() # create window contents as children to > root.. > self.entryframe = Frame(self.root) > self.entryframe.pack(fill=BOTH,expand=1) > > self.entry = Entry(self.entryframe) > self.entry.pack(side=TOP,expand=1,fill=BOTH) > self.entry.focus() > self.entry.bind('',(lambda event: self.fetch())) # > on enter key > > self.button = > Button(self.entryframe,text="Call",command=self.getvar) > self.button.pack(side=LEFT,expand=YES,fill=BOTH) > > self.root.mainloop() > > def fetch(self): > print 'Input => "%s"' % self.entry.get() # get text form entry > > def getvar(self,event=0): > c=Second(self,self.root) > > > > class Second: > def __init__(self,parent,s="thing"): > self.root = Tk() > self.ent = Entry(self.root) > self.ent.pack() > self.btn = Button(self.root,text='Fetch',command=self.fetch) > self.btn.pack(side=RIGHT) > def fetch(self): > text = self.ent.get() # get text form entry in this window > d.entry.insert(0, text)# must insert in other window > > d = First() #First window The problem is that First.__init__() never returns so the instance of First is never bound to d. Take the line self.root.mainloop() out of First.__init__() and and the line d.root.mainloop() at the end of the program and it will work as you expect. Kent From enleverlesO.OmcO at OmclaveauO.com Mon May 23 16:35:04 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Mon, 23 May 2005 22:35:04 +0200 Subject: no win32com.client References: <1116878775.133106.240430@z14g2000cwz.googlegroups.com> <1116879334.341631.245570@z14g2000cwz.googlegroups.com> Message-ID: <42923f1e$0$11688$8fcfb975@news.wanadoo.fr> Hi ! Or : http://sourceforge.net/project/showfiles.php?group_id=78018 @-salutations -- Michel Claveau From geon at post.cz Sat May 28 12:21:46 2005 From: geon at post.cz (pavel.kosina) Date: Sat, 28 May 2005 18:21:46 +0200 Subject: Tkinter slowes down In-Reply-To: References: Message-ID: Fredrik Lundh napsal(a): > when you add an item to the canvas, it's part of the canvas > until you remove it. if performance drops, it's usually because > you keep adding new items without removing the old ones. > > try adding a w.delete(ALL) call before you "repaint". > In the meantime I found that widget.destroy() works well, too (before "repainting"). Thanks a lot -- geon Vyj?mka je pravidlo. Rekurzivn?. From apardon at forel.vub.ac.be Mon May 23 05:33:31 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 23 May 2005 09:33:31 GMT Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116440427.255902.36260@g49g2000cwa.googlegroups.com> Message-ID: Op 2005-05-20, Dieter Maurer schreef : > "Fredrik Lundh" writes on Thu, 19 May 2005 09:54:15 +0200: >> ... >> and unless your operating system is totally braindead, and thus completely unfit >> to run huge enterprise size applications, that doesn't really matter much. leaks >> are problematic, large peak memory use isn't. > > Could you elaborate a bit? > > Large peak memory use means that the application got a large > address space. What garantees that the residual memory use > (after the peak) is compact and not evenly spread across > the address space. Well nothing. But how do you want to return memory back to the O.S. when the residual memory use isn't compact and evenly spread across the address space? -- Antoon Pardon From slayer.bbs at bbs.wretch.cc Thu May 5 02:27:14 2005 From: slayer.bbs at bbs.wretch.cc (slayer) Date: 05 May 2005 06:27:14 GMT Subject: [newbie] how to look up functions Message-ID: <4I4S42$89a@bbs.wretch.cc> Hi all, I am a python newbie. I need some help to loop up about API, or reference. If any web that Java API Document, I will try it. Is there some one like it or other ways? -- ????????????????????????????????????? ?????BBS telnet://bbs.wretch.cc ???? ?? ??????????? ????????????????????????????????????? ????????????????????????????????????? ?????????????????????? pc210-59-94-118.nutn.edu.tw? From beyer at imb-jena.de Thu May 19 16:19:41 2005 From: beyer at imb-jena.de (Andreas Beyer) Date: Thu, 19 May 2005 13:19:41 -0700 Subject: NaN support etc. Message-ID: <428CF4DD.8090108@imb-jena.de> /S?bastien Boisg?rault wrote:/ > But, practically, I have never found a platform where > the following fpconst-like code did not work: > > import struct > cast = struct.pack > > big_endian = cast('i',1)[0] != '\x01' > if big_endian: > nan = cast('d', '\x7F\xF8\x00\x00\x00\x00\x00\x00')[0] > else: > nan = cast('d', '\x00\x00\x00\x00\x00\x00\xf8\xff')[0] Exactly this code doesn't work. When executing it I get the error message: Traceback (most recent call last): File "float_tools.py", line 8, in ? nan = cast('d', '\x00\x00\x00\x00\x00\x00\xf8\xff')[0] error: required argument is not a float Maybe the second line should read: cast = struct.unpack However, the actual fpconst.py works fine. Thanks for the hints, Andreas From danb_83 at yahoo.com Thu May 19 17:14:38 2005 From: danb_83 at yahoo.com (Dan Bishop) Date: 19 May 2005 14:14:38 -0700 Subject: Byte-operations. References: Message-ID: <1116537278.532342.232080@o13g2000cwo.googlegroups.com> Dave Rose wrote: > I hope someone can please help me. A few months ago, I found a VBS file, > MonitorEDID.vbs on the internet. ...[snip]... > Anyway, the functions from VBS I don't know how to translate to Python are: > > # location(0)=mid(oRawEDID(i),0x36+1,18) > # location(1)=mid(oRawEDID(i),0x48+1,18) IIRC, the BASIC mid$ function is mid(string, start, length), where the starting index is 1-based. The Python equivalent is string[start-1:start-1+length], so these two lines would convert to location = [oRawEDID(i)[54:72], oRawEDID(i)[72:90]] > # #you can tell if the location contains a serial number if it starts > with 0x00 00 00 ff > # strSerFind=chr(0x00) & chr(0x00) & chr(0x00) & chr(0xff) The "chr" function is the same in Python as in VB. But unlike VB, you can use literals for special characters. strSerFind = '\x00\x00\x00\xFF' ...[snip]... > # tmpver=chr(48+tmpEDIDMajorVer) & "." & chr(48+tmpEDIDRev) In python, the string concatenation operator is "+" instead of "&". However, this line can be written more concisely as: tmpver = "%c.%c" % (48 + tmpEDIDMajorVer, 48 + tmpEDIDRev) But for single-digit integers, chr(48+n) is just an obscure way of writing str(n), so what it really means is: tmpver = "%s.%s" % (tmpEDIDMajorVer, tmpEDIDRev) > # if (Byte1 and 16) > 0: > # Char1=Char1+4 VB's "and" operator is a bitwise operator; the "if" statement is testing whether bit 4 is set in Byte1. The Python equivalent is if Byte1 & 0x10: Char1 += 4 From fredrik at pythonware.com Wed May 25 03:18:11 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 25 May 2005 09:18:11 +0200 Subject: Tkinter Text Question References: <200505241547.49091.jstroud@mbi.ucla.edu> Message-ID: James Stroud wrote: > I would like to get the index of the character closest to the pointer in a > Text, something like Canvas.find_closest(). I want it to bind to ''. > Does anybody know how this might be done? use w.index("@x,y" % (event.x, event.y)) to find the character "under" the pointer, and, if necessary, use w.bbox() and/or w.dlineinfo() on neighbouring characters/lines to find the "closest" (depending on your definition of closest). From prabapython at yahoo.co.in Wed May 4 07:16:33 2005 From: prabapython at yahoo.co.in (praba kar) Date: Wed, 4 May 2005 12:16:33 +0100 (BST) Subject: Difference between Python CGI applications and Php applications In-Reply-To: 6667 Message-ID: <20050504111633.4434.qmail@web8401.mail.in.yahoo.com> Dear all, I have a project that is conversion of Php Web applications into Python cgi applications. In my mind compare python-cgi php is better. But I want to know clearly. which one is better. so kindly show me the advantages of python-cgi compare to Php regards PRaba ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From tjreedy at udel.edu Wed May 11 22:48:31 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2005 22:48:31 -0400 Subject: Solipsis: Python-powered Metaverse References: <4280F03E.2070903@kzoo.edu> <428220D2.5070701@ulmcnett.com> Message-ID: "Paul McNett"

wrote in message news:428220D2.5070701 at ulmcnett.com... > Sure, that's how it is here in the US too. You have a modem/router > supplied by the cable or DSL company that provides DHCP and NAT for > outbound traffic. Comcast supplied me with a DHCP cable modem that comverts whatever the cable uses for transport to standard ethernet signals. I supplied the 4-port NAT ethernet router which seems to block at least some uninvited inbound traffic. > and what if both computers > wanted to participate on the port 6000 fun? Recently, I had one family member use my purchased account to logon to and play an online action game, which sends a constant stream of update info. Then, curious what would happen, I logged on, from a different computer but through the same router, with a temporary guest account. Somewhat to my surprise, it worked -- without touching the computer (XP) or router settings. And kept working the whole weekend. So there is a way to tag update packets so they can be reliably separated into two streams (and vice versa). Solipsis should be able to do the same. Terry J. Reedy From efoda5446 at yahoo.com Wed May 18 22:49:12 2005 From: efoda5446 at yahoo.com (Lorn) Date: 18 May 2005 19:49:12 -0700 Subject: Extracting multiple zip files in a directory In-Reply-To: <5vtn81h8qt9mk73etq0r3e02uqsdjf5jo1@4ax.com> References: <1116462658.723097.134390@g43g2000cwa.googlegroups.com> <5vtn81h8qt9mk73etq0r3e02uqsdjf5jo1@4ax.com> Message-ID: <1116470952.173588.200990@o13g2000cwo.googlegroups.com> Thanks John, this works great! Was wondering what your reasoning is behind replacing "filter" with the x for x statement? Appreciate the help, thanks again. Lorn From python-url at phaseit.net Tue May 3 12:08:03 2005 From: python-url at phaseit.net (Simon Brunning) Date: Tue, 03 May 2005 16:08:03 GMT Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 3) Message-ID: QOTW: "The security 'droids have decided that since the MS Office Suite is a 'standard' application then software written in MS Office VBA must be 'safe.' Any other development environments (such as Java, Perl, Cygwin) are 'unsafe' and can't be installed." - Peter Olsen "There's nothing wrong with open source projects catering to a market, and there's nothing wrong with running open source software on a proprietary operating system." - Steve Holden Efficiently running a regex over a large file: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6a91f75b5bef1d0d Readable switch construction without lambdas or dictionaries: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410692 Lexical Analysis, Python-style: http://jason.diamond.name/weblog/2005/04/26/lexical-analysis-python-style What happened at Python UK: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/72446ebe0271f3cf http://www.reportlab.org/~andy/accu2005/accu2005.html Europython 2005: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/3ac8419954f9094a PyCon Brasil is a success! http://www.livejournal.com/users/gniemeyer/ Using the logging module: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/412552 Sparklines in data: URIs: http://bitworking.org/news/Sparklines_in_data_URIs_in_Python Static typing is a sleeping policeman: http://www.itworld.com/AppDev/nls_ebiznaked050426/ Got some free time? The Python Challenge will fix that: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/7a755219ea1a5cec Let Python be Python: http://www.unixreview.com/documents/s=9700/ur0504k/ Yet another Python code sharing site: http://www.pycode.com/ Notable releases: ID3Writer http://www.comfortableshoe.co.uk/cgi-bin/blosxom.cgi/Home/Python/id3Writer.comments Snakelets 1.40 http://snakelets.sourceforge.net/ Roundup 0.8.3 http://roundup.sourceforge.net/ wxPython 2.6.0.0 http://wxpython.org/ PyDev 0.9.3 http://pydev.sourceforge.net/ PythonCAD 24 http://www.pythoncad.org/ ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From gtcopeland2002 at yahoo.com Fri May 6 14:15:12 2005 From: gtcopeland2002 at yahoo.com (Greg Copeland) Date: 6 May 2005 11:15:12 -0700 Subject: inheritance with new-style classes - help In-Reply-To: <1115402296.414753.324000@f14g2000cwb.googlegroups.com> References: <1115402296.414753.324000@f14g2000cwb.googlegroups.com> Message-ID: <1115403312.031793.204560@f14g2000cwb.googlegroups.com> Doh! Child's __init__ was declared as __init(). Fixing that took care of it! Sorry for wasting the bandwidth! Cheers, Greg From a-steinhoff at web.de Tue May 17 10:04:14 2005 From: a-steinhoff at web.de (Armin Steinhoff) Date: Tue, 17 May 2005 16:04:14 +0200 Subject: PyXML/expat and the empty elements In-Reply-To: References: Message-ID: Armin Steinhoff wrote: > > > Hi all, > > is it possible to get the name of an empty element specified > by ... the expat parser seems only to recognize > the form > > Regards > > Armin Ok ... found the root of the problem. The expat parser is OK :) Regards Armin From anthra.norell at tiscalinet.ch Fri May 6 06:58:23 2005 From: anthra.norell at tiscalinet.ch (Anthra Norell) Date: Fri, 6 May 2005 12:58:23 +0200 Subject: Setting the corner color in rotated PIL images References: Message-ID: <052501c5522a$85e7eb40$0201a8c0@mcuf7> What do you mean 'is required'? I tend to think that getting ahead with a job is what is required. I don't sneer at work-arounds if they save time. Frederic A somewhat craftier solution, if still pretty hackish, would be to go through your image pixel by pixel, look what color each one is (color = image.getpixel (here)) and change the ones with the wrong color (if color == wrong_color: putpixel (here, right_color)). If the color of the corners does not occur inside your picture, you can go throught the entire image. Else you'd have to stop changing colors at the first occurrence of a pixel that does not have the wrong color, coming inward from each of the lateral edges. (Code below (untested)). If you have elements in your picture that not only have the same color as the corners, but also run into them, then you might have to refine your code further in order for the inner loop not stray into the image. # Left edge for y in range (image.size [1]): for x in range (image.size [0]): color = image.getpixel ((x,y)) if color != WRONG_COLOR: break image.putpixel ((x,y), RIGHT_COLOR) # Right edge for y in range (image.size [1]): for x in range (image.size [0]-1), -1, -1): color = image.getpixel ((x,y)) if color != WRONG_COLOR: break image.putpixel ((x,y), RIGHT_COLOR) ----- Original Message ----- From: "rzed" Newsgroups: comp.lang.python To: Sent: Tuesday, May 03, 2005 8:13 PM Subject: Re: Setting the corner color in rotated PIL images > "Anthra Norell" wrote in > news:mailman.91.1115117893.6583.python-list at python.org: > > [in response to: > >> I'm using PIL to generate some images which may be rotated at > >> the user's option. When they are rotated, the original image is > >> cropped in the new image (which is fine), and the corners are > >> black (which is not, in this case). I can't find any documented > >> way to change the default fill color (if that's what it is) for > >> the corners, and PIL also doesn't seem to support a flood fill. > >> I have created a flood fill in Python, which works but which > >> markedly slows image generation.] > > > I just had the same problem the other day. I solved it by > > starting out with an image large enough to retain enough white > > area following the rotation. > > Well, that's a workaround I could try, but I'm half-hearted about > it. I don't like to think that it's *required*. Another possible > solution is to make the outer portion black, so the rotation seems > to do the right things, but in the cases I'm dealing with, that's > either out or more trouble than it's worth. I can haul the rotated > images into a paint program and manually touch up the corners, too, > but I don't like to have to do that either. > > It seems strange that there wouldn't be some way to change the > black to another color, or (maybe just as good) to transparent. PIL > is so useful that it strikes me as an aberrant oversight. More > likely, there *is* a better way, but I just don't know it and can't > find it in the docs. > > -- > rzed > > -- > http://mail.python.org/mailman/listinfo/python-list From phillip.watts at anvilcom.com Wed May 4 12:04:10 2005 From: phillip.watts at anvilcom.com (phil) Date: Wed, 04 May 2005 11:04:10 -0500 Subject: Read / Write image file REC SEP References: <1115208396.640095.155190@g14g2000cwa.googlegroups.com> Message-ID: <4278F27A.7000505@anvilcom.com> >> >>So what if the client sends 4 bytes, and then sends 8000 bytes? WIll I >>get the first 4 bytes as a separate msg so to speak? Basically i want >>to catch each message from the client as a whole. >> IF YOU WANT SEPARATE MESSAGES: Modify the client to send an end of record, then: On Server: datasep = '' # or whatever you like datal = [] seversocket.settimeout(5.0) # or 0(infinite) or something reasonable while 1: try: data = serversocket.recv(BUFFERSIZE) # fails on timeout if not data: break datal.append(data) except: break msglist = datal.split(datasep) # a list of messages From http Thu May 19 20:01:11 2005 From: http (Paul Rubin) Date: 19 May 2005 17:01:11 -0700 Subject: Twisted an several CPUs References: Message-ID: <7xhdgy6a0o.fsf@ruckus.brouhaha.com> Jp Calderone writes: > Distributing load across multiple machines scales better than > distributing it over multiple CPUs in a single machine. If you have > serious scalability requirements, SMP is a minor step in the wrong > direction (unless you're talking about something like 128-way SMP on > a supercomputer :) See PoSH: http://poshmodule.sourceforge.net/ The performance gain from multiple CPU's and shared memory is quite real. I've been wanting for quite a long time to hack up a web server that uses this stuff. From doodle4 at gmail.com Thu May 12 15:19:15 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 12 May 2005 12:19:15 -0700 Subject: increment bits Message-ID: <1115925555.287850.308390@z14g2000cwz.googlegroups.com> Hello, How do i manipulate arrays to increment 8 bits at a time. I need to generate a pattern like 01,02,03,.....0xFF Thanks, -Ashton From bokr at oz.net Sat May 7 19:45:57 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 07 May 2005 23:45:57 GMT Subject: Newbie : checking semantics References: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> Message-ID: <427d4e89.944376982@news.oz.net> On 7 May 2005 15:05:20 -0700, "LDD" wrote: >Hi everyone, > >I am new to python and was very enthustic about its possibilities when >I discover that python is really what it is : just a scripting >language. Not "just." > >What disappoints me is that pyton will happily accept and execute this >code : > >if ( aConditionThatIsFalse ): > AFunctionThatIsntDefined() > >print "Hello world" > >The fact that python doesn't check if the symbol >AFunctionThatIsntDefined is defined, is really bad when you develop big >pieces of code. You will never be sure that your code is free of this >kind of dummy errors and testing every possible execution paths is >nightmarish ! If you aren't going to test your functions, how will you know they don't have dummy errors?? > >Is there a way to force Python to check the definition of symbol ? > If _are_ going to test your functions, how long will it take to discover that a function doesn't exist? IOW, do you mean that if you know a function is defined, you will assume it is free of dummy errors? Such faith ;-) Regards, Bengt Richter From tim.golden at viacom-outdoor.co.uk Tue May 17 12:19:28 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 17 May 2005 17:19:28 +0100 Subject: Problem listing services with wmi Message-ID: <9A28C052FF32734DACB0A288A3533991EBB821@vogbs009.gb.vo.local> [... snip results ...] | So it would seem that the 3 methods give the same result. As to which | service it has gotten to when it gets to position 88 in the list, | obviously I can't find out with a script, and it seems that the list | isn't in any order I can see, so I couldn't even venture a | guess... I'll | try looking if there's a service in my list that isn't valid | (points to | an uninstalled program for example) or something like that... | But if you | have other ideas please let me know. Well I honestly don't know if this will go any further, but the following code uses the win32service module from pywin32 to collect the service information, on the off-chance that it *won't* fail where WMI does. I can't easily test it since the script doesn't raise an error on my machine. At the end, it tries to print out the differences between the win32-collected info and the wmi-collected info. # # Not sure if you're running 2.3/2.4 # try: set except NameError: from sets import Set as set ## ## Taken from a post to c.l.py by William J. Rice ## import win32service import win32con accessSCM = win32con.GENERIC_READ hscm = win32service.OpenSCManager (None, None, accessSCM) win32_names = set () for service_info in win32service.EnumServicesStatus(hscm): win32_names.add (service_info[1]) import win32com.client c = win32com.client.GetObject ( "winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2" ) wmi_names = set () for service in c.ExecQuery ("SELECT * FROM Win32_Service"): try: short_name = service.Properties_ ("Caption").Value except: pass else: wmi_names.add (short_name) print "only in win32:", ", ".join (win32_names - wmi_names) print print "only in wmi:", ", ".join (wmi_names - win32_names) print Let me know if anything shows up. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From mj at zopatista.com Thu May 5 07:39:59 2005 From: mj at zopatista.com (Martijn Pieters) Date: Thu, 05 May 2005 13:39:59 +0200 Subject: If you use PayPal you might consider an alternative In-Reply-To: References: Message-ID: <427A060F.8060701@zopatista.com> Tim Roberts wrote: > That web zite iz juzt too cutezy. I could never truzt it, even if I hadn't > learned about it through a newzgroup zpam. And a quick Google shows you to be very right: http://www.greenzapscam.com/ http://wwsn-forums.com/forum/index.php?showtopic=3496%3Ehttp://wwsn-forums.com/forum/index.php?showtopic=3496 Martijn Pieters -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 264 bytes Desc: OpenPGP digital signature URL: From peter at engcorp.com Wed May 4 07:30:28 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 04 May 2005 07:30:28 -0400 Subject: How to write this regular expression? In-Reply-To: References: Message-ID: could ildg wrote: > I need a regular expression to check if a string matches it. Why do you think you need a regular expression? If another approach that involved no regular expressions worked much better, would you reject it for some reason? -Peter From http Fri May 27 18:04:39 2005 From: http (Paul Rubin) Date: 27 May 2005 15:04:39 -0700 Subject: cpu usage limit References: <1117206216.695085.282510@g44g2000cwa.googlegroups.com> Message-ID: <7xpsvcnx54.fsf@ruckus.brouhaha.com> "mmf" writes: > How can I make sure that a Python process does not use more that 30% of > the CPU at any time. I only want that the process never uses more, but > I don't want the process being killed when it reaches the limit (like > it can be done with resource module). > > Can you help me? In general you can only do that with a real-time operating system. Most other OS's will let you adjust process priorities so that you can prevent your Python process from hogging cycles away from other processes. But if the machine is idle and nobody else wants the cycles, Python will get all of them. From jeremy+plusnews at jeremysanders.net Thu May 26 06:40:18 2005 From: jeremy+plusnews at jeremysanders.net (Jeremy Sanders) Date: Thu, 26 May 2005 11:40:18 +0100 Subject: __init__() not called automatically References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> Message-ID: On Wed, 25 May 2005 21:31:57 -0700, Sriek wrote: > Similarly, why do we have to explicitly use the 'self' keyword everytime? I didn't like that when starting Python. Now when I look back at C++ code, I find it very hard to work out which variables and methods and members, and which are not, unless the author used a clear naming convention. Jeremy From greg at invalid.invalid Tue May 17 23:33:23 2005 From: greg at invalid.invalid (Greg Krohn) Date: Wed, 18 May 2005 03:33:23 GMT Subject: A Specific PyGame In-Reply-To: <428ab5d7$1_1@newsfeed.slurp.net> References: <428ab5d7$1_1@newsfeed.slurp.net> Message-ID: <7Iyie.2326$X92.1859@newsread2.news.pas.earthlink.net> Michael P. Nugent wrote: > I am looking for a specific "game" that is really a programming > environment for young kids. > > I believe it implements PyGame, and presents two windows: one is a grid > with some obstacles, and a character that must traverse the grid; > another is an interactive editor that encourages a learner to write a > script to navigate the character around the obstacles. > > I saw this within the past week, but I cannot remember or discover > where. I have revisited a number of PyGame related sites, and Googled > like crazy, but I'm not finding any visited links that are productive. > I've also extracted everything out of .mozilla/.../history.dat. As you > can see, I'm looking for a specific answer to my specific query. > Perhaps you are thinking of GvR (Guido van Robot): http://gvr.sourceforge.net/ . -greg From gtog at _no___spam_myrealbox.com Thu May 12 11:10:42 2005 From: gtog at _no___spam_myrealbox.com (George) Date: Thu, 12 May 2005 17:10:42 +0200 Subject: Launch file in Notepad In-Reply-To: <42836519.1343368812@news.oz.net> References: <42835db6$0$1334$5fc3050@dreader2.news.tiscali.nl> <42836519.1343368812@news.oz.net> Message-ID: <428372ae$0$1374$5fc3050@dreader2.news.tiscali.nl> Bengt Richter wrote: > On Thu, 12 May 2005 15:41:14 +0200, George wrote: >>(By the way, b1 comes from a command line parameter, so the user enters >>c:\test.txt as command line parameter.) > > It should be ok then, unless you have somehow processed the command line parameter and interpreted > the backslash as an escape. E.g., pargs.py here prints command line args and backslash is > an ordinary string character as you see in argv[3] below. If it were a tab, you would see > whitespace instead of the backslash. Perhaps that's what I did (processing the command line parameter). For some reason it works now. > If by "command line" you mean your own programmed input, make sure you use raw_input, not input, e.g., I was referring to the user launching my script with a filename as parameter: test.py c:\test.txt Here's my code so far (it removes blank lines from the input file (for example c:\test.txt), and creates a new file (c:\test_new.txt) to store the output): import string import sys import os if len(sys.argv)<=1: print 'Usage: dbl.py [filename]' sys.exit() b1=sys.argv[1] b2=b1[:-4] + '_new' + b1[-4:] f1=open(b1,'r') f2=open(b2,'w') r1=f1.readlines() for r in r1: if string.capwords(r)<>'': f2.write(r) f1.close() f2.close() print 'Output file: ' + b2 os.system ('start notepad.exe ' + b2) George From fredrik at pythonware.com Fri May 20 02:59:22 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 20 May 2005 08:59:22 +0200 Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com><1116443474.565264.176640@g44g2000cwa.googlegroups.com><7xd5rn93zi.fsf@ruckus.brouhaha.com> <7xpsvm6h7s.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: >> Send e-mail to webmaster at python.org -- actually, you can have commit >> privs if you want. > > I think I'm going to enter an SF bug on the issue if there isn't > already one. It's not obvious to me whether a reasonable fix is > possible, but at least it should be tracked. The current behavior is > weird and confusing. this has been reported before, and it won't get fixed (unless you're volunteering to add Python-compatible garbage collection to Tk, that is). From http Mon May 23 23:04:03 2005 From: http (Paul Rubin) Date: 23 May 2005 20:04:03 -0700 Subject: Multiple threads in a GUI app (wxPython), communication between worker thread and app? References: Message-ID: <7xd5rhjpek.fsf@ruckus.brouhaha.com> Jp Calderone writes: > >Secondly, I don't know about wxPython, but in tkinter you have to > >resort to a kludge in order for the gui thread to handle gui events > >and also notice stuff on a queue. There's a tkinter command to run > >some function after a specified time (say 50 msec). So you'd set that > >timeout to check the queue and restart the timer, which means the gui > >would check 20x a second for updates from the worker threads. When it > >got such an update, it would create a new window or whatever. > > You can do better than this. Tkinter has an after_idle function, > which lets you post an event to the Tkinter thread _immediately_. > This is basically the Queue "put" operation. I don't understand how this is supposed to work. Can you explain a little further? As far as I can tell, it's not documented as safe to call w.after_idle from another thread. Is it actually safe according to how the code is written? Otherwise, the only way I can see is to use a queue (or other synchronization object) and let the tkinter thread check the queue periodically itself. > > Python thread support seems to have been something of an > > afterthought and there's a lot of weirdness like this to deal with. > I'm not sure what you see as weird about this. Having to deal with this timeout stuff instead of having a documented thread-safe way to add events to a tkinter event queue. From onurb at xiludom.gro Wed May 25 12:54:25 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 25 May 2005 18:54:25 +0200 Subject: Python analog of Ruby on Rails? In-Reply-To: References: Message-ID: <4294adc3$0$2526$626a14ce@news.free.fr> Christopher J. Bottaro wrote: > Hello fellow Pythonists, > Is there such a thing? As what ? Oops, sorry, the question is in the subject... May be helpful to repeat it in the body. You may want to have a look at Subway > My work is thinking of maybe experimenting with > Ruby on Rails for some lesser projects. Naturally, I wonder if Python can > do as good a job or better... Doing 'as good or better' does not mean 'doing the same'. -- bruno desthuilliers ruby -e "print 'onurb at xiludom.gro'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@')" From fredrik at pythonware.com Tue May 10 06:16:15 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 10 May 2005 12:16:15 +0200 Subject: why this happend using model random? References: Message-ID: "flyaflya" wrote: > from random import * > > col = [0 for i in range(10)] > a = [col for i in range(10)] http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list > seed() > for i in range(10): > for j in range(10): > a[i][j] = randint(0, 100) > print a > > the result is: > [[78, 65, 35, 5, 68, 60, 1, 51, 81, 70], > [78, 65, 35, 5, 68, 60, 1, 51, 81, 70], > [78, 65, 35, 5, 68, 60, 1, 51, 81, 70], .....] > why result isn't true random? because you've assigned all the values to the same list ("col"). see the link above for details. From dotpyFE at gmail.com Tue May 3 21:19:59 2005 From: dotpyFE at gmail.com (Lucas Raab) Date: Wed, 04 May 2005 01:19:59 GMT Subject: Any decent IM protocol implementations (icq or aim) In-Reply-To: References: Message-ID: <3rVde.4909$V01.93@newsread1.news.atl.earthlink.net> Jaime Wyant wrote: > Can anyone recommend one? Google isn't giving me much. > > jw I believe there's one for AIM called pyTOC. Trying Googling that or something like "Python ABC". ABC being the messenger service. -- -------------------------- Lucas Raab lvraab"@"earthlink.net dotpyFE"@"gmail.com AIM: Phoenix11890 MSN: dotpyfe "@" gmail.com IRC: lvraab ICQ: 324767918 Yahoo: Phoenix11890 From sakesun at boonthavorn.com Sat May 21 00:54:07 2005 From: sakesun at boonthavorn.com (Sakesun Roykiattisak) Date: Sat, 21 May 2005 11:54:07 +0700 Subject: SQL Query via python In-Reply-To: <200505202357.01579.jeffelkins@earthlink.net> References: <200505202357.01579.jeffelkins@earthlink.net> Message-ID: <428EBEEF.4040500@boonthavorn.com> Try cursor.execute ( """ SELECT name, month, day ,category, city FROM bday WHERE %s = %s """ %(arg1,arg2)) Jeff Elkins wrote: >I'm attempting to pass an SQL query via the console: > >$ ./getbd month 05 > >The arguments get seem to passed correctly (via print statements) and then: > > cursor.execute (""" > SELECT name, month, day ,category, city FROM bday > WHERE %s = %s > """,(arg1,arg2)) > >No results. However, if I hardcode the WHERE argument with a field name: > > cursor.execute (""" > SELECT name, month, day ,category, city FROM bday > WHERE month = %s > """,(arg2)) > >It works. > >How can I code the left side of the WHERE clause so I can pass an arbitrary >field name to search on? > > >Thanks, > >Jeff Elkins > > > > From sean_mcilroy at yahoo.com Mon May 16 18:58:13 2005 From: sean_mcilroy at yahoo.com (Sean McIlroy) Date: 16 May 2005 15:58:13 -0700 Subject: Null String Variable In-Reply-To: References: Message-ID: <1116284293.856204.97470@g47g2000cwa.googlegroups.com> well, somebody's already pointed out that bool(msg)==False iff msg==''. i'm curious to know what's wrong with simply writing if msg=='': ## do_something From rkern at ucsd.edu Wed May 25 23:11:11 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 25 May 2005 20:11:11 -0700 Subject: Checking for a full house In-Reply-To: References: Message-ID: Tony Meyer wrote: > [Tony Meyer] > >>>def isfullHouse(roll): >>> return len(set(roll)) != 2 > > [Robert Kern] > >>[1, 1, 1, 1, 2] is not a full house. > > Opps. I did say it was untested (that should have been == not !=, too). > What about: > > def isfullHouse(roll): > return len(set(roll)) == 2 and roll.count(min(roll)) != 1 and > roll.count(max(roll)) != 1 > > Although your solution looks a lot nicer than this (though it may use more > memory, and might be slower). It *is* slower as written, although a more optimized version using itertools and sets (left as an exercise for the bored) gets close to yours. I don't think memory is an issue with 5-element lists of small integers. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From none Thu May 12 03:51:58 2005 From: none (Hansan) Date: Thu, 12 May 2005 09:51:58 +0200 Subject: Problem combining python code and html References: <42822b3d$0$653$ba624c82@nntp02.dk.telia.net> <42826023$0$8235$636a15ce@news.free.fr> Message-ID: <42835c82$0$26268$ba624c82@nntp06.dk.telia.net> Any suggestions to the problem with only one character being displayed? Thanks Thanks for your time "Bruno Desthuilliers" wrote in message news:42826023$0$8235$636a15ce at news.free.fr... > Hansan a ?crit : >> Hi all, I hope you have time to help me out a little. My problem is that >> I want to combine some python code I have made with some html templates, >> I found a tutorial at dev shed: > (snip a whole lot of code) > >> But I get the error message: >> error: multiple repeat >> args = ('multiple repeat',) ", Content,TemplateInput) File >> "/home//Python-2.3.2//lib/python2.3/sre.py", line 151, in subn return >> _compile(pattern, 0).subn(repl, string, count) >> I tried making the templates global, but that dosnt help either. > > Why should it ? > >> Is the code from dev shed wrong, > > Seems like... And it is *very* ugly. > >> And is there a nother way to combine python code and html templates? > > Many. The one I prefer is Zope Page Templates (there's a free-standing > implementation named SimpleTAL), but I didn't tried all and every existing > solutions. > From grebe at bigfoot.com Fri May 27 13:50:33 2005 From: grebe at bigfoot.com (George van den Driessche) Date: Fri, 27 May 2005 18:50:33 +0100 Subject: distutils, 'scripts' and Windows Message-ID: Hi folks, I'm looking at packaging a project I'm working on using distutils. The project is for Windows and contains a COM server which needs registration, so the installer needs to be a little more complicated than usual. Looking at the options for the bdist_wininst command to distutils, I see it's possible to specify --install-script= which ought to do the trick. But to use this, myinstallscript itself must first be installed by passing scripts='myinstallscript' to distutils.core.setup in setup.py. That will copy myinstallscript into a particular location (C:\Python24\Scripts in my case) and leave it there forever. Which raises a couple of questions: - Why is myinstallscript left there forever? The documentation makes some vague reference to needing it for uninstalling packages, but then I can't actually find a way to uninstall packages. - What is the use of the Scripts directory on Windows? It's not added to my PATH, so unless I do that myself it won't do anything like it's meant to on other platforms. - Should I supply myinstallscript, or myinstallscript.py? I suspect the latter, since that's the only way to give files types on Windows. - Is there some other better way to perform post-installation actions? Would it work out of a binary generated from bdist_wininst? - Should I even be using distutils? It doesn't really matter that much where the files are installed because the COM server can register itself to run out of whatever location it happens to be in. Thanks, George From jjl at pobox.com Tue May 31 14:15:25 2005 From: jjl at pobox.com (John J. Lee) Date: 31 May 2005 19:15:25 +0100 Subject: scripting browsers from Python References: <1117525953.255166.234420@g14g2000cwa.googlegroups.com> Message-ID: "Michele Simionato" writes: > I would like to know what is available for scripting browsers from > Python. > For instance, webbrowser.open let me to perform GET requests, but I > would like > to do POST requests too. I don't want to use urllib to emulate a > browser, I am > interested in checking that browser X really works as intended with my > application. Any suggestion? Yes: http://selenium.thoughtworks.com/index.html http://agiletesting.blogspot.com/2005/03/web-app-testing-with-python-part-2.html http://products.actimind.com/actiWATE/ Unfortunately, there's still no free (as in speech) "macro recorder" implemented as a browser plugin (nor even one implemented on the HTTP level that can produce output in a form selenium understands, AFAIK). For some other relevant links, see under "Misc Links" here (and for that matter, the previous bullet point too): http://wwwsearch.sourceforge.net/bits/GeneralFAQ.html John From cdkrug at worldnet.att.net Fri May 20 18:54:47 2005 From: cdkrug at worldnet.att.net (Charles Krug) Date: Fri, 20 May 2005 22:54:47 GMT Subject: performance of Nested for loops References: <1116628510.816306.31390@g43g2000cwa.googlegroups.com> Message-ID: On 20 May 2005 15:35:10 -0700, querypk at gmail.com wrote: > Is there a better way to code nested for loops as far as performance is > concerned. > > what better way can we write to improve the speed. > for example: > N=10000 > for i in range(N): > for j in range(N): > do_job1 > for j in range(N): > do_job2 > What do you see when you profile the code? Premature Optimization is the root of all manner of evil and all that good stuff. From fredrik at pythonware.com Fri May 13 09:37:08 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 13 May 2005 15:37:08 +0200 Subject: MySQL: 'latin-1' codec can't encode character References: <1115990748.006171.96240@g49g2000cwa.googlegroups.com> Message-ID: "francescomoi at europe.com" > I'm trying to store a text within a MySQL field (v 3.23.58) by using > MySQLdb > (v 1.2.1c3). > > The text is: "telephone..." (note the last character) > > And I get this error message: > ----------- > File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line > 33, in defaulterrorhandler > raise errorclass, errorvalue > UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2026' in > position 288: ordinal not in range(256) > ----------------------- > > Position 288 is the character I've mentioned. I suppose I must encode > this caracter > into a right one which MySQL could store, but I have no idea about how > to perform > it. Any suggestion? the character \u2026 is not part of the ISO-8859-1 character set. if you insist on storing that in 8-bit string, you have to find an 8-bit encoding that includes that character (UTF-8 is one such alternative). if MySQL is set to store ISO-8859-1 only, you can replace the character with it with three periods, drop it (use the "ignore" encoding option) or replace it with a suitable marker (use the "replace" encoding option). From bogus@does.not.exist.com Tue May 3 09:35:02 2005 From: bogus@does.not.exist.com () Date: Tue, 03 May 2005 13:35:02 -0000 Subject: No subject Message-ID: #! rnews 1990 Newsgroups: comp.lang.python Path: news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp From: Harry George Subject: Re: Py2Exe security X-Nntp-Posting-Host: cola2.ca.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Lines: 35 Sender: hgg9140 at cola2.ca.boeing.com Organization: The Boeing Company References: <1115121780.404491.84240 at f14g2000cwb.googlegroups.com> Mime-Version: 1.0 Date: Tue, 3 May 2005 13:18:19 GMT Xref: news.xs4all.nl comp.lang.python:375624 "Terje Johan Abrahamsen" writes: > Hello. > > We have created some programs in Python that are to be distributed > around. The programs will be made into .exe files by py2exe. However, > in the source there are certain webadresses, logins and passwords that > the programs use, that we would like to keep away from the end users. > They will use them thru the program, but we would like them not to be > extracted and used separately for other purposes. > > Is the compiling by py2exe enough? I have opened all the files in the > directory py2exe has made, and have not found anything I could read in > clear text. However, that does not mean that others can not. Is it > possible to extract these passwords, adresses and logins from the > sourcecode? If py2exe is not enough, is there some other simple tools > we can use to hide the source from the endusers? > > Thanks in advance. > Putting passwords in your program is a bad idea, with or without Python and py2exe. Even if you wrote the program in obfuscated C, and stripped comments etc, an attacker could use "strings" to search for candidate passwords. Or just start at the beginning of the program and use each byte as a candidate starting char. Since you are working on MS Windows, consider getting: M. Howard, D. LeBlanc, "Writing Secure Code", Microsoft Press, 2002. -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 294-4718 From hugh.macdonald at gmail.com Tue May 24 12:33:24 2005 From: hugh.macdonald at gmail.com (Hugh Macdonald) Date: 24 May 2005 09:33:24 -0700 Subject: Hacking the scope to pieces In-Reply-To: <1116944386.188200.33490@g49g2000cwa.googlegroups.com> References: <1116933053.924055.50250@g14g2000cwa.googlegroups.com> <1116944386.188200.33490@g49g2000cwa.googlegroups.com> Message-ID: <1116952404.702970.39310@g14g2000cwa.googlegroups.com> Maybe I misunderstood what you meant, but I couldn't quite manage to get this one working.... My initial hopes about __import__() were that I could define it inside my new module (moduleLoader) and, when the module is imported, it could do stuff (like try to hold onto the vars() and globals() from the importing scope). However, I couldn't get it to import... The route I've ended up going (which is just about as simple) is just to return the new module from moduleLoader.loadModule, so my loading code is: import moduleLoader myModule = moduleLoader.loadModule("myModule", os.getenv("MODULE_VERSION")) I've also switched over to using 'inp' for this, rather than creating a compiler string - much nicer.... Anyway, thanks Skip -- Hugh From sebastien.ramage at gmail.com Wed May 25 04:58:36 2005 From: sebastien.ramage at gmail.com (=?iso-8859-1?q?S=E9bastien_Ramage?=) Date: 25 May 2005 01:58:36 -0700 Subject: embedded Python In-Reply-To: <1117005077.657701.226750@z14g2000cwz.googlegroups.com> References: <1117005077.657701.226750@z14g2000cwz.googlegroups.com> Message-ID: <1117011516.103990.233410@g43g2000cwa.googlegroups.com> PROBLEME RESOLU j'ai r?solu le probl?me en supprimant le commutateur \GZ de le link http://support.microsoft.com/kb/q191669/ From emami at knmi.nl Thu May 19 05:05:39 2005 From: emami at knmi.nl (Nader Emami) Date: Thu, 19 May 2005 11:05:39 +0200 Subject: datetime Message-ID: <47736$428c56e3$9117fe9b$26924@news2.tudelft.nl> L.S., It is very simple question: Why doesn't work the next statments? import datetime today = datetime.date.today() and I get the next error: today = datetime.date.today() Traceback (most recent call last): File "", line 1, in ? AttributeError: time I can't understand it! From klaus at seistrup.dk Mon May 16 17:18:14 2005 From: klaus at seistrup.dk (Klaus Alexander Seistrup) Date: Mon, 16 May 2005 21:18:14 +0000 (UTC) Subject: Null String Variable References: Message-ID: Rotary wrote: > I want to say something like that: if msg is empty ...then do > something. So how can i figure that msg is empty string (no > character, msg = ''). #v+ if not msg: print 'msg is empty' #v- -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ From rschroev_nospam_ml at fastmail.fm Sun May 1 03:55:11 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 01 May 2005 07:55:11 GMT Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <1114927892.321086.60190@z14g2000cwz.googlegroups.com> References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> Message-ID: Dan Bishop wrote: > Dan Bishop wrote: > > Correction: Now I'm stuck on Level 11. I think I'm supposed to do > something with the pixels in the image, but what? Me too. I've tried making different images out of the even and the odd pixels, but nothing interesting happened. I tried to combine both images in various ways (using the Gimp), but that also seemed to be a dead end. I don't think we need to concernt ourselves with the individual pixel values; otherwise the image would not be a jpeg, it would be a non-lossy format instead. The forum's tips only go up to 9, so that doesn't help either. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From michaels at rd.bbc.co.uk Mon May 23 04:28:43 2005 From: michaels at rd.bbc.co.uk (Michael Sparks) Date: Mon, 23 May 2005 09:28:43 +0100 Subject: first release of PyPy References: Message-ID: holger krekel wrote: > The PyPy 0.6 release > -------------------- > > *The PyPy Development Team is happy to announce the first > public release of PyPy after two years of spare-time and > half a year of EU funded development. The 0.6 release > is eminently a preview release.* Yay! Congratulations guys! Michael. -- Michael.Sparks at rd.bbc.co.uk British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. From onurb at xiludom.gro Fri May 6 12:16:53 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 06 May 2005 18:16:53 +0200 Subject: Best way to convert a list into function call arguments? In-Reply-To: <1115299220.736781.54810@o13g2000cwo.googlegroups.com> References: <1115299220.736781.54810@o13g2000cwo.googlegroups.com> Message-ID: <427b9878$0$9950$626a14ce@news.free.fr> bwooster47 at gmail.com wrote: > I'm a newcomer to python - what is the best way to convert a list into > a function call agruments? Jeff Epler already answered to the question. Now a couple of advices: > For example: > > list = (2005, 5, 5) 1/ this is not a list, it's a tuple. A list would be [2005, 5, 5]. (BTW, it's quite ok - and even better imho - to use a tuple here) 2/ using the word 'list' as identifier shadows the builtin function 'list'. This is allowed, but you may prefer to avoid doing so. 3/ also, using the word 'list' as an identifier here is a poor choice from a semantic POV, since it convey useless (and in this case wrong) informations about an implementation detail (the data structure type) but says nothing about the intended use of the data. Something like 'the_date' would have been better IMHO. My 2 cents -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From max at alcyone.com Sun May 1 22:12:24 2005 From: max at alcyone.com (Erik Max Francis) Date: Sun, 01 May 2005 19:12:24 -0700 Subject: Static Methods in Python In-Reply-To: <1114999599.608054.52730@f14g2000cwb.googlegroups.com> References: <1114999599.608054.52730@f14g2000cwb.googlegroups.com> Message-ID: Kris wrote: > I am a newbie to Python. With a background in Java, I was attempting > to write static methods in the class without the self as the first > parameter, when I got an error. I did a search for the same on Google > and found out that there was no consistent approach to this. I would > like to know what is the prescribed approach for the same. Any > thoughts, pointers about the same would be very much appreciated. Do something like (2.4): @staticmethod def aStaticMethod(x, y, z): ... Prior to 2.4, use: def aStaticMethod(x, y, z): ... aStaticMethod = staticmethod(aStaticMethod) -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis Wyrd has swept all my kin / all the brave chiefs away! / Now I must follow them! -- Beowulf From jstroud at mbi.ucla.edu Fri May 20 18:46:53 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Fri, 20 May 2005 15:46:53 -0700 Subject: passing arguments In-Reply-To: <200505201826.09939.jeffelkins@earthlink.net> References: <200505201826.09939.jeffelkins@earthlink.net> Message-ID: <200505201546.53578.jstroud@mbi.ucla.edu> import sys try: arg1 = sys.argv[1] except IndexError: print "This script takes an argument, you boob!" sys.exit(1) OR, way better: See the optparse module. On Friday 20 May 2005 03:26 pm, Jeff Elkins wrote: > I'm sure this is obvious, but how the heck do pass an argument(s) to a > python script from the command line? > > Thanks, > > Jeff Elkins -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From rrr at ronadam.com Wed May 18 01:51:13 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 18 May 2005 05:51:13 GMT Subject: Quick Reference from module doc strings. In-Reply-To: <1116389035.309275.94580@o13g2000cwo.googlegroups.com> References: <1116199904.205240.58300@g49g2000cwa.googlegroups.com> <42880d98$1@nntp0.pdx.net> <1116320306.737808.313530@g44g2000cwa.googlegroups.com> <1116349136.477233.205260@z14g2000cwz.googlegroups.com> <1116389035.309275.94580@o13g2000cwo.googlegroups.com> Message-ID: Michele Simionato wrote: > Ron Adam: > >>Thats part of what I'm trying to resolve, the doc strings a lot of > > time > >>isn't enough by itself or is missing. So I'm trying to build up a >>complete enough record so if there is no doc string, at least some > > sense > >>of what it is can be figured out without a lot browsing or looking at >>the source code. > > > I have a command line option so I can decide if I want to display only > the > documented objects or every object, including the ones without > docstring. > I could add an option to tell "minidoc" to interpret docstrings are > plain > text, not restructured text; however I don't want to do that (part of > the reason for "minidoc" is to force me to write good reST docstrings > in my own modules). If it works, don't fix it. ;-) >>Then to enable different searches by subject and keywords on these >>instead of by package or module. > > > Well, my browser has a CTRL-F functionality ;) I recently switched over to using the GVIMs Cream version as an editor, So it should be possible to map a function key to grab the import statements from the currently edited document, feed the imported module names to quickref and capture the output in a window for searching in the same way. It will be fun to play around with once I get back from a week long trip starting Thursday. >>in case it was an over site. > > Yes, I am aware of it, it was on purpose ;) I was pretty sure it was. >>Ps... I like your physics link page. :) > > That page is old, I am no more in physics, but I still have that > account for free > and I am lazy, so I am keeping it ;) > > Michele Simionato I'm not in physics in *any* way, but I have a few pet theories (more like opinions really). So I like to check what's going on and see if anyone or anything proves or disproves them. ;-) From tjreedy at udel.edu Wed May 11 20:17:25 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2005 20:17:25 -0400 Subject: Python Documentation (should be better?) References: <1115839271.271071.32710@z14g2000cwz.googlegroups.com> <1115841659.470657.33320@o13g2000cwo.googlegroups.com> Message-ID: "S?bastien Boisg?rault" wrote in message news:1115841659.470657.33320 at o13g2000cwo.googlegroups.com... > > "Manual" == scope of the *Lib Reference* + informal style of the > *Tutorial*, You, as well as the OP, left out the Language Reference, which is the manual (by me definition) for the language itself. Chapter 2 of the Lib Reference on builtin types and functions is essential also and should be read in its entirety. The rest, to me, is 'need to know' reading, especially since the addition of string methods. > Consider non-official manuals such as: > + http://diveintopython.org/toc/index.html (free) > + python in a nutshell > + python cookbook > + etc. Yes, these and others (the etc) are helpful too, and should not be discounted just because they are maintained independently of the core developer group. Terry J. Reedy From steve at REMOVETHIScyber.com.au Sat May 7 10:42:22 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 08 May 2005 00:42:22 +1000 Subject: Ask for a tool to protect my .pyc file :) References: Message-ID: On Sat, 07 May 2005 06:45:32 -0700, Robert Kern wrote: > Lily Kakm wrote: >> when I distribute my software, I will give the users .pyc file (maybe I can >> use py2exe, but I think there's no essential different), because I don't >> like them to know my source code. >> >> But actually, through .pyc file is not so directly as .py file, but the user >> can also easily guest the detail of the program. Because in the .pyc file, >> the name of the variables are exist. >> >> I ask you for a tool. Maybe it can hide the name of the variables. > > That's not going to provide you any security. Any competent attacker > won't care what you name the variables. > > If you want real security, don't distribute your code. Expose the > critical parts as a web service (or similar) instead. > > If you want pretend security, .pycs or py2exe executables are enough. Lily, I think the point that Robert is making is that you have to ask, "Why do I want to keep my code secret?" If the answer is "My code is very bad and I don't want people to see it because I am ashamed", then distributing .pyc files is good enough. Or better, learn to write better code. If the answer is, "My code is worth a lot of money, and I don't want people to copy it", then hiding variable names will not protect you. If your code is worth enough money, then people will spend hundreds of hours cracking whatever security you use. The more valuable your code, the more time and effort they will spend. And using variables like xxxxxxxy won't protect you from competent programmers. As soon as they read the code and realise that xxxxxxxy is a node, they will do a Search and Replace of "xxxxxxxy" to "some_node" and have readable code again. So why do you want to hide your code? Who do you expect to hide it from? [snip] >> xxxxxxxxxx = 100 >> xxxxxxxxxy = 500 - xxxxxxxxxx >> >> It has the same function, but it can not easily be seen by the users. > > Reads just fine to me. In fairness Robert, would you really want to read 10,000 lines of code like that? I know I wouldn't -- not even 100 lines. Obfuscated code like that is, well, obfuscated. That makes it the opposite of well-written, easily maintained and understood code. This isn't a impenetrable barrier to a motivated programmer, but it is hardly easy to read. >> Do you know where to download a tool like this. > > You ask an open source software community for a free tool to keep your > source proprietary? High expectations. Again, in fairness, source code obfuscation isn't wrong in and of itself. For example, Lily might be a teacher running a course on reverse-engineering, and wants some Python code that can't easily be understood by just reading the source. Well, it's possible *wink* Lily, if you are still reading, I think it is very important that you think about why you want to keep your source code secret. Then think about the alternative: publish your code as Open Source software. There are many companies these days who make money from Open Source software, including IBM, Red Hat, Apple, Sun, all the way down to small businesses like the one I work for. (Modesty prevents me mentioning the name, but if you look at my email address you should be able to work it out.) If you aren't selling your software, but just want people to be able to download it and use it, then think about the advantages of making the code available. If you can't think what those advantages are, please ask, I'm sure many people here will be more than happy to discuss it with you. Finally, if you still decide that you want to keep your code secret, that Open Source is not for you, then I suggest you do a Google search on "python obfuscater". If you don't find anything, then you can always write your own. Steven. From Facundo.Batista at telefonicamoviles.com.ar Mon May 9 16:18:15 2005 From: Facundo.Batista at telefonicamoviles.com.ar (Batista, Facundo) Date: Mon, 9 May 2005 17:18:15 -0300 Subject: PyAr - Python Argentina 9th Meeting, this Thursday Message-ID: The Argentine Python User Group, PyAr, will have its nineth meeting this Thursday, May 12nd at 7:00pm. Agenda ------ Despite our agenda tends to be rather open, this time we would like to cover these topics: - See what we'll do with the t-shirts, and other "merchandising". - Analyze a future meeting point. Where ----- We're meeting at Hip Bar, Hip?lito Yirigoyen 640, Ciudad de Buenos Aires, starting at 19hs. We will be in the back room, so please ask the barman for us. About PyAr ---------- For more information on PyAr see http://pyar.decode.com.ar (in Spanish), or join our mailing list (Also in Spanish. For instructions see http://pyar.decode.com.ar/Members/ltorre/listademail) We meet on the second Thursday of every month. . Facundo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ADVERTENCIA. La informaci?n contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener informaci?n confidencial o propietaria, cuya divulgaci?n es sancionada por la ley. Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no est? autorizado a divulgar, copiar, distribuir o retener informaci?n (o parte de ella) contenida en este mensaje. Por favor notif?quenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magn?tico) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telef?nica Comunicaciones Personales S.A. o alguna empresa asociada. Los mensajes electr?nicos pueden ser alterados, motivo por el cual Telef?nica Comunicaciones Personales S.A. no aceptar? ninguna obligaci?n cualquiera sea el resultante de este mensaje. Muchas Gracias. -------------- next part -------------- An HTML attachment was scrubbed... URL: From f.geiger at vol.at Fri May 27 15:35:49 2005 From: f.geiger at vol.at (F. GEIGER) Date: Fri, 27 May 2005 21:35:49 +0200 Subject: [pysqlite] Equivalent for SHOW TABLES? Message-ID: For now, the names of the tables, the app knows of, are added into an internal list, when the app is started. Then, when queries fail, the app knoes that it has to create them. It would be nice somehow to be able to ask the database what tables it contains. Is anyone doing this that way? How do you do that? Kind regards Franz GEIGER From Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org Mon May 16 12:58:24 2005 From: Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org (Alexander) Date: Mon, 16 May 2005 20:58:24 +0400 Subject: trouble with copy/deepcopy Message-ID: Hello! I have trouble with copy/deepcopy. It seems, I just don't understand something. Please explain where things goes wrong and how to do it the right way. I have one class: class Distribution: __gr_on_transp=dict() __ostatok_m=dict() and so on And, I want to make full copy of it: d1=Distribution() d2=copy.deepcopy(d1) But, members-dictionaries are don't copied. For example if I will write: d1.clear() which clears all two dictionaries, I will find that d2's dictionaries are also empty!!! Now I'am using the quick-hack: class Distribution: __gr_on_transp=dict() __ostatok_m=dict() ... def my_copy(self): d2=copy.deepcopy(self) d2.__gr_on_transp=self.__gr_on_transp.copy() d2.__ostatok_m=self.__ostatok_m.copy() return d2 It's work well, but I don't understand why previous is wrong and how to do it in right way. Alexander, zatv at bk.ru From chris.lyon at spritenote.co.uk Tue May 10 11:30:23 2005 From: chris.lyon at spritenote.co.uk (chris.lyon at spritenote.co.uk) Date: 10 May 2005 08:30:23 -0700 Subject: Library Naming Conventions. References: <1114851378.781754.194030@z14g2000cwz.googlegroups.com> <1114860766.488589.152380@o13g2000cwo.googlegroups.com> Message-ID: <1115739023.302545.109300@o13g2000cwo.googlegroups.com> quoting: Modules should have short, lowercase names, without underscores. this still doesn't explain Cookie. wittempj at hotmail.com wrote: > see http://www.python.org/peps/pep-0008.html for naming conventions and > other style issues From efoda5446 at yahoo.com Sat May 28 17:40:27 2005 From: efoda5446 at yahoo.com (Lorn) Date: 28 May 2005 14:40:27 -0700 Subject: String manipulations Message-ID: <1117316427.826830.189260@g14g2000cwa.googlegroups.com> I'm trying to work on a dataset that has it's primary numbers saved as floats in string format. I'd like to work with them as integers with an implied decimal to the hundredth. The problem is that the current precision is variable. For instance, some numbers have 4 decimal places while others have 2, etc. (10.7435 vs 1074.35)... all numbers are of fixed length. I have some ideas of how to do this, but I'm wondering if there's a better way. My current way is to brute force search where the decimal is by slicing and then cutoff the extraneous numbers, however, it would be nice to stay away from a bunch of if then's. Does anyone have any ideas on how to do this more efficiently? Many Thanks, Lorn From martin.witte at gmail.com Sat May 7 18:40:02 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 7 May 2005 15:40:02 -0700 Subject: globbing multiple wildcards In-Reply-To: <1115504878.558146.327440@f14g2000cwb.googlegroups.com> References: <1115477662.937084.260270@g14g2000cwa.googlegroups.com> <1115481354.357281.240920@g14g2000cwa.googlegroups.com> <1115504878.558146.327440@f14g2000cwb.googlegroups.com> Message-ID: <1115505602.061603.113530@f14g2000cwb.googlegroups.com> Then take a look at os.walk, see http://docs.python.org/lib/os-file-dir.html From rrr at ronadam.com Tue May 17 12:10:59 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 17 May 2005 12:10:59 -0400 Subject: Quick Reference from module doc strings. In-Reply-To: <1116320306.737808.313530@g44g2000cwa.googlegroups.com> References: <1116199904.205240.58300@g49g2000cwa.googlegroups.com> <42880d98$1@nntp0.pdx.net> <1116320306.737808.313530@g44g2000cwa.googlegroups.com> Message-ID: <428A1793.2090403@ronadam.com> Michele Simionato wrote: >>Do you have any feature suggestions, additional information that > > could > >>go in, something that would extend the content in some way and make > > it > >>more useful? > > > I have written something similar which I use all the time. It generates > ReST > output which I can browse with "less" from the command line, as well as > HTML > output and PDF output that I can print. The hard work is done by > docutils, of course. > I have options to specify if I want to least private names or not, and > to specify > if I want an analytical index to be generated or not. Also, the HTML > output > contains hyperlinks to the original source code, so I can see it with > a click. > I can feed to "minidoc" whole packages (it works recursively on > subpackages, so everything is documented). > > It was unvaluable in my struggle with Zope. > > Michele Simionato > Hi Michele, Sound great! Adding a command line parser, I'm going to add a brief command line parser to it today, but nothing as elaborate as you have already. Could you post a part of the output as an example? How is the index built? The direction I'm going is to build a database/dictionary with each individual item as a record. Maybe feed it the whole lib directory, then to be able to generate cross module/package lists by subject or keyword. I'm not exactly sure how to connect everything together yet. This is a figure it out as I go project, but I think it's worth trying. Cheers, _Ron From fredrik at pythonware.com Thu May 5 05:12:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 5 May 2005 11:12:10 +0200 Subject: UnicodeDecodeError References: <000801c5516c$19a41a30$bb64a8c0@eformswin> Message-ID: Thomas Thomas wrote: > filename=unicode(filename); > #file = ('file', filename, data) #This won't work will give a > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 > in position 10: ordinal not in range(128) there's no way the tuple creation will generate a UnicodeDecodeError all by itself. are you sure the error occurs on that line? are you running this with a stock interpreter, or are you using some fancy IDE thing? what does filename really contain? (there's no "0xc7" character in the filepath in your example). try adding print repr(filepath) before the os.path.split call, and let us know what it prints. From anton.vredegoor at gmail.com Sat May 14 07:21:04 2005 From: anton.vredegoor at gmail.com (anton.vredegoor at gmail.com) Date: 14 May 2005 04:21:04 -0700 Subject: Python on a public library computer Message-ID: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> Here's my situation: I'm typing this in a public library on a computer with OS windows 2000 server. I can run Internet explorer, word, excel and powerpoint, that's it. Maybe java, but it seems to be flaky. I want to run python scripts from this computer. At home I have a multi-computer network (from better times) but no internet access anymore, I could use this to try out solutions. I also have access to a friends computer which has internet connection, but I can't visit his place all the time. He's away often but he's got a life of his own :-) So I'm thinking of running some kind of python webserver from a dedicated computer over there (visualizing some cherrypy webpage based interpreter at the moment) but I would like to know other options. However it would have to run from a webpage here ... For example I would like to run a python script over there (e.g. getting news from a usenet server) which puts the output in a zipfile on another webpage so that I can fetch it here with the Internet Explorer. There seems to be no traffic load problem since there would be only a few users (but it could become popular fast?). Also I'm worried about security issues, but not so much that I would consider installing some large scale payware professional solution. Let me know what you think, unless it costs money. On the other hand money would solve this problem so if I can do something to get that it would be even better. Anton [the things they make you go through ...] From mwm at mired.org Mon May 16 03:21:00 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 16 May 2005 02:21:00 -0500 Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever sepa References: <1116096706.696830.275140@g44g2000cwa.googlegroups.com> Message-ID: <86sm0nd4bn.fsf@guru.mired.org> rockon02 at senet.com.au (Mike brown) writes: > In article , "Bubba" wrote: > >> I'm so glad you've decided what everyone believes.... >> > > > > Some of us don't. > > > > > > Believe that is. > > > > > > In anything in particular. Everybody should believe in something. I believe I'll have another beer. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From me at privacy.net Wed May 18 10:22:38 2005 From: me at privacy.net (Dan Sommers) Date: 18 May 2005 10:22:38 -0400 Subject: speeding up Python script References: <3evgolF56gtkU3@individual.net> <3f0os2F4lpshU1@individual.net> Message-ID: On Wed, 18 May 2005 12:56:50 +0100, "Luis P. Mendes" wrote: > The reason why I'm using six nested for loops is because I need to find > the best output using those six variables as input. > Here's the simplified code: > for per in range(): > ~ for s in range(): > ~ for t in range(): > for v in range(): > ~ for n in range(): > ~ for l in range(): > var a, \ > var b, \ > ... > var 15 = function1(arg1, \ > ... > arg20) > ~ var a, \ > var d, \ > var a, \ > ... > var 14 = function2(arg1, \ > ... > arg25) > var c, \ > ... > var 18 = function3(arg1, \ > ... > arg20) > ia = var1*var2-numPerdidos*sl > result.insert(index, [per,s,t,v,n,l,ia]) > index = index + 1 > thanks for the replies I don't know how large your search-space is, but if the ranges for s, t, v, n, and/or l don't change, at the very least you can pre-compute those ranges instead of creating a new list with range every time: srange = range( ) trange = range( ) vrange = range( ) nrange = range( ) lrange = range( ) for per in range( ): for s in srange: for t in trange: for v = vrange: for n in nrange: for l in nrange: somevar = somefunction( per, s, t, v, n, l ) result.append( [ somevar, per, s, t, v, n, l ] ) (Appending the results is probably quicker than inserting them, but I don't know for sure.) But a better-than-an-exhaustive-search algorithm sounds like a good idea, too. Regards, Dan -- Dan Sommers From steven.bethard at gmail.com Thu May 5 14:17:15 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 05 May 2005 12:17:15 -0600 Subject: How to detect a double's significant digits In-Reply-To: <1115316826.659271.247350@o13g2000cwo.googlegroups.com> References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> <1115316826.659271.247350@o13g2000cwo.googlegroups.com> Message-ID: mrstephengross wrote: > First of all, str() is not a function. Yes it is. > float f = 1.004; > ostringstream s; > s << f; > cout << s.str(); This doesn't look like Python to me. Are you sure you're on the right newsgroup? STeVe From donn at drizzle.com Wed May 11 02:17:06 2005 From: donn at drizzle.com (Donn Cave) Date: Wed, 11 May 2005 06:17:06 -0000 Subject: Python Args By Reference References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> <1182j1daaepv6f4@corp.supernews.com> <1115787330.723188.295610@f14g2000cwb.googlegroups.com> Message-ID: <1115792224.936633@yasure> Quoth "ncf" : ... | The two issues I am having in grasping all of this are as follows: | 1) Being new to Python, terms like mutable and immutable. Although I | have probably dealt with them in other languages, the terms by | themselves are a little confusing, but managable overall, so this issue | isn't so big. It's often introduced in a confusing way. We just say it's mutable if it has one or more functions that modify its contents. There isn't any other distinction, any other difference than that. | 2) LARGELY, my issue is as demonstrated by the following code. I was | trying to accomplish an effect similar to what is possible in C. | (Trying to make a pure-python FIPS-180-2 compliant implementation of | the SHA-256 algorithm for more Python practice and to put into some | code for a *trial* secure protocol.) | Example C Code: | #define P(a,b,c,d,e,f,g,h,x,K) \ | { \ | temp1 = h + S3(e) + F1(e,f,g) + K + x; \ | temp2 = S2(a) + F0(a,b,c); \ | d += temp1; h = temp1 + temp2; \ | } | | Python Code: | def P(a,b,c,d,e,f,g,h,x,K): | temp1 = h + S3(e) + F1(e,f,g) + K + x | temp2 = S2(a) + F0(a,b,c) | d += temp1; h = temp1 + temp2 | | The reason why it'd be a pain to implement this by any of the methods | provided in the Python FAQs is that SHA-256 rotates the variable order | in the calls. Example code: | P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 ); | P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 ); | P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF ); | P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 ); | P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B ); | P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 ); | P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 ); | P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 ); | P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 ); | | Since I cannot simply do it the way I had originally seen it, would | there be an alternative method to proforming the operations that I am | missing? I could be missing something, but I think you just have to suck it up and do it one of the other two ways: 1. The more or less functional way: the function doesn't have any side effects. It just returns the values it computes, and it's for the caller to bind them to variables. D, H = P(A, B, C, D, E, F, G, H, W[0], 0x428A2F98) C, G = (H, A, B, C, D, E, F, G, W[1], 0x71374491) ... 2. The OOP way: each object has the appropriate function that modifies its content value. That looks like a big waste of time to me, but I mention it for conceptual completeness. Donn Cave, donn at drizzle.com From domma at procoders.net Wed May 11 14:49:44 2005 From: domma at procoders.net (Achim Domma (Procoders)) Date: Wed, 11 May 2005 20:49:44 +0200 Subject: win32com and ADO In-Reply-To: <1115833669.142021.294080@g44g2000cwa.googlegroups.com> References: <1115833669.142021.294080@g44g2000cwa.googlegroups.com> Message-ID: Chris Curvey wrote: > result = conn.execute("select * from foo") > > while not result.EOF: > doSomething() > result.MoveNext() > > 'tuple' object has no attribute EOF The recordset you are looking for is a element of the tuple. Out of my head I would say it's element 1, so you have to write: result = conn.execute("select * from foo")[1] regards, Achim From cappy2112 at gmail.com Mon May 2 22:18:16 2005 From: cappy2112 at gmail.com (Cappy2112) Date: 2 May 2005 19:18:16 -0700 Subject: WordPress Python Library 1.0 In-Reply-To: References: Message-ID: <1115086696.356342.76870@f14g2000cwb.googlegroups.com> If you wan't explain what WordPress is, can you at least supply a link for a page that's in English? From exarkun at divmod.com Fri May 27 10:17:58 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 27 May 2005 14:17:58 GMT Subject: write to the same file from multiple processes at the same time? In-Reply-To: <7x1x7siy3b.fsf@ruckus.brouhaha.com> Message-ID: <20050527141758.559.523559912.divmod.quotient.11154@ohm> On 27 May 2005 06:43:04 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: >Jp Calderone writes: >> >But they haven't. They depend on messy things like server processes >> >constantly running, which goes against the idea of a cgi that only >> >runs when someone calls it. >> >> SQLite is an in-process dbm. > >http://www.sqlite.org/faq.html#q7 > > (7) Can multiple applications or multiple instances of the same > application access a single database file at the same time? > > Multiple processes can have the same database open at the same > time. Multiple processes can be doing a SELECT at the same > time. But only one process can be making changes to the database > at once. > >But multiple processes changing the database simultaneously is >precisely what the OP wants to do. Er, no. The OP precisely wants exactly one process to be able to write at a time. If he was happy with multiple processes writing simultaneously, he wouldn't need any locking mechanism at all >:) If you keep reading that FAQ entry, you discover that SQLite implements its own locking mechanism internally, allowing different processes to *interleave* writes to the database, and preventing any data corruption which might arise from simultaneous writes. That said, I think an RDBM is a ridiculously complex solution to this simple problem. A filesystem lock, preferably using the directory or symlink trick (but flock() is fun too, if you're into that sort of thing), is clearly the solution to go with here. Jp From no at spam.com Sun May 22 19:55:37 2005 From: no at spam.com (John Doe) Date: Mon, 23 May 2005 02:55:37 +0300 Subject: How come print cannot be assigned to a variable? In-Reply-To: <1116600042.622872.49850@g14g2000cwa.googlegroups.com> References: <1116600042.622872.49850@g14g2000cwa.googlegroups.com> Message-ID: anonymousnerd at gmail.com wrote: > Hi all, > In Python, some functions can be assigned to variables like this: > length=len > Why is it that print cannot be assigned to a variable like this? (A > syntax error is declared.) > > Thanks, > > Vaibhav > print can't be assigned to variables since it's not a funcion, it's part of the syntax of the language, like `for', `while', etc. and it can't be assigned to variables, just as those can't be assigned. If you need a function that prints stuff, consider these two examples: [snip] PrintFunc = lambda x: print x [snip] Or, a somewhat better solution: [snip] import sys PrintFunc = sys.write [snip] From eee at nmt.edu Tue May 10 13:18:57 2005 From: eee at nmt.edu (Earl Eiland) Date: Tue, 10 May 2005 11:18:57 -0600 Subject: error using process module Process class Message-ID: <1115745537.2995.256.camel@dulcevida> When executing the following code snippet import process ... ... for x in Files: Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set compression_method ppmz -setg include_paths none -add ' + os.path.join(InputDirectory, x) + ' -apply -quit' PROC = process.Process(Command_String) PROC.wait() from the command line C:\Documents and Settings\eeiland\Desktop>Thesis_Programs\Compressor2.py Test_Da ta\sliceX12 Test_Output\Test generates the following error: Traceback (most recent call last): File "C:\Documents and Settings\eeiland\Desktop\Thesis_Programs\Compressor2.py ", line 61, in ? PROC = process.Process(Command_String) File "C:\Python24\Lib\site-packages\process.py", line 839, in __init__ self._startOnWindows() File "C:\Python24\Lib\site-packages\process.py", line 913, in _startOnWindows cmd = _whichFirstArg(cmd, self._env) File "C:\Python24\Lib\site-packages\process.py", line 303, in _whichFirstArg import which ImportError: No module named which From Wibble at Mailinator.com Mon May 23 07:14:05 2005 From: Wibble at Mailinator.com (Wibble) Date: Mon, 23 May 2005 07:14:05 -0400 Subject: What are OOP's Jargons and Complexities? In-Reply-To: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> Message-ID: You're point being...? I'm an old lisp hacker too, and lisp developed objects too, because they're cool and useful (Flavors & CLOS). Java has inner classes also, and nobody misses FLET & LABELS. Limiting responsiblity and enhanced type safety, as well as improved readablity are a win hands down over the bad old days. Lisp is not a more advanced language than Java. Its 30+ years older and shows it in alot places. Lisp has some things I wish were in Java but the corralary holds true. Object orient programming in Lisp is nice too. Xah Lee wrote: > What are OOP's Jargons and Complexities > Xah Lee, 20050128 > > The Rise of Classes, Methods, Objects > > In computer languages, often a function definition looks like this: > subroutine f (x1, x2, ...) { > variables ... > do this or that > } > > In advanced languages such as LISP family, it is not uncommon to define > functions inside a function. For example: > subroutine f (x1, x2, ...) { > variables... > subroutine f1 (x1...) {...} > subroutine f2 (x1...) {...} > } > > Often these f1 f2 inner functions are used inside f, and are not > relevant outside of f. Such power of the language gradually developed > into a style of programing. For example: > subroutine a_surface () { > coordinatesList = ...; > subroutine translate (distance) {...} > subroutine rotate (angle) {..} > } > > Such a style is that the a_surface is no longer viewed as a function. > But instead, a boxed set of functions, centered around a piece of data. > And, all functions for manipulating this piece of data are all embodied > in this function. For example: > subroutine a_surface (arg) { > coordinatesList = ... > subroutine translate (distance) {set coordinatesList to translated > version} > subroutine rotate (angle) {set coordinatesList to rotated version} > subroutine return () {return coordinatesList} > > if (no arg) {return coordinatesList} > else { apply arg to coordinatesList } > } > > In this way, one uses a_surface as a data, which comes with its owe set > of functions: > mySurface = a_surface(); > mySurface(rotate(angle)); // now the surface data has been > rotated > mySurface(translate(distance)); // now its translated > newSurface = mySurface(return()) > > So now, a_surface is no longer viewed as a subroutine, but a boxed set > of things centered around a piece of data. All functions that work on > the data are included in the boxed set. This paradigm possible in > functional languages has refined so much so that it spread to other > groups and became known as Object Oriented Programing, and complete > languages with new syntax catered to such scheme emerged. > > In such languages, instead of writing them like this: > mySurface = a_surface(); > mySurface(rotate(angle)); > > the syntax is changed to like this, for example: > mySurface = new a_surface(); > mySurfaceRotated = mySurface.rotate(angle); > > In such languages, the super subroutine a_surface is no longer called a > function or subroutine. It is now called a ?Class?. And now the > variable holding the function "mySurface = a_surface()" is now called a > ?Object?. Subroutines inside the function a_surface() are no longer > called inner-subroutines. They are called ?Methods?. The act of > assigning a super-subroutine to a variable is called instantiation. > > This style of programing and language have become so fanatical that in > such dedicated languages like Java, everything in the language are > ?Classes?. One can no longer just define a variable or subroutine. > Instead, one creates these meta-subroutine ?Classes?. Everything > one do are inside Classes. And one assign Classes inside these Classes > to create ?Objects?. And one uses ?Methods? to manipulate > Objects. In this fashion, even basic primitives like numbers, strings, > and lists are no longer atomic entities. They are now Classes. > > For example, in Java, a string is a class String. And inside the class > String, there are Methods to manipulate strings, such as finding the > number of chars, or extracting parts of the string. This can get very > complicated. For example, in Java, there are actually two Classes of > strings: One is String, and the other is StringBuffer. Which one to use > depends on whether you intend to change the data. > > So, a simple code like this in normal languages: > a = "a string"; > b = "another one"; > c = join(a,b); > print c; > > or in lisp style > (set a "a string") > (set b "another one") > (set c (join a b)) > (print c) > > becomes in pure OOP languages: > public class test { > public static void main(String[] args) { > String a = new String("a string"); > String b = new String("another one"); > StringBuffer c = new StringBuffer(40); > c.append(a); c.append(b); > System.out.println(c.toString()); > } > } > > Here, the "new String" creates a String object. The "new > StringBuffer(40)" creates the changeable string object StringBuffer, > with room for 40 chars. "append" is a method of StringBuffer. It is > used to join two Strings. > > Notice the syntax "c.append(a)", which we can view it as calling a > inner subroutine "append", on a super subroutine that has been assigned > to c, where, the inner subroutine modifies the inner data by appending > a to it. > > And in the above Java example, StringBuffer class has another method > "toString()" used to convert this into a String Class, necessary > because System.out.println's parameter requires a String type, not > StringBuffer. > > For a example of the complexity of classes and methods, see the Java > documentation for the StringBuffer class at > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html > (local copy) > > In the same way, numbers in Java have become a formalization of many > classes: Double, Float, Integer, Long... and each has a bunch of > "methods" to operate or convert from one to the other. > > Instead of > aNumber = 3; > print aNumber^3; > > In Java the programer needs to master the ins and outs of the several > number classes, and decide which one to use. (and if a program later > needs to change from one type of number to another, it is often > cumbersome.) > > This Object Oriented Programing style and dedicated languages (such as > C++, Java) have become a fad like wild fire among the programing mass > of ignoramuses in the industry. Partly because of the data-centric new > perspective, partly because the novelty and mysticism of new syntax and > jargonization. > > It is especially hyped by the opportunist Sun Microsystems with the > inception of Java, internet, and web applications booms around 1995. At > those times, OOP (and Java) were thought to revolutionize the industry > and solve all software engineering problems, in particular by certain > "reuse of components" concept that was thought to come with OOP. > > As part of this new syntax and purity, where everything in a program is > of Classes and Objects and Methods, many complex issues and concept > have arisen in OOP. > > We now know that the jargon Class is originally and effectively just a > boxed set of data and subroutines, all defined inside a subroutine. And > the jargon "Object" is just a variable that has been set to this super > subroutine. And the inner subroutines are what's called Methods. > > ---------- > to be continued tomorrow. > > This is part of an installment of the article > ?What are OOP's Jargons and Complexities? > by Xah Lee, 20050128. The full text is at > http://xahlee.org/Periodic_dosage_dir/t2/oop.html > > ? Copyright 2005 by Xah Lee. Verbatim duplication of the complete > article for non-profit purposes is granted. > > The article is published in the following newsgroups: > comp.lang.c,comp.lang.c++,comp.lang.lisp,comp.unix.programmer > comp.lang.python,comp.lang.perl.misc,comp.lang.scheme,comp.lang.java.programmer > comp.lang.functional,comp.object,comp.software-eng,comp.software.patterns > > Xah > xah at xahlee.org > ? http://xahlee.org/ > From jstroud at mbi.ucla.edu Tue May 10 14:06:30 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 10 May 2005 11:06:30 -0700 Subject: Need a little parse help In-Reply-To: <000901c55589$c6597880$6400a8c0@grondor> References: <000901c55589$c6597880$6400a8c0@grondor> Message-ID: <200505101106.30248.jstroud@mbi.ucla.edu> Try outputfile.write(words[1]+"\n") On Tuesday 10 May 2005 10:57 am, Alex Nordhus wrote: > outputfile.write(words[1]) -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From jdc at uwo.ca Mon May 9 16:17:15 2005 From: jdc at uwo.ca (Dan Christensen) Date: Mon, 09 May 2005 16:17:15 -0400 Subject: global lists In-Reply-To: References: Message-ID: <87acn4upbo.fsf@uwo.ca> andrea crotti writes: > Hi everbybody again, > I have a little "problem", I don't understand the reason of this: > > a = [10,1,2,3] > def foo(): > global a > for n in range(len(a)): > a[n] = a[n]*2 If I type the above, and then call foo, I get what looks like reasonable output: In [1]:a = [10,1,2,3] In [2]:def foo(): .2.: global a .2.: for n in range(len(a)): .2.: a[n] = a[n]*2 .2.: In [3]:foo() In [4]:print a [20, 2, 4, 6] However, you didn't say what you expected, so I'm not sure what bug I'm looking for! Dan From cfbolz at gmx.de Mon May 23 13:26:14 2005 From: cfbolz at gmx.de (Carl Friedrich Bolz) Date: Mon, 23 May 2005 19:26:14 +0200 Subject: first release of PyPy In-Reply-To: References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> Message-ID: <42921236.7010509@gmx.de> Rocco Moretti wrote: > Alex Stapleton wrote: > >>The question still remains, can it run it's self? ;) >> This allready worked in the past, though it doesn't at the moment. > > > I think they try, every once in a while, to self host. The only problem > at this stage of the game is the ~2000x speed slowdown. Using that > figure, a five second startup time for PyPy on CPython would take about > 3 hours for PyPy on PyPy on CPython (5s*2000). Running a 1 second (on > CPython) Python program would take a month and a half for PyPy on PyPy > on CPython. (1s*2000*2000) > > Once they get the speed issue licked, the self hosting problems should > be no trouble. ;) Speed isn't even the biggest problem when running PyPy on itself. PyPy still 'fakes' some objects, e.g. borrows them from the underlying Python. This is mostly the case for things that have direct access to the OS, e.g. files. If you run PyPy on PyPy on CPython you try to fake the faked objects again, which gives trouble. Since we have to handle faked objects differently in the future anyway we decided that at the moment it isn't worth the effort to keep the self-hosting working. Regards, Carl Friedrich From gandalf at geochemsource.com Thu May 19 04:03:51 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Thu, 19 May 2005 10:03:51 +0200 Subject: EpyDoc problem In-Reply-To: <1116446157.756809.97320@g49g2000cwa.googlegroups.com> References: <428A5CAA.906@geochemsource.com> <428A66A8.9090000@geochemsource.com> <1116446157.756809.97320@g49g2000cwa.googlegroups.com> Message-ID: <428C4867.4050906@geochemsource.com> >EpyDoc is hosted in Sourceforge. This alone may answer your question >about a bug-tracker: > >http://sourceforge.net/tracker/?atid=405618&group_id=32455&func=browse > > Well, I wrote to the bug tracker some days ago but no answer so far. From jepler at unpythonic.net Wed May 4 12:21:09 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed, 4 May 2005 11:21:09 -0500 Subject: descriptor dilemma In-Reply-To: <1115223258.624304.198900@f14g2000cwb.googlegroups.com> References: <1115216416.700492.71020@f14g2000cwb.googlegroups.com> <1115223258.624304.198900@f14g2000cwb.googlegroups.com> Message-ID: <20050504162108.GE14737@unpythonic.net> On Wed, May 04, 2005 at 09:14:18AM -0700, S?bastien Boisg?rault wrote: > > Yup ?!? Weird ... especially as: > > >>> id(c.f) == id(C.__dict__['f'].__get__(c,C)) > True Here, c.f is discarded by the time the right-hand-side of == is executed. So the object whose id() is being calculated on the right-hand-side could turn out to be the same, since the two objects have disjoint lifetimes. Here are some more cases of the same thing: >>> id([]) == id([]) 1 >>> id([]) == id([1]) 1 Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From phillip.watts at anvilcom.com Wed May 18 12:05:26 2005 From: phillip.watts at anvilcom.com (phil) Date: Wed, 18 May 2005 11:05:26 -0500 Subject: iso_8859_1 mystery/tkinter Message-ID: <428B67C6.7000708@anvilcom.com> These work fine on Linux s.const = {} s.const['DEG'] = '%c' % (0xb0) s.const['DIV'] = '%c' % (0xf7) s.const['ANG'] = '%c' % (0xd8) On WinXP the symbols for division and angle work fine. But the symbol for degrees, a little circle, produces a vertical bar in Tkinter Text box or Canvas. However, if I run from IDLE and output to a console window, 0xb0 produces the correct character for degrees. Any idea why? Thanks From philippe at philippecmartin.com Sat May 14 14:46:25 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 14 May 2005 18:46:25 GMT Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> Message-ID: <5Irhe.1553$sb5.144@newssvr12.news.prodigy.com> Yes, I gathered. We all get our habits from somewhere :-) Regards, Philippe Bernd Nawothnig wrote: > On 2005-05-14, Philippe C. Martin wrote: > >> You're thinking you're passing the arguments as reference > > That is the way Fortran handles them: > > [...] > >>> Right now I'm taking a simple program I wrote in Fortran > > > > > Bernd > From sjmachin at lexicon.net Tue May 31 18:45:08 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 01 Jun 2005 08:45:08 +1000 Subject: The need to put "self" in every method In-Reply-To: References: <1117554344.938440.54700@g14g2000cwa.googlegroups.com> Message-ID: <429CE8F4.5070301@lexicon.net> Simon Brunning wrote: > On 31 May 2005 08:45:45 -0700, Fernando M. > wrote: > >>i was just wondering about the need to put "self" as the first >>parameter in every method a class has because, if it's always needed, >>why the obligation to write it? > > > It doesn't need to be 'self'. You could use 'this', or 's', or whatever. > > Of course, if you *don't* use 'self', you should expect an angly mob > with pitchforks and torches outside your castle. > Wouldn't an angly mob be carrying fishing rods? From snobis at gmx.de Mon May 16 12:37:24 2005 From: snobis at gmx.de (Stefan Nobis) Date: Mon, 16 May 2005 18:37:24 +0200 Subject: Newbie : checking semantics References: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> <87d5rrsh7h.fsf@snobis.de> Message-ID: <87fywnuny3.fsf@snobis.de> Andrew Dalke writes: > When you say "beginners" is that people with no previous > programming experience >From time to time I teach some programming (in an institution called "Volkshochschule" here in Germany -- inexpensive courses for adults). My Python course is for absolute beginners with no previous programming experience of any kind. And yes, this people have quite some difficulties to get their blocks indented right. Before Python I used C++ in this beginner course and at least setting the boundaries for blocks was a little less of a problem. So I would appreciate optional statements to end a block (indentation rules may be mandatory). This comes also very handy in something like Python Server Pages of mod_python (where a comment line to explicitly end a block is sometimes needed). -- Stefan. From jmdeschamps at cvm.qc.ca Sun May 15 23:36:31 2005 From: jmdeschamps at cvm.qc.ca (jean-marc) Date: 15 May 2005 20:36:31 -0700 Subject: PythonWin + Tkinter = broken relation with WindowsXP !?!?! Message-ID: <1116214591.343470.213660@o13g2000cwo.googlegroups.com> I read that Tkinter and Python IDEs (PythonWin and Idle at least) makes for a bad mix in execution mode because they're fighting for the event loop, but this mode is usefull to use the debugger. But to the point of breaking something elsewhere than in memory ??? (Shutting down and rebooting the computer doesn't resolve the problems... PythonWin becomes impossible to use if another window is open (pdf files, winAmp music, browser et al...) is this documented somewhere??? It's been happening quite a few times to me (real bummer!). NOTE: This situation seems to appear slowly... Not like a works or doesn't work situation but rather that corruption is progressive. This is a complete mystery to me???? Thanks in advance, JMD Python 2.3.5, WinXP Pro SP2 I've started using Python Scripter, which seems less problematic (at this point) From frithiof.jensen at die_spammer_die.ericsson.com Tue May 24 08:16:50 2005 From: frithiof.jensen at die_spammer_die.ericsson.com (Frithiof Andreas Jensen) Date: Tue, 24 May 2005 14:16:50 +0200 Subject: SQL Query via python References: <200505211500.06747.jeffelkins@earthlink.net> Message-ID: "Jeff Elkins" wrote in message news:mailman.305.1116740808.8733.python-list at python.org... > Just as an fyi: > > In one weekend I have gone from knowing zip about SQL/Python to implementing > code on my personal server that emails info to family about birthdays and > such. Actually - http://www.pythonweb.org/ will handle the SQL (and many other tasks) in a much simpler way! If you do try the web.database.object examples, be aware that the docs are not entirely tracking the code; f.ex. databases have no "type" parameter; it's an "adapter" i.e. connection = web.database.connect(type="sqlite",database="object-simple.db") should be: connection = web.database.connect(adapter="sqlite",database="object-simple.db")' there are probably others - it's good to see what the parameters are in "idle" if something does not work as advertised. Overall, Pythonweb is very impressive work IMO. From michele.petrazzo at TOGLIunipex.it Tue May 31 07:56:38 2005 From: michele.petrazzo at TOGLIunipex.it (Michele Petrazzo) Date: Tue, 31 May 2005 13:56:38 +0200 Subject: sys.stderr and thread Message-ID: <429c500c$0$15913$5fc30a8@news.tiscali.it> I have a wxpython application (the main program) and a lot of external modules (import mymodule) that use always 2 thread (one is my application and one is twisted with new threadselectreactor). Sometime when I close my app, I receive a thread error that I want to redirect to a file (I don't know why this error occur, but this is another problem...). I use the redirection of stderr and stdout to a file This work for all my application, work also for an exception that I insert for try, but not for the thread error (when this occur). Is there a solution for redirect all the messages? This is the exception: Unhandled exception in thread started by > Traceback (most recent call last): File "C:\Python23\lib\threading.py", line 451, in __bootstrap self.__stop() File "C:\Python23\lib\threading.py", line 460, in __stop self.__block.notifyAll() File "C:\Python23\lib\threading.py", line 256, in notifyAll self.notify(len(self.__waiters)) File "C:\Python23\lib\threading.py", line 238, in notify currentThread() # for side-effect TypeError: 'NoneType' object is not callable Thanks, Michele From guettli at thomas-guettler.de Thu May 26 10:03:28 2005 From: guettli at thomas-guettler.de (Thomas Guettler) Date: Thu, 26 May 2005 16:03:28 +0200 Subject: converting jpg to pdf References: <1117116021.652260.66260@g14g2000cwa.googlegroups.com> Message-ID: Am Thu, 26 May 2005 07:00:21 -0700 schrieb Raghul: > Hi friends > Is it possible to convert jpg to pdf in python. I need a > program to convert jpg format file to pdf. Is there any sample or any > library to do that? Pls guide me. Hi, import os os.system("convert foo.jpg foo.pdf") convert is part of ImageMagick. HTH, Thomas -- Thomas G?ttler, http://www.thomas-guettler.de/ From geoffSPAMarnold at hotmail.com Wed May 11 18:21:28 2005 From: geoffSPAMarnold at hotmail.com (Fletch) Date: Wed, 11 May 2005 15:21:28 -0700 Subject: BluWater: God is not a man In-Reply-To: <1115839435.018664.70230@f14g2000cwb.googlegroups.com> References: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> <1115839435.018664.70230@f14g2000cwb.googlegroups.com> Message-ID: Obaid R. wrote: > For a detailed response to the claims of the poster please refer to the > following. > > [1] "Ron Grossi: God is not a man" an essay: > http://groups-beta.google.com/group/microsoft.public.windowsxp.networ... > > [2] "Ron Grossi: God is not a man" an entire thread: > http://groups-beta.google.com/group/microsoft.public.windowsxp.networ... > > Here is a quick quote showing the man at odds with none other than > Christ, peace and blessings be upon him, (PBBUH) himself: > > "Moreover, and on at least two occasions in > the Bible, Christ PBBUH is explicitly > proclaiming that he was sent only to the lost > sheep of the house of Israel, not to anyone > else of the Gentiles. > > "But he answered and said, I am not sent but > unto the lost sheep of the house of Israel." > (Matthew 15: 24) (see also Matthew 10:6)." > You clearly need to do more reading and learn that Jesus was not so short sighted or narrow of mind that He was not aware of the extent to which His teachings would be spread. Was it not Jesus who also said, preach the gospel to the whole world, make disciples of the whole world, which obviously includes Gentiles? And need I remind you of John 3:16? "For God so love the world (not just Israel), that He gave is only begotten Son that whosoever (fully inclusive of all humanity) believes in Him shall not perish but have everlasting life." Clearly, you need to do more study of the scriptures to understand the depth of the message Jesus brought, not just for Israel, but the whole world, something He was quite clear was the function and purpose of His ministry. As for Ron Gossi, well, we will simply say that he has been asked to cease and desist from these invasive spam posts as they do not reflect the nature of God, to stand at the door and knock, waiting to be invited in. --fletch From bj_666 at gmx.net Mon May 16 16:18:17 2005 From: bj_666 at gmx.net (Marc 'BlackJack' Rintsch) Date: Mon, 16 May 2005 22:18:17 +0200 Subject: trouble with copy/deepcopy References: Message-ID: In , Alexander Zatvornitskiy wrote: > class Distribution: > __gr_on_transp=dict() > __ostatok_m=dict() > and so on Those two dicts are *class variables* not *instance variables*! > And, I want to make full copy of it: > d1=Distribution() > d2=copy.deepcopy(d1) > > But, members-dictionaries are don't copied. For example if I will write: > d1.clear() > which clears all two dictionaries, I will find that d2's dictionaries are also > empty!!! That clears only one dictionary at class level. Which is visible on both instances. class Distribution: def __init__(self): self.__gr_on_transp = dict() self.__ostatok_m = dict() ... This creates *instance variables* which should be deepcopied without problems. Ciao, Marc 'BlackJack' Rintsch From ivoras at _-_fer.hr Wed May 4 17:17:32 2005 From: ivoras at _-_fer.hr (Ivan Voras) Date: Wed, 04 May 2005 23:17:32 +0200 Subject: wxPython custom list drawing? Message-ID: Does wxPython (actually, the wx toolkit) support setting up ListCtrls or similar to allow custom element drawing? Something like generating an 'OnPaint()' event in which I could paint whatever I like in a listbox element. (example from some other toolkits) From steven.bethard at gmail.com Thu May 19 10:09:29 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 May 2005 08:09:29 -0600 Subject: help with generators In-Reply-To: <1116494846.500522.31920@g47g2000cwa.googlegroups.com> References: <1116461870.130411.9280@g43g2000cwa.googlegroups.com> <1116494846.500522.31920@g47g2000cwa.googlegroups.com> Message-ID: George Sakkis wrote: > "Steven Bethard" wrote: > >>py> def bin(n): >>... s = [] >>... def bin(n): >>... if n == 0: >>... yield s >>... else: >>... s.append(0) >>... for s1 in bin(n - 1): >>... yield s1 >>... s.pop() >>... s.append(1) >>... for s1 in bin(n - 1): >>... yield s1 >>... s.pop() >>... return bin(n) >>... [snip] > A caveat of the implementation above: it yields the same instance (s), > which is unsafe if the loop variable is modified (e.g. in the "for s in > bin(n)" loop, s should not be modified). Moreover, each yielded value > should be 'consumed' and then discarded; attempting to store it (as in > list(bin(n))) references only the last yielded value. Yup. However, this was the most direct translation of the OP's original function (which also only had a single list). Since the question was about how generators worked, I figured the most direct translation would probably be the most useful response. > Here's a shorter, clear and safe implementation: > > def bin2(n): > if n: > for tail in bin2(n-1): > yield [0] + tail > yield [1] + tail > else: > yield [] This is definitely the way I would have written it. STeVe From steven.bethard at gmail.com Fri May 6 18:03:56 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Fri, 06 May 2005 16:03:56 -0600 Subject: min max of a list In-Reply-To: References: <1115245476.036508.273930@g14g2000cwa.googlegroups.com> <1115259992.558123.189580@g14g2000cwa.googlegroups.com> <1115396805.064114.183010@f14g2000cwb.googlegroups.com> <1115408190.437054.222350@z14g2000cwz.googlegroups.com> Message-ID: Peter Hansen wrote: > querypk at gmail.com wrote: > >> I get a syntax error in : >> >> py> [(min((abs(p - v), v) for v in valleys + [0] if v < p)[1], >> ... p, >> ... min((abs(p - v), v) for v in valleys if v > p)[1]) >> ... for p in peaks] > > > I think we already covered the part where you were using an older > version of Python. In this case, the missing feature is "generator > expressions" and they are inside the two min() calls. > > You might want to consider upgrading... But if you can't, you should write this as something like: [(min([(abs(p - v), v) for v in valleys + [0] if v < p])[1], p, min([(abs(p - v), v) for v in valleys if v > p])[1]) for p in peaks] Note the extra brackets in the min calls. STeVe From borges2003xx at yahoo.it Tue May 31 09:31:32 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 31 May 2005 06:31:32 -0700 Subject: regular expression problem In-Reply-To: <1117529673.000965.321770@g49g2000cwa.googlegroups.com> References: <1117527562.055872.93830@o13g2000cwo.googlegroups.com> <1117529673.000965.321770@g49g2000cwa.googlegroups.com> Message-ID: <1117546292.578437.298070@g47g2000cwa.googlegroups.com> thank you again: i used list and not set because order in my list is important. in fact i'd like to apply this function to strings (or ordered sequences of data). For this reason proposed to use regular expression. best regards. From ptmcg at austin.rr.com Sat May 28 01:29:17 2005 From: ptmcg at austin.rr.com (Paul McGuire) Date: 27 May 2005 22:29:17 -0700 Subject: regexp for sequence of quoted strings References: <1117050058.836444.189460@o13g2000cwo.googlegroups.com> <1117058353.702619.179010@z14g2000cwz.googlegroups.com> <1117221696.053591.152710@g44g2000cwa.googlegroups.com> Message-ID: <1117258157.381526.16770@g49g2000cwa.googlegroups.com> George - Thanks for your enthusiastic endorsement! Here are some quibbles about your pyparsing grammar (but really, not bad for a first timer): 1. The Word class is used to define "words" or collective groups of characters, by specifying what sets of characters are valid as leading and/or body chars, as in: integer = Word(digitsFrom0to9) firstName = Word(upcaseAlphas, lowcaseAlphas) In your parser, I think you want the Literal class instead, to match the literal string '{'. 2. I don't think there is any chance to confuse a withQuotes with a withoutQuotes, so you can try using the "match first" operator '|', rather than the greedy matching "match longest" operator '^'. 3. Lastly, don't be too quick to use asList() to convert parse results into lists - parse results already have most of the list accessors people would need to access the returned matched tokens. asList() just cleans up the output a bit. Good luck, and thanks for trying pyparsing! -- Paul From dalke at dalkescientific.com Mon May 2 12:33:54 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Mon, 02 May 2005 16:33:54 GMT Subject: lists in cx_Oracle References: <1115047620.602263.180780@o13g2000cwo.googlegroups.com> Message-ID: infidel wrote: > Something like this might work for you: > >>>> ids= ['D102', 'D103', 'D107', 'D108'] >>>> in_clause = ', '.join([':id%d' % x for x in xrange(len(ids))]) >>>> sql = "select * from tablename where id in (%s)" % in_clause >>>> import cx_Oracle as ora >>>> con = ora.connect('foo/bar at geewhiz') >>>> cur = con.cursor() >>>> cur.execute(sql, ids) That's pretty much what I did but it seems inelegant. I would rather do ids = ['D102', 'D103', 'D107', 'D108'] .. connect and set up the cursor .. cursor.execute("select * from tablename where id in :ids", ids) and if 'ids' is seen to be a list or tuple then it does the appropriate conversion. (I'm also fine with having to use ()s in the SQL query, as in "id in (:ids)".) The lack of a simple way to do this is error prone. I've seen people do cursor.execute("select * from tablename where id in (%s)" % repr(ids)) because the repr of a string is close enough that it works for expected string values. But it opens up the possibility of SQL injection problems. Andrew dalke at dalkescientific.com From iker at research.att.com Tue May 17 13:34:29 2005 From: iker at research.att.com (Iker Arizmendi) Date: Tue, 17 May 2005 17:34:29 GMT Subject: Adding "proxy" functions to a type Message-ID: <428A2B25.9010409@research.att.com> Hello all. Is there a convenient scheme within a C extension to add methods to a type in such a way as to allow me to transparently add a "proxy" around them? For example: typedef PyObject* (*PyMethodCall)(PyObject*, PyObject*); PyObject* middleMan(PyObject* self, PyObject* args) { printf("Before call to wrapped funct\n"); PyMethodCall actualFunc = getRealFunction(...); PyObject* retval = actualFunc(self, args); printf("After call to wrapped func\n"); return retval; } void addMethod(PyTypeObject* t, PyMethodCall* m, char* name, char* doc) { // code to forward calls to "middleMan" while putting the // pointer to "m" somewhere convenient ... } My current solution is cumbersome and involves adding a special field to the PyObject associated with my type, a custom tp_getattro function and the "middleMan" function: struct MyPyObj { PyObject_HEAD PyMethodCall realfunc; }; // when adding the method def for "m" instead of pointing it to // the given function, I point it to the middle man and save // the "m" function somewhere I can find it later. void addMethod(PyTypeObject* t, PyMethodCall m, char* name, char* doc) { PyMethodDef* def = allocPyMethodDef(t, name); def->ml_name = name; def->ml_doc = doc; def->ml_meth = middleMan; def->ml_flags = METH_VARARGS; saveTargetFunction(name, m); // note I add these here so that documentation is // available within the interpreter PyObject* methobj = PyDescr_NewMethod(t, def); PyDict_SetItemString(t->tp_dict, def->ml_name, methobj); Py_DECREF(methobj); } // when the interpreter does a lookup on an instance of my // type I set the "realfunc" member of my PyObject and return // a bound method (which will call into middleMan). PyObject* customGetaAttro(PyObject* self, PyObject* name) { MyPyObj* rself = (MyPyObj*)self; rself->realfunc = findSavedTargetFunc(name); PyMethodDef* mdef = getMethodDef(self->ob_type, name); return PyCFunction_New(def, self); } // finally, when the middle man is called it extracts the "real" // function from self and calls that. PyObject* middleMan(PyObject* self, PyObject* args) { MyPyObj* rself = (MyPyObj*)(self); printf("pre call\n"); PyObject* rv = rself->realfunc(rself->obj, args); printf("post call\n"); rself->realfunc = 0; return rv; } The problem here is that this doesn't work for static functions which lack a self argument, or for module level functions. Is there a better way? Thanks, Iker Arizmendi From tim.peters at gmail.com Tue May 17 12:39:58 2005 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 17 May 2005 12:39:58 -0400 Subject: processing a Very Large file In-Reply-To: <118k530sl6kve5c@corp.supernews.com> References: <118k530sl6kve5c@corp.supernews.com> Message-ID: <1f7befae05051709396590e224@mail.gmail.com> [DJTB] > I'm trying to manually parse a dataset stored in a file. The data should be > converted into Python objects. > > Here is an example of a single line of a (small) dataset: > > 3 13 17 19 -626177023 -1688330994 -834622062 -409108332 297174549 955187488 589884464 -1547848504 857311165 585616830 -749910209 194940864 -1102778558 -1282985276 -1220931512 792256075 -340699912 1496177106 1760327384 -1068195107 95705193 1286147818 -416474772 745439854 1932457456 -1266423822 -1150051085 1359928308 129778935 1235905400 532121853 > > The first integer specifies the length of a tuple object. In this case, the > tuple has three element: (13, 17, 19) > The other values (-626177023 to 532121853) are elements of a Set. > > I use the following code to process a file: > > from time import time > from sets import Set > from string import split Note that you don't use string.split later. > file = 'pathtable_ht.dat' > result = [] > start_time = time () > f=open(file,'r') > for line in f: > splitres = line.split() Since they're all integers, may as well: splitres = map(int, line.split()) here and skip repeated int() calls later. > tuple_size = int(splitres[0])+1 > path_tuple = tuple(splitres[1:tuple_size]) > conflicts = Set(map(int,splitres[tuple_size:-1])) Do you really mean to throw away the last value on the line? That is, why is the slice here [tuple_size:-1] rather than [tuple_size:]? > # do something with 'path_tuple' and 'conflicts' > # ... do some processing ... > result.append(( path_tuple, conflicts)) > > f.close() > print time() - start_time > > The elements (integer objects) in these Sets are being shared between the > sets, in fact, there are as many distinct element as there are lines in the > file (eg 1000 lines -> 1000 distinct set elements). AFAIK, the elements are > stored only once and each Set contains a pointer to the actual object Only "small" integers are stored uniquely; e.g., these aren't: >>> 100 * 100 is 100 * 100 False >>> int("12345") is int("12345") False You could manually do something akin to Python's "string interning" to store ints uniquely, like: int_table = {} def uniqueint(i): return int_table.setdefault(i, i) Then, e.g., >>> uniqueint(100 * 100) is uniqueint(100 * 100) True >>> uniqueint(int("12345")) is uniqueint(int("12345")) True Doing Set(map(uniqueint, etc)) would then feed truly shared int (and/or long) objects to the Set constructor. > This works fine with relatively small datasets, but it doesn't work at all > with large datasets (4500 lines, 45000 chars per line). Well, chars/line doesn't mean anything to us. Knowing # of set elements/line might help. Say there are 4500 per line. Then you've got about 20 million integers. That will consume at least several 100 MB if you don't work to share duplicates. But if you do so work, it should cut the memory burden by a factor of thousands. > After a few seconds of loading, all main memory is consumed by the Python > process and the computer starts swapping. After a few more seconds, CPU > usage drops from 99% to 1% and all swap memory is consumed: > > Mem: 386540k total, 380848k used, 4692k free, 796k buffers > Swap: 562232k total, 562232k used, 0k free, 27416k cached > > At this point, my computer becomes unusable. > > I'd like to know if I should buy some more memory (a few GB?) or if it is > possible to make my code more memory efficient. See above for the latter. If you have a 32-bit processor, you won't be able to _address_ more than a few GB anyway. Still, 384MB of RAM is on the light side these days . From python at rcn.com Thu May 26 05:32:31 2005 From: python at rcn.com (Raymond Hettinger) Date: 26 May 2005 02:32:31 -0700 Subject: Checking for a full house References: <1117071824.882035.250710@g49g2000cwa.googlegroups.com> <1117085950.739186.14240@z14g2000cwz.googlegroups.com> <1117086974.854184.5930@g43g2000cwa.googlegroups.com> <7x8y22v76i.fsf@ruckus.brouhaha.com> <5Cele.101369$Sd5.6145133@phobos.telenet-ops.be> Message-ID: <1117099951.524496.232130@f14g2000cwb.googlegroups.com> [Benedict] >> It would be interesting to see how complicated it would get to write >> code to detect the correct hands in poker with wildcards included. There is an interesting SF project with code written in C: http://pokersource.sourceforge.net/ In contrast, Python makes short work of these kind of problems. Here are some primitives to get you started (just add a representation for suits, flush detection, and controlling logic for ranking hands): def is_straight(hand, numwildcards=0): """Checks for a five card straight Inputs: list of non-wildcards plus wildcard count 2,3,4, ... 10, 11 for Jack, 12 for Queen, 13 for King, 14 for Ace Hand can be any length (i.e. it works for seven card games). Outputs: highest card in a five card straight or 0 if not a straight. Original list is not mutated. Ace can also be a low card (i.e. A2345). >>> is_straight([14,2,3,4,5]) 5 >>> is_straight([14,2,3,4,6]) 0 >>> is_straight([10,11,12,13,14]) 14 >>> is_straight([2,3,5], 2) 6 >>> is_straight([], 5) 14 >>> is_straight([2,4,6,8,10], 3) 12 >>> is_straight([2,4,4,5,5], 2) 6 """ hand = set(hand) if 14 in hand: hand.add(1) for low in (10,9,8,7,6,5,4,3,2,1): needed = set(range(low, low+5)) if len(needed & hand) + numwildcards >= 5: return low+4 return 0 def groups(hand, numwildcards=0): """Checks for pairs, threes-of-kind, fours-of-a-kind, and fives-of-a-kind Inputs: list of non-wildcards plus wildcard count 2,3,4, ... 10, 11 for Jack, 12 for Queen, 13 for King, 14 for Ace Hand can be any length (i.e. it works for seven card games) Output: tuple with counts for each value (high cards first) for example (3, 14), (2, 11) full-house Aces over Jacks for example (2, 9), (2, 7) two-pair Nines and Sevens Maximum count is limited to five (there is no seven of a kind). Original list is not mutated. >>> groups([11,14,11,14,14]) [(3, 14), (2, 11)] >>> groups([7, 9, 10, 9, 7]) [(2, 9), (2, 7)] >>> groups([11,14,11,14], 1) [(3, 14), (2, 11)] >>> groups([9,9,9,9,8], 2) [(5, 9), (2, 8)] >>> groups([], 7) [(5, 14), (2, 13)] """ result = [] counts = [(hand.count(v), v) for v in range(2,15)] for c, v in sorted(counts, reverse=True): newcount = min(5, c + numwildcards) # Add wildcards upto five numwildcards -= newcount - c # Wildcards remaining if newcount > 1: result.append((newcount, v)) return result import doctest print doctest.testmod() From greg at invalid.invalid Sat May 14 03:41:20 2005 From: greg at invalid.invalid (Greg Krohn) Date: Sat, 14 May 2005 07:41:20 GMT Subject: pygame on win32, image.fromstring() In-Reply-To: References: Message-ID: tlviewer wrote: > hello, hi > fp = open( "e:/batch/python/aceclub.bmp", "wt") wt? Should this be wb? > # gives: ValueError: String length does not equal format and resolution size > img = gm.image.fromstring(str,(71,96),"P") The pygame docs say "P" is for 8bit pallete indices. When I look at the properties of aceclub.bmp, Windows says it's Bit Depth is 4. I'm not sure if they're talking about the same thing, though. If so, you could probably use PIL to convert the depth. -greg From sjmachin at lexicon.net Wed May 25 00:24:55 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 25 May 2005 14:24:55 +1000 Subject: Counting occurences of words in a list of strings In-Reply-To: References: Message-ID: <4293fe18@news.eftel.com> Travers Naran wrote: > Here's the basic idea. I have a dictionary of substrings (the > substrings stored as keys). I have a list of strings. I want to find > out, for each word in the dictionary, how many times the substring > occurs non-overlapping occurrences there are in the list of strings. > This is the best I could come up with: > > for j in self.dict.keys(): > c = 0 > for i in tc.strings: > c += i.count(j) > self.dict[j]['count'] += c > > I tried Boyer-Moore-Horspool as someone else suggested in the group, but > it was even slower (probably because of the time spent setting up the > pattern). Even when I split the algorithm in two, doing the set-up > before the inner loop and only testing the pattern in the inner loop, it > was still slow. Are you comparing BMH implemented in Python with str.count() implemented in C? > > So, am I doing this the optimal way or am I overlooking something > _really_ simple to do? > > Statistics on the data: > The dictionary has 3000+ entries in it. > There are several thousand strings. > The strings average 10-26 characters in length. 1. A pure Python suggestion: Presuming there is a character SEP that cannot appear in the keys in your query dictionary, try this: SEP = '\n' # for example big_string_count = SEP.join(tc.strings).count for query_key in self.dict.keys(): self.dict[query_key]['count'] += big_string_count(query_key) Why do we have += in the above line? Is there anything else being added in by not-shown code? If not, the following would be much more comprehensible, and faster: self.dict_count = {} SEP = '\n' # for example big_string_count = SEP.join(tc.strings).count for query_key in self.dict.keys(): self.dict_count[query_key] = big_string_count(query_key) Checking your requirements for "non-overlapping": if you have 'foobar' and 'barzot' in the dictionary, and a string contains 'foobarzot', your code will count 1 for 'foobar' and 1 for 'barzot'. Is that OK? 2. Next, if you don't mind using a C-extension, look at Danny Yoo's ahocorasick module, which will search in parallel for your 3000+ keys. http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/ Under one definition of non-overlapping, you will be able to use one of the findall methods; under the other definition, you will need to use one of the search methods and restart at (matched_position + 1). 3. If you want to roll your own, start with Gonzalo Navarro's publications: http://www.dcc.uchile.cl/~gnavarro/subj-multiple.html HTH, John From pcolsen at comcast.net Sun May 1 09:18:27 2005 From: pcolsen at comcast.net (Engineer) Date: 1 May 2005 06:18:27 -0700 Subject: Python interpreter in Basic or a Python-2-Basic translator. Message-ID: <1114953507.031865.244920@g14g2000cwa.googlegroups.com> I'm looking for a Python interpreter written in BASIC, preferably Visual Basic, and one written in VBA would be best of all. An alternative would be a Python-2-Basic compiler. Unfortunately I have to develop some special purpose code in an organization where my only development environment is Microsoft Office Visual Basic for Applications. The security 'droids have decided that since the MS Office Suite is a "standard" application then software written in MS Office VBA must be "safe." Any other development environments (such as Java, Perl, Cygwin) are "unsafe" and can't be installed. The result is that any software I write must be bootstrapped from MS Office VBA. So, if I want Python, I need a Python interpreter in VBA. If you respond, please send a copy to pcolsen at comcast.net From tim.tadh at gmail.com Mon May 2 22:47:15 2005 From: tim.tadh at gmail.com (Tim Henderson) Date: 2 May 2005 19:47:15 -0700 Subject: Inspect Python Classes for instance data information In-Reply-To: <1115081401.464719.142070@o13g2000cwo.googlegroups.com> References: <1115081401.464719.142070@o13g2000cwo.googlegroups.com> Message-ID: <1115088435.807539.274020@o13g2000cwo.googlegroups.com> Thanks to both of you. Now that I know the correct terminology for what I want to do, I can detirmine the best way to do it. I am not sure if meta-classing is the simplist solution to this problem, however it can be the most elegant. When I have a final implimintation of this project it will be posted. cheers Tim Henderson From steven.bethard at gmail.com Sun May 15 00:49:18 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sat, 14 May 2005 22:49:18 -0600 Subject: Exception question In-Reply-To: References: Message-ID: Ron Adam wrote: > > Do exceptions that take place get stored in a stack or list someplace? [snip] > I know I can catch the error and store it myself with, > > except Exception, exc: > > or possibly, > > errlist = [] > errlist.append(sys.exc_info()) > > But what I want to know is does the interpreter do that in any way? And > if so, can I access it? No, but there's been some recent talk about having it do so: http://mail.python.org/pipermail/python-dev/2005-May/053672.html If that happens though, it's not likely to show up before Python 3.0. Too backwards incompatible to do now. It also seems that the exact semantics haven't yet been agreed upon. STeVe From jrastrick at student.usyd.edu.au Thu May 5 12:59:53 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 5 May 2005 09:59:53 -0700 Subject: dictionary comparison In-Reply-To: <1115306371.818120.150340@f14g2000cwb.googlegroups.com> References: <1115306371.818120.150340@f14g2000cwb.googlegroups.com> Message-ID: <1115312393.514506.77600@z14g2000cwz.googlegroups.com> rickle wrote: > I'm trying to compare sun patch levels on a server to those of what sun > is recommending. For those that aren't familiar with sun patch > numbering here is a quick run down. > > A patch number shows up like this: > 113680-03 > ^^^^^^ ^^ > patch# revision > > What I want to do is make a list. I want to show what server x has > versus what sun recommends, and if the patch exists, but the revision > is different, I want to show that difference. > > Here are some sample patches that sun recommends: > 117000-05 > 116272-03 > 116276-01 > 116278-01 > 116378-02 > 116455-01 > 116602-01 > 116606-01 > > Here are some sample patches that server x has: > 117000-01 > 116272-02 > 116272-01 > 116602-02 > > So there are some that are the same, some that sun recommends that > server x doesn't have, and some where the patch is the same but the > revision is different. > > I've thrown the data into dictionaries, but I just can't seem to figure > out how I should actually compare the data and present it. Here's what > I have so far (the split is in place because there is actually a lot > more data in the file, so I split it out so I just get the patch number > and revision). So I end up with (for example) 116272-01, then split so > field[0] is 116272 and field[1] is 01. > > def sun(): > sun = open('sun-patchlist', 'r') > for s in sun: > sun_fields = s.split(None, 7) > for sun_field in sun_fields: > sun_field = sun_field.strip() > sun_patch = {} > sun_patch['number'] = sun_fields[0] > sun_patch['rev'] = sun_fields[1] > print sun_patch['number'], sun_patch['rev'] > sun.close() > > def serverx(): > serverx = open('serverx-patchlist', 'r') > for p in serverx: > serverx_fields = p.split(None, 7) > for serverx_field in serverx_fields: > serverx_field = serverx_field.strip() > serverx_patch = {} > serverx_patch['number'] = serverx_fields[0] > serverx_patch['rev'] = serverx_fields[1] > print serverx_patch['number'], serverx_patch['rev'] > serverx.close() > > if __name__=='__main__': > sun() > serverx() > > > Right now I'm just printing the data, just to be sure that each > dictionary contains the correct data, which it does. But now I need > the comparison and I just can't seem to figure it out. I could > probably write this in perl or a shell script, but I'm trying really > hard to force myself to learn Python so I want this to be a python > script, created with only built-in modules. > > Any help would be greatly appreciated, > Rick Well, it seems that what youre asking is more of a generic programming question than anything specific to Python - if you can think of how you'd solve this in Perl, for example, then a Python solution along the same lines would work just as well. I'm not sure if there was some specific issue with Python that was confusing you - if so, perhaps you could state it more explicitly. To address the problem itself, there are a few things about your approach in the above code that I find puzzling. First of all, the sun() and servex() functions are identical, except for the name of the file they open. This kind of code duplication is bad practice, in Python, Perl, or any other language (even Shell scripting perhaps, although I wouldn't really know) - you should definitely use a single function that takes a filename as an argument instead. Second, you are creating a new dictionary inside every iteration of the for loop, one for every patch in the file; each dictionary you create contains one patch number and one revision number. This data is printed, and thereafter ignored (and thus will be consumed by Python's Garbage Collector.) Hence youre not actually storing it for later use. I don't know whether this was because you were unsure how to proceed to the comparing the two datasets; however I think what you probably wanted was to have a single dictionary, that keeps track of all the patches in the file. You need to define this outside the for loop; and, if you want to use it outside the body of the function, you'll need to return it. Also, rather than have a dictionary of two values, keyed by strings, I'd suggest a dictionary mapping patch numbers to their corresponding revision numbers is what you want. Once you've got two dictionaries - one for the list for the servers patches, and one for Sun's recommended patches - you can compare the two sets of data by going through the Sun's patches, checking if the server has that patch, and if so, caluclating the difference in revision numbers. So heres a rough idea of how I'd suggest modifying what you've got to get the intended result: def patchlevels(filename): patchfile = open(filename, 'r') patch_dict = {} for line in patchfile: fields = line.split(None, 7) for field in fields: field = field.strip() number = fields[0] rev = fields[1] patch_dict[number] = rev # print number, patch_dict[number] patchfile.close() return patch_dict if __name__=='__main__': sun = patchlevels('sun-patchfile') serverx = patchlevels('serverx-patchfile') print "Sun recommends:\t\t", "Server has:\n" for patch in sun: if patch in serverx: rev = serverx[patch] diff = int(rev) - int(sun[patch]) serverhas = "Revision: %s Difference: %s" % (rev, diff) else: serverhas = "Does not have this patch" print patch, sun[patch], "\t\t", serverhas I've tried to stay as close to your code as possible and not introduce new material, although I have had to use the inbuilt function int to convert the revision numbers from strings to integers in order to subtract one from the other; also, I used C printf-style string formatting on the line after. I hope its reasonably obvious what these things do. For the sample data you gave, this outputs: Sun recommends: Server has: 116276 01 Does not have this patch 116378 02 Does not have this patch 116272 03 Revision: 01 Difference: -2 116278 01 Does not have this patch 116602 01 Revision: 02 Difference: 1 116606 01 Does not have this patch 116455 01 Does not have this patch 117000 05 Revision: 01 Difference: -4 Here negative differences mean the server's version of the patch is out of date, whereas positive differences mean its as recent as Sun's recommendation or better. You could change the nature of the output to whatever your own preference is easily enough. Or, if you want store the data in some other structure like a list for further processing, instead of just printing it, thats also pretty simple to do. This code isn't exactly a work of art, I could have put more effort into a sensible name for the function and variables, made it more 'pythonic' (e.g. by using a list-comprehension in place of the whitespace stripping for loop ), etc; but I think it achieves the desired result, or something close to it, right? Let me know if I was on completely the wrong track. From uval at rz.uni-karlsruhe.de Tue May 17 07:06:03 2005 From: uval at rz.uni-karlsruhe.de (=?ISO-8859-1?Q?Daniel_Sch=FCle?=) Date: Tue, 17 May 2005 13:06:03 +0200 Subject: \r functionality In-Reply-To: <1116325048.303756.222070@z14g2000cwz.googlegroups.com> References: <1116325048.303756.222070@z14g2000cwz.googlegroups.com> Message-ID: Jake wrote: > in c and c++ there is a useful way to refresh an output line in printf > and cout using \r meta command. So for example in the wget application > the progress of the download is updated on the same output line of the > screen. From an intital investigation python seems to lack this. Is > this correct? > >>> print "a\rb" b >>> From mwm at idiom.com Thu May 26 09:14:50 2005 From: mwm at idiom.com (Mike Meyer) Date: 26 May 2005 06:14:50 -0700 Subject: Python Impact Analysis Tool ? References: <1117027674.787033.113730@f14g2000cwb.googlegroups.com> <200505251520.54697.hancock@anansispaceworks.com> <1117111596.183489.201240@o13g2000cwo.googlegroups.com> Message-ID: <5jfywaw2lx.fsf@idiom.com> dcolford2000 at hotmail.com writes: > I am a mainframe designer/progrmmer. What I need is a tool that shows > me at design time what links to what so that I can understand the > application. When a design change comes through I could say OK this > change affects only A, B, and C out of the whole alphanet. Then I would > be able to isolate what needs to be changed and unit tested..I am > trying to improve programmer productivity at design time. Take as look at PyUMLGraph. That should narrow it down to classes. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From apardon at forel.vub.ac.be Tue May 3 09:49:15 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 May 2005 13:49:15 GMT Subject: sorting list and then return the index of the sorted item References: <1115127433.984686.99060@f14g2000cwb.googlegroups.com> Message-ID: Op 2005-05-03, custard_pie schreef : > I need help sorting a list...I just can't figure out how to sort a list > and then return a list with the index of the sorted items in the list > for example if the list I want to sort is [2,3,1,4,5] > I need [2,0,1,3,4] to be returned > Can someone help please.... > Something like this: >>> lst = [2,3,1,4,5] >>> inx = range(len(lst)) >>> inx.sort(lambda x,y: lst[x] - lst[y]) >>> print inx [2, 0, 1, 3, 4] -- Antoon Pardon From dalke at dalkescientific.com Tue May 24 17:13:27 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 24 May 2005 21:13:27 GMT Subject: searching substrings with interpositions References: <1116926253.186047.195260@g43g2000cwa.googlegroups.com> <3fgekjF7lq3qU1@individual.net> <1116939594.958040.14110@z14g2000cwz.googlegroups.com> <3fh2leF7mbtfU1@individual.net> Message-ID: Claudio Grondi wrote: > Note: code below is intended to help to clarify things only, > so that a bunch of examples can be tested. > If you need bugfree production quality code, maybe > someone else can provide it. Still not tested enough to ensure that it's bug free, but more concise. Here's one the implements the algorithm directly and another that uses a regexp. The latter should be the preferred approach. My intent was that the algorithm implements the given pattern so they should given identical results. # Doing the work ourselves def find_spread_substring(query, target, limit = None): stack = [] ti = qi = 0 Nq = len(query) Nt = len(target) delta = 0 while ti < Nt: # We have a match if query[qi] == target[ti]: stack.append( (qi, ti, delta) ) qi = qi + 1 if qi == Nq: return [ti for (qi, ti, delta) in stack] ti = ti + 1 delta = 0 else: # No match while 1: # If we have a partial match, check if we've # gone over the limit. if stack: delta = delta + 1 if limit is not None and delta > limit: # backtrack, treating it as an invalid match # (so retry this 'else:' block) qi, ti, delta = stack.pop() continue # No backtracking needed break # Advance to check the next character in the target ti = ti + 1 # Failure return None # Using regular expressions import re def find_spread_substring2(query, target, limit = None): if limit is None: template = "(%s).*?" else: template = "(%%s).{,%d}?" % (limit,) terms = [template % c for c in query] pattern = "".join(terms) pat = re.compile(pattern) m = pat.search(target) if not m: return None return [m.start(i) for i in range(1, len(query)+1)] def test(): for (q, t, limit, is_valid) in ( ("1010", "10001001", None, True), ("1010", "100011", None, False), ("1010", "100010", 3, True), ("1010", "100010", 1, True), ("1010", "1000010", 1, False), ("1010", "01000010", 2, True), ("1010", "01000010", 1, False), ("1010", "0100000", None, False), ): result = find_spread_substring(q, t, limit) result2 = find_spread_substring2(q, t, limit) if result != result2: raise AssertionError( (result, result2) ) if result is not None: if limit is not None: # check that it's a proper subset for (x, y) in zip(result[:-1], result[1:]): # +1 because 'limit' is the maximum gap size if (y-x) > limit+1: raise AssertionError((q, t, limit, result, x, y)) s = "".join([t[i] for i in result]) if s != q: raise AssertionError((q, t, limit, result, s)) if result is None and not is_valid: pass elif result is not None and is_valid: pass else: raise AssertionError( (q, t, limit, is_valid, result) ) if __name__ == "__main__": test() print "All tests passed." Andrew dalke at dalkescientific.com From tdelaney at avaya.com Tue May 10 19:53:54 2005 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 11 May 2005 09:53:54 +1000 Subject: bad argument type for built-in operation Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE025204FF@au3010avexu1.global.avaya.com> Florian Lindner wrote: > Traceback (most recent call last): > File "visualizer.py", line 8, in ? > main() > File "visualizer.py", line 5, in main > g = GraphCreator(f) > File "/home/florian/visualizer/GraphCreator.py", line 13, in > __init__ self.conf = ConfigReader(config) > File "/home/florian/visualizer/ConfigReader.py", line 53, in > __init__ graph.sourceReader = CSVReader(filename, firstline, > delimiter) File "/home/florian/visualizer/ConfigReader.py", line > 13, in __init__ self.reader = csv.reader(f, delimiter=Adelimiter) > TypeError: bad argument type for built-in operation > > f ist file object, Adelimiter is ",". > > What is wrong there? Lack of code. I'd start looking very carefully as to whether `f` really is a file object. Tim Delaney From iv at lantic.net Mon May 16 12:00:36 2005 From: iv at lantic.net (Iwan Vosloo) Date: 16 May 2005 09:00:36 -0700 Subject: Structuring larger applications - ideas In-Reply-To: References: <1116255787.625276.221670@g14g2000cwa.googlegroups.com> Message-ID: <1116259236.861818.127170@g14g2000cwa.googlegroups.com> I know my foreign (to python) one class per module idea is what makes life more difficult for me here. And there is an argument to be made out that it is a stupid remnant I stick to from having used it in other programming languages (do I have to admit C++ in my background?) Two small examples of where it it useful for me: my development environment is run by make to a large extent. Many standard UNIX tools have the intelligence to deal with filenames, and if you know a file corresponds to a class, you have a lot more info available in your makefile. Also, if I use my version control software (currently gnu arch) to see what's changed, for example, I get a list of changes files which again gives me more info because I know a file corresponds to a class. So, I can do a number of such small things using that convention that works well with standard old UNIX tools. And I find that valuable. As for the dependencies- I'm trying to keep the specification of them simple. From a design point of view, it makes sense to me to only specify ONCE that largeish-collection-of-classes-A depends on largeish-collection-of-classes-B. As another simple small example: say I change the name of large-collection-of-classes-B - this way I only need to do it once, else I need to grep and sed all over in order to do it. It just feels cleaner and easier. I know essentially, if you stick to having many classes in a python module, you have what I referred to in the previous paragraph, because you can stick to importing other modules at the beginning of a module and so have them and their contens available in the entire file. Still, I'm investigating whether I can bend the ever-so-flexible python to work well with my admittedly somewhat strange requirement. And, off course, I'd like to hear what others think. -i From martin.witte at gmail.com Sat May 7 11:12:34 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 7 May 2005 08:12:34 -0700 Subject: globbing multiple wildcards In-Reply-To: <1115477662.937084.260270@g14g2000cwa.googlegroups.com> References: <1115477662.937084.260270@g14g2000cwa.googlegroups.com> Message-ID: <1115478754.735902.54390@z14g2000cwz.googlegroups.com> what about : martin at ubuntu:~$ python Python 2.4.1 (#2, Mar 30 2005, 21:51:10) [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import glob >>> print glob.glob('/home/*/.mozilla/*/*/Cache*/*') ['/home/martin/.mozilla/firefox/dem8d5eu.default/Cache/_CACHE_MAP_', '/home/martin/.mozilla/firefox/dem8d5eu.default/Cache/_CACHE_001_', ......... '/home/martin/.mozilla/firefox/dem8d5eu.default/Cache/66FA72F2d01', '/home/martin/.mozilla/firefox/dem8d5eu.default/Cache/85F82253d01', '/home/martin/.mozilla/firefox/dem8d5eu.default/Cache/CE3B4D9Cd01'] >>> From rrr at ronadam.com Tue May 17 16:03:27 2005 From: rrr at ronadam.com (Ron Adam) Date: Tue, 17 May 2005 20:03:27 GMT Subject: Quick Reference from module doc strings. In-Reply-To: <1116349136.477233.205260@z14g2000cwz.googlegroups.com> References: <1116199904.205240.58300@g49g2000cwa.googlegroups.com> <42880d98$1@nntp0.pdx.net> <1116320306.737808.313530@g44g2000cwa.googlegroups.com> <1116349136.477233.205260@z14g2000cwz.googlegroups.com> Message-ID: Michele Simionato wrote: > Ron Adam: > > >>Sound great! Adding a command line parser, I'm going to add a brief ^---------------------------^ That part should have been deleted, I meant your whole program sounded good, not just that part. :-) >>command line parser to it today, but nothing as elaborate as you have >>already. Could you post a part of the output as an example? How is > > the > >>index built? > > > For the command line parser, see > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844 I got this one covered, just haven't done it yet. ;-) > Here is an example of output: > > http://www.phyast.pitt.edu/~micheles/python/ms.html > > (it is a package called "ms" (as "My Stuff") where I put my utilities). Good idea, I think I'll follow your lead. Currently my file are not too organized. > The system works for module of the standard library too, but since > most of the time they do not have docstrings in reST format, there > are ugly formatting errors. But this is a bug of the standard library, > not of my tool ;) Thats part of what I'm trying to resolve, the doc strings a lot of time isn't enough by itself or is missing. So I'm trying to build up a complete enough record so if there is no doc string, at least some sense of what it is can be figured out without a lot browsing or looking at the source code. Then to enable different searches by subject and keywords on these instead of by package or module. > For the index: "minidoc" associates a footnote number to every name, > and then > prints the names in alphabetical order. You can reach the documentation > for that name with a click. > > Michele Simionato That's a nice format. It took me a while before I realized the whole page *is* the output and not a part of it as I expected. Did you use the inspect module to get the class/function name and args? BTW, I presume you're aware that the "source links" on the web page link to your computer and not to a file on the web site. Just letting know in case it was an over site. Cheers, _Ron Ps... I like your physics link page. :) From tim.golden at viacom-outdoor.co.uk Tue May 17 04:18:33 2005 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue, 17 May 2005 09:18:33 +0100 Subject: Problem listing services with wmi Message-ID: <9A28C052FF32734DACB0A288A3533991EBB816@vogbs009.gb.vo.local> [Jean-S?bastien Guay] [... snip Larry Bates' suggestion of removing whitespace ...] | Out of curiosity, is there any reason why whitespace between | the method | name and parameter list parentheses isn't good? Because the code I | posted before was copy-pasted from Tim Golden's site | (http://tgolden.sc.sabren.com/python/wmi.html) and the spaces | were there. It's just a matter of style. Whitespace isn't *that* significance in Python! I personally -- in whatever language -- put spaces between function names and their first parameter. Guido vR, as someone else has pointed out, prefers not to. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From fredrik at pythonware.com Sat May 28 10:17:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 28 May 2005 16:17:21 +0200 Subject: CVS interface module References: <1117288852.725521.239660@o13g2000cwo.googlegroups.com> Message-ID: "Jim" wrote: > Inside of a Python script I need to work a CVS archive. Nothing fancy, > but I need to update the local tree, change or add some files from time > to time, and commit. Naturally I looked for a module that would allow > me to easily see if there were conflicts, the server is down, etc. > > I've looked in this group, Googled around, etc., but I've not found > anything. have you seen http://pycvs.sourceforge.net/ ? (on the other hand, if it's your own archive, you might wish to switch to a more modern CVS-style system, http://subversion.tigris.org, which has a native Python API) From bokr at oz.net Wed May 4 12:12:01 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 04 May 2005 16:12:01 GMT Subject: xmlrpclib and decoding entity references References: <1115132826.795008.320190@z14g2000cwz.googlegroups.com> Message-ID: <4278e9a2.656401605@news.oz.net> On 3 May 2005 08:07:06 -0700, "Chris Curvey" wrote: >I'm writing an XMLRPC server, which is receiving a request (from a >non-Python client) that looks like this (formatted for legibility): > > > >echo > > > >Le Martyre de Saint André <BR> avec inscription >'Le Dominiquain.' et 'Le tableau fait par le dominicain, >d'après son dessein à... est à Rome, à >l'église Saint André della Valle' sur le >cadre<BR> craie noire, plume et encre brune, lavis brun >rehaussé de blanc sur papier brun<BR> 190 x 228 mm. (7 1/2 x >9 in.) > > > > > >But when my "echo" method is invoked, the value of the string is: > >Le Martyre de Saint Andr;
avec inscription 'Le Dominiquain.' et >'Le tableau fait par le dominicain, d'apr:s son dessein 2... est 2 >Rome, 2 l';glise Saint Andr; della Valle' sur le cadre
craie noire, >plume et encre brune, lavis brun rehauss; de blanc sur papier brun
>190 x 228 mm. (7 1/2 x 9 in.) > >Can anyone give me a lead on how to convert the entity references into >something that will make it through to my method call? > I haven't used XMLRPC but superficially this looks like a quoting and/or encoding problem. IOW, your "request" is XML, and the ... part is also XML which is part of the whole, not encapsulated in e.g. (which would tell an XML parser to suspend markup interpretation of ...stuff...). So IWT you would at least need the ... content to be converted to unicode to preserve all the represented characters. It wouldn't surprise me if the whole request is routinely converted to unicode, and the "value" you are showing above is a result of converting from unicode to an encoding that can't represent everything, and maybe just drops conversion errors. What do you get if you print repr(value)? (assuming value is passed to you echo method) If it is a unicode string, you will just have to choose an appropriate value.encode('appropriate') from available codecs. If it looks like e.g., a utf-8 encoding of unicode, you could try value.decode('utf-8').encode('appropriate') I'm just guessing here. But something is interpreting the basic XML, since <BR> is being converted to
. Seems not unlikely that the rest are also being converted, and to unicode. You just wouldn't notice a glitch when unicode
is converted to any usual western text encoding. OTOH, if the intent (which I doubt) of the non-python client were to pass through a block of pre-formatted XML as such (possibly for direct pasting into e.g. web page XHTML?) then a way to avoid escaping every & and < would be to use CDATA to encapsulate it. That would have to be fixed on that end. Regards, Bengt Richter From fredrik at pythonware.com Thu May 5 15:30:13 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 5 May 2005 21:30:13 +0200 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com><1115315863.050413.275390@g14g2000cwa.googlegroups.com> <1115317222.685180.62020@z14g2000cwz.googlegroups.com> Message-ID: "mrstephengross" wrote: > >But, assuming you have your numbers as strings, I would suggest > looking > at str.split() and len(). > > Well, the numbers are in fact stored as numbers, so string processing > won't work. if they're not strings, your question is meaningless. as others have pointed out, the exact internal representation for 0.103 is more like 0.10299999999999999433786257441170164383947849273681640625 which has a lot more than 3 digits... > >I'd give you an example, but this sounds kinda like a homework > assignment. > > The task may sound like it comes from class, but I can assure you that > I am indeed a professional developer. well professional or not, you clearly need to refresh your floating point skills. I suggest reading the following documents before proceeding: http://docs.python.org/tut/node16.html http://www.lahey.com/float.htm From pajo at pajo.com Wed May 18 04:14:16 2005 From: pajo at pajo.com (Pajo) Date: Wed, 18 May 2005 10:14:16 +0200 Subject: How to learn OO of python? In-Reply-To: <1116402543.485651.8300@g44g2000cwa.googlegroups.com> References: <1116402543.485651.8300@g44g2000cwa.googlegroups.com> Message-ID: Here's the link for download: http://ibiblio.org/obp/thinkCS/python.php Bloke wrote: > The best one I found was Dive Into Python - and it's free > > http://www.diveintopython.org/ > > Also, How to Think Like a computer scientist - can't remember the link. > > Bloke > From prabapython at yahoo.co.in Fri May 6 04:19:14 2005 From: prabapython at yahoo.co.in (praba kar) Date: Fri, 6 May 2005 09:19:14 +0100 (BST) Subject: RFC 2822 format date printing function in python In-Reply-To: 6667 Message-ID: <20050506081914.42197.qmail@web8408.mail.in.yahoo.com> Dear All, In Php we can print RFC 2822 formatted date by date('r') with parameter r. Then it will print the below format date. "Thu, 7 Apr 2005 01:46:36 -0300". I want to print same RFC 2822 format in python. Is it possible in python? . If possible kindly mention the function related to print RFC format date regards, Prabahar ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From bokr at oz.net Sat May 14 17:06:35 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 14 May 2005 21:06:35 GMT Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116092670.420301.196570@o13g2000cwo.googlegroups.com> Message-ID: <428660c2.174663152@news.oz.net> On 14 May 2005 10:44:30 -0700, "M.E.Farmer" wrote: [...] >Be sure to study up on namespaces, it will ease your Python woes. >Namespaces are the most fundamental part of Python that new users don't >understand. Namespace mastery will take you far. >Just remember there are only two scopes local and global ;) And don't jump to conclusions when you read a line like the last above ;-) I.e., there can be many different local and global scopes, not just one of each, and since Python is a very dynamic language, existence of things can vary with execution time and logic, so those scopes don't all have to exist at the same time, or at all, nor persist until the program runs to its end. Also, ISTM "local" is probably being stretched a little above to include nested scopes, which are a bit different from either plain local or global in how you can access them. I would second the advice to explore namespaces, and particularly attribute name spaces such as are defined by classes. Attribute access and descriptors conspire to enable much of the magic you can cook up with Python, as well as stuff that happens automatically. In short, a whole unopened deluxe set of programming Legos is at your elbow, besides the pieces you have encountered so far. Have fun ;-) Regards, Bengt Richter From thorj at ibas.no Mon May 23 16:26:06 2005 From: thorj at ibas.no (Thor Arne Johansen) Date: Mon, 23 May 2005 22:26:06 +0200 Subject: Access lotus notes using Python In-Reply-To: References: Message-ID: Sateesh wrote: > Hi, > Is it possible to access Lotus notes using Python? Can anyone provide me > some pointers? > > Thanks > Sateesh > > NotesSQL is an ODBC driver for Notes. Using NotesSQL and a python odbc connection you can use the standard python db-api2 to access tables. (Examples of odbc connection: mxODBC or the odbc provided by win32all) HTH, Thor Arne Johansen Technical Director Ibas AS From michele.simionato at gmail.com Mon May 16 11:05:11 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 16 May 2005 08:05:11 -0700 Subject: decorator module Message-ID: I have written a decorator module to make easier to write good decorators (i.e. decorators preserving the signature of the functions they decorate). The documentations contains a (hopefully) nice collections of use cases (which are also test cases, sice I take doctest very seriously ;). You can find it here: http://www.phyast.pitt.edu/~micheles/python/decorator.zip It is released under the Python licence. Let me know if you are using it and if you would like further additions/improvements/changes/etc. Feeback is welcome! Michele Simionato From jwaixs at gmail.com Mon May 23 13:41:44 2005 From: jwaixs at gmail.com (Noud Aldenhoven) Date: Mon, 23 May 2005 19:41:44 +0200 Subject: blabla Message-ID: Python rulz and sorry for this spam... From tjreedy at udel.edu Sat May 14 01:29:33 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 May 2005 01:29:33 -0400 Subject: 80 bit precision ? References: <20050514003732.GA4225@mrna.tn.nic.in> Message-ID: "km" wrote in message news:20050514003732.GA4225 at mrna.tn.nic.in... > Hi all, > > does python currently support 80 bit precision Floating Point Unit ? Last I read, in CPython, the float type encapsulates a C double. So, does any C compiler implements doubles as 80 bit floats? Or, if it has 64 bit doubles and 80 bit long doubles, are the latter transparently substitutible for the former, so that you could change Python's float declaration and have everything work as expected? (I an not sure of either.) Terry J. Reedy From dieter at handshake.de Tue May 24 16:43:20 2005 From: dieter at handshake.de (Dieter Maurer) Date: 24 May 2005 22:43:20 +0200 Subject: python24.zip References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> <428faddd$0$26322$9b622d9e@news.freenet.de> <4290dc79$0$9989$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" writes on Sun, 22 May 2005 21:24:41 +0200: > ... > What do you mean, "unable to"? It just doesn't. The original question was: "why does Python put non-existing entries on 'sys.path'". Your answer seems to be: "it just does not do it -- but it might be changed if someone does the work". This fine with me. > ... > In the past, there was a silent guarantee that you could add > items to sys.path, and only later create the directories behind > these items. I don't know whether people rely on this guarantee. I do not argue that Python should prevent adding non-existing items on "path". This would not work as Python may not know what "existing" means (due to "path_hooks"). I only argue that it should not *itself* (automatically) put items on path where it knows the responsible importers and knows (or can easily determine) that they are non existing for them. > ... > > The application was Zope importing about 2.500 modules > > from 2 zip files "zope.zip" and "python24.zip". > > This resulted in about 12.500 opens -- about 4 times more > > than would be expected -- about 10.000 of them failing opens. > > I see. Out of curiosity: how much startup time was saved > when sys.path was explicitly stripped to only contain these > two zip files? I cannot tell you precisely because it is very time consuming to analyse cold start timing behavior (it requires a reboot for each measurement). We essentially have the following numbers only: warm start cold start (filled OS caches) (empty OS caches) from file system 5s 13s from ZIP archives 4s 8s frozen 3s 5s The ZIP archive time was measured after a patch to "import.c" that prevents Python to view a ZIP archive member as a directory when it cannot find the currently looked for module (of course, this lookup fails also when the archive member is viewed as a directory). Furthermore, all C-extensions were loaded via a "meta_path" hook (and not "sys.path") and "sys.path" contained just the two Zip archives. These optimizations led to about 3.000 opens (down from originally 12.500). > I would expect that importing 2500 modules takes *way* > more time than doing 10.000 failed opens. You may be wrong: searching for non existing files may cause disk io which is several orders of magnitude slower that CPU activities. The comparison between warm start (few disc io) and cold start (much disc io) tells you that the import process is highly io dominated (for cold starts). I know that this does not prove that the failing opens contribute significantly. However, a colleague reported that the "import.c" patch (essential for the reduction of the number of opens) resulted in significant (but not specified) improvements. Dieter From flamesrock at gmail.com Tue May 31 18:11:53 2005 From: flamesrock at gmail.com (flamesrock) Date: 31 May 2005 15:11:53 -0700 Subject: convert a string to tuple In-Reply-To: <09mdnZZHwb73QAHfRVn-sQ@powergate.ca> References: <1117570449.887422.225670@g43g2000cwa.googlegroups.com> <1117572374.910751.5400@f14g2000cwb.googlegroups.com> <09mdnZZHwb73QAHfRVn-sQ@powergate.ca> Message-ID: <1117577513.609930.62320@o13g2000cwo.googlegroups.com> lol From bdesth.quelquechose at free.quelquepart.fr Wed May 4 18:34:24 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Thu, 05 May 2005 00:34:24 +0200 Subject: About Encapsulation In-Reply-To: References: Message-ID: <42794957$0$282$636a15ce@news.free.fr> Adriano Monteiro a ?crit : > Hey folks, > > I wanna know more about encapsulation in python. Is it fully suported? > How can I define the encapsulation statements for methods and attributes? If you're thinking of things like private/protected/public: class Foo(object): def __init__(self): self.public = 'this is the API' self._protected = 'implementation detail' self.__private = 'keep out' BTW, you may want to have a look at this: http://c2.com/cgi/wiki?EncapsulationIsNotInformationHiding From sjmachin at lexicon.net Sun May 29 01:24:26 2005 From: sjmachin at lexicon.net (John Machin) Date: Sun, 29 May 2005 15:24:26 +1000 Subject: How do i read just the last line of a text file? In-Reply-To: <1117341766.166081.132240@o13g2000cwo.googlegroups.com> References: <1117341766.166081.132240@o13g2000cwo.googlegroups.com> Message-ID: <4299520b@news.eftel.com> nephish wrote: > Hey there. > i want to set a variable to represent the last line of a text file > how do i do that? > or even better, how do i create a list of the lines of a text file? > Hey there to you too. According to the manual http://www.python.org/doc/2.4.1/lib/bltin-file-objects.html readlines([sizehint]) Read until EOF using readline() and return a list containing the lines thus read. Which part of this don't you understand? From steven.bethard at gmail.com Wed May 25 06:51:59 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 May 2005 04:51:59 -0600 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 24) In-Reply-To: References: Message-ID: <5NKdnevP2exSxQnfRVn-hA@comcast.com> Simon Brunning wrote: > On 5/24/05, Cameron Laird wrote: >> General principle: if in doubt about the significance of an item in >> "Python-URL!", assume that it's intended in a constructive way. > > I find that if you make the same assumption about c.l.py in general, > you are seldom wrong. +1 QOTW. ;) STeVe From chris at angband.org Wed May 4 07:13:09 2005 From: chris at angband.org (Operation Latte Thunder) Date: Wed, 4 May 2005 11:13:09 +0000 (UTC) Subject: twisted jabber and xmlstream References: Message-ID: Sylvain Thenault wrote: > you can find some examples in our fatima project, a jabber bot testing > client, available at http://www.logilab.org/projects/fatima/0.1 > You'll find a jabber.py module in the distribution containing jabber > related code. > > hope that helps thanks, I'll check it out! -- chris at acheris.net | Roma Invicta! From max.derkachev at gmail.com Thu May 5 05:50:02 2005 From: max.derkachev at gmail.com (Max Derkachev) Date: 5 May 2005 02:50:02 -0700 Subject: Adding new methods to new-style classes dynamically In-Reply-To: <1115284225.644287.140090@o13g2000cwo.googlegroups.com> References: <1115282109.707219.163660@f14g2000cwb.googlegroups.com> <1115284225.644287.140090@o13g2000cwo.googlegroups.com> Message-ID: <1115286602.145867.123350@o13g2000cwo.googlegroups.com> John Machin wrote: > >>> A.foo > 123 Oh, I've been a little dumb to forget about it :) Thanks. Max. From roy at panix.com Sun May 8 20:48:06 2005 From: roy at panix.com (Roy Smith) Date: Sun, 08 May 2005 20:48:06 -0400 Subject: __brace__ (PEP?) References: Message-ID: In article , James Stroud wrote: > On Sunday 08 May 2005 05:15 pm, Roy Smith wrote: > > This seems like a pretty esoteric operation to devote a bit of syntax to. > > It doesn't seem like something people want to do very often. > > Similar to __call__, I don't think that this syntax would be neccessarily > devoted to any particular operation. I'm simply offering cross-sectioning as > a potential and intuitive operation that would benefit from a shortcut. The > main point is that using braces after a name is not defined right now and I > think that they could be put to good use. > > James One of the nice things about Python is that the syntax is relatively simple, and words are generally favored over punctuation. There's lots of punctuation which is not currently used, but that doesn't mean it's a good idea to go off inventing meanings for it. I supposed we could have: foo->bar ==> foo.__arrrow__(bar) foo$bar ==> foo.__dollar__(bar) foo#bar ==> foo.__hash__(bar) foo::bar ==> foo.__scope__(bar) and so on down the list of non-alphanumeric characters, but the result wouldn't be anything most of us would recognize as Python. From __peter__ at web.de Sun May 1 02:51:15 2005 From: __peter__ at web.de (Peter Otten) Date: Sun, 01 May 2005 08:51:15 +0200 Subject: Tkinter weirdness item count References: Message-ID: phil wrote: > def __del__(s): > line.count?=?line.count?-?1 > > ##?delete?the?line?object?if?the > ##?class?instance?is?deleted > s.glob.can.delete(s.obj) > > > After the rotation I check line.count and it is 3 Did you know that exceptions are ignored in the __del__() method? One way to verify that your __del__() runs to completion would be to make the line.count decrement the last statement, and check the total line.count after the rotation again. Generally speaking the __del__() method is not the most robust cleanup mechanism. Maybe you can add a line.delete() method and change your program flow for it to be called explicitly when the line should no longer be visible. Peter From ajikoe at gmail.com Tue May 31 08:26:26 2005 From: ajikoe at gmail.com (ajikoe at gmail.com) Date: 31 May 2005 05:26:26 -0700 Subject: exit after process exit Message-ID: <1117542386.379343.215340@g47g2000cwa.googlegroups.com> Hello, I would like to run a python process and wait until the process exit. How can I do it? For example I would like to run a.exe. and wait until a.exe exit. Sincerely Yours, Pujo From sjmachin at lexicon.net Sun May 1 05:18:25 2005 From: sjmachin at lexicon.net (John Machin) Date: Sun, 01 May 2005 19:18:25 +1000 Subject: Best way to parse file into db-type layout? References: <7v1371pn9gvsh52m7nld6ddjm9b9k3elgf@4ax.com> <391871t746ng3pgjlm8dv801qjd5cg9qem@4ax.com> Message-ID: On Sat, 30 Apr 2005 23:11:48 -0400, Steve Holden wrote: >John Machin wrote: >> If the job at hand is simulating awk's file reading habits, yes then >> fileinput is convenient. However if the job at hand involves anything >> like real-world commercial data processing requirements then fileinput >> is NOT convenient. >> >Yet again, get real. If someone tells me that fileinput meets their >requirements who am I (not to mention who are *you*) to say they should >invest extra effort in solving their problem some other way? Michael Hoffmann has said that it meets his simple requirements. He doesn't use its filelineno() and nextfile(), and says he wouldn't use it if he needed that sort of functionality. I have no argument with that. If I genuinely thought that fileinput (or any other piece of software) would not meet somebody's requirements i.e. would not solve their problem, then what should I do? Unless bound by blood ties or contractual obligations should I keep silent? In any case, who are *you* to suggest I shouldn't express an opinion? Back to fileinput: it complicates things when you want to do something less simple, like some action at the end of each file -- you have to poll for the first line of the next file, which means that the end-of-each-file code has to be repeated at the end of all files. Further, you don't get to see empty files. Hence the examples: > >> Example 1: Requirement is, for each input file, to display name of >> file, number of records, and some data totals. >> >> Example 2: Requirement is, if end of file occurs when not expected >> (including, but not restricted to, the case of zero records) display >> an error message and terminate abnormally. >> >Possibly these examples would have some force if they weren't simply >invented. The only "invention" was *simplification* of genuine real-world requirements. Many entities receive periodically, often daily, remittances from other entities with whom they do business. In parallel to the remittance being paid into the recipient's bank account, there is sent a file containing details of the breakdown of the total money amount. At the end of the file there is a trailer record which is mandated to contain the number of detail records and the total amount of money. Checking the contents of the trailer record against (a) the bank account and (b) calculated totals from the detail records is a real requirement. So is ringing the alarm bells if end of file is detected before the trailer record is detected (or there is any other evidence that the file is defective). How could you possibly imagine that these are "simply invented"? Perhaps we should just agree that we have differing perceptions of reality, and move on. Cheers, John From flamesrock at gmail.com Mon May 30 20:19:12 2005 From: flamesrock at gmail.com (flamesrock) Date: 30 May 2005 17:19:12 -0700 Subject: how to prepend string to a string? Message-ID: <1117498752.591304.42280@g44g2000cwa.googlegroups.com> so I know you can append a string. But how do you *prepend* a string, as shown in the following code #dirList = ['depth1','depth2','depth3'] #string = """position""" #for x in len(dirList): # string += '>> %s'%dirList.pop() #(????????????) # to return position>> depth1 >> depth2 >> depth3 rather than position>> depth3 >> depth2 >> depth1 I really hope this feature exists =) -thanks From mogmios at mlug.missouri.edu Fri May 13 04:10:16 2005 From: mogmios at mlug.missouri.edu (Michael) Date: Fri, 13 May 2005 01:10:16 -0700 Subject: mod_python seg faults with xml Message-ID: <428460E8.1050006@mlug.missouri.edu> Trying to process xml (xml-rpx) with a handler in mod_python crashes mod_python. Previous versions worked fine. Only change is I recompiled with newest versions of Apache, Python, and mod_python. No PHP or anything like that involved. Any idea why it seg faults when I try to import xmlrpclib and similar modules? Thanks. -- Michael http://kavlon.org From phillip.watts at anvilcom.com Mon May 30 14:24:05 2005 From: phillip.watts at anvilcom.com (phil) Date: Mon, 30 May 2005 13:24:05 -0500 Subject: Unicode Congruence Message-ID: <429B5A45.6040001@anvilcom.com> I can't find, anyone know the unicode symbol CONGRUENT. either tilde over equal or triple tidde would do. Thanks. From cpu.crazy at gmail.com Wed May 18 09:32:31 2005 From: cpu.crazy at gmail.com (CPUFreak91) Date: 18 May 2005 06:32:31 -0700 Subject: Looking for bored python newbies Message-ID: <1116423151.573145.57920@f14g2000cwb.googlegroups.com> Are you a newbie to python? Are you bored? Does everybody else's cool projects seem to complex for you? I still pretty newbie myself and I feel like that. How about we newbies start a simple project of our own? From onfrek at yahoo.com Sun May 29 15:49:09 2005 From: onfrek at yahoo.com (Michael Onfrek) Date: 29 May 2005 12:49:09 -0700 Subject: How to restrict lenght of entry widget to certain number of character Message-ID: <1117396149.334908.238580@g14g2000cwa.googlegroups.com> Hi! I'm playing with entry again and trying to restrict length of entry widget to certain number of character, so users cannot enter more character into it. Any ideas? Reg. Michael Onfrek From dcrespo at gmail.com Mon May 2 11:21:48 2005 From: dcrespo at gmail.com (dcrespo) Date: 2 May 2005 08:21:48 -0700 Subject: Which IDE is recommended? In-Reply-To: References: <426f90ac$1_2@rain.i-cable.com> <9f7v619jhigbtoksslnr88f4idoc6ejvu3@4ax.com> <1115039282.069052.287920@o13g2000cwo.googlegroups.com> Message-ID: <1115047308.550787.132130@f14g2000cwb.googlegroups.com> Hi. You were right: I meant "Code Completition". I did what you told me to do. I get now auto completition of code. For example: import wx wx.(here appear a list with the possibilities) But.... (there's always a "but") with: button = wx.Button(...) when I write "button." there's a flick of the list of the possible parameters, resulting in no showing it. Is there a way to correct it? Daniel From dcrespo at gmail.com Fri May 6 09:25:04 2005 From: dcrespo at gmail.com (dcrespo) Date: 6 May 2005 06:25:04 -0700 Subject: Python & SQLite In-Reply-To: References: <1115131256.058058.139980@o13g2000cwo.googlegroups.com> Message-ID: <1115385904.297397.266190@g14g2000cwa.googlegroups.com> > There are specific python modules for SQLite on Linux. Which? I thought pysqlite works on Linux. My important question is: If I develop an app using Python-wxPython-PySQLite under Windows, and run it on Linux, it should work, ?right? Daniel From irmen.NOSPAM at xs4all.nl Fri May 27 17:35:24 2005 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Fri, 27 May 2005 23:35:24 +0200 Subject: [ANN] XPN 0.4.6 In-Reply-To: <20050527210213.3341.45078.XPN@orion.homeinvalid> References: <20050527210213.3341.45078.XPN@orion.homeinvalid> Message-ID: <4297929b$0$150$e4fe514c@news.xs4all.nl> Nemesis wrote: > XPN (X Python Newsreader XPN) is a multi-platform newsreader with > Unicode support. It has features like scoring/actions, X-Face and Face > decoding, muting of quoted text, newsrc import/export, find article and > search in the body, spoiler char/rot13, random taglines, and > configurable attribution lines. Wow, nice work! I'm using Thunderbird and am very happy with that, but looking quickly at your website it seems that XPN is a very nice application. Will it work on windows? It's not immediately clear to me... --Irmen From cfbolz at gmx.de Tue May 31 20:23:29 2005 From: cfbolz at gmx.de (Carl Friedrich Bolz) Date: Wed, 01 Jun 2005 02:23:29 +0200 Subject: The need to put "self" in every method In-Reply-To: <429CE8F4.5070301@lexicon.net> References: <1117554344.938440.54700@g14g2000cwa.googlegroups.com> <429CE8F4.5070301@lexicon.net> Message-ID: <429D0001.5050400@gmx.de> John Machin wrote: >>Of course, if you *don't* use 'self', you should expect an angly mob >>with pitchforks and torches outside your castle. >> > > Wouldn't an angly mob be carrying fishing rods? > Well, I thought they would be carrying pitchfolks and tolches. From deetsNOSPAM at web.de Mon May 2 07:33:13 2005 From: deetsNOSPAM at web.de (Diez B. Roggisch) Date: Mon, 02 May 2005 13:33:13 +0200 Subject: Is python support jxta now? References: <42760108$1_2@rain.i-cable.com> Message-ID: monkey wrote: > Hi all, just read from the jxta.org that a python implemention of jxta > framework is being developed. But its project page doesn't state whether > it can be use now.. > > I am interested to learn to develop p2p app, that's why I am studying > python now. Or there is any lib in python that already implement a p2p > protocol? Please insight me, thanks a lot ( : Bittorrent, one of the most actively used p2p protocols is _written_ in python. -- Regards, Diez B. Roggisch From alexs at advfn.com Mon May 23 15:24:35 2005 From: alexs at advfn.com (Alex Stapleton) Date: Mon, 23 May 2005 20:24:35 +0100 Subject: ANNOUNCE: twill v0.7, scriptable Web testing In-Reply-To: References: Message-ID: <078A7C70-0E14-4567-A7BE-DB34D6AA98E1@advfn.com> This is exactly the sort of thing ive been trying to avoid implementing my self for ages :) I will take it for a spin and see how it behaves, looks great though. On 23 May 2005, at 05:07, C. Titus Brown wrote: > ANNOUNCING twill v0.7. > > twill is a simple Web scripting language built on top of Python and > mechanize. It's designed for automated testing of Web sites, but > it may be useful for anybody who needs to deal with Web sites > (with e.g. logins and cookies) in a non-interactive manner. > > twill is a reimplementation of Cory Dodt's PBP. > > A twill script looks like this: > > # go to the /. login page > go http://slashdot.org/login.pl > > # fill in the form > fv 1 unickname test > fv 1 upasswd test > submit > > # ok, there's no such account ;). show error HTML. > show > > --- > > This is the first public release of twill, version 0.7. > > (Tagline: "It seems usable to me, but then I'm its author.") > > With this release, I'm looking for general feedback on usability, as > well as suggestions on additional use cases. > > Download directly here: > > http://darcs.idyll.org/~t/projects/twill-0.7.tar.gz > > Documentation is online at > > http://www.idyll.org/~t/www-tools/twill.html > > --- > > Miscellaneous details: > > twill is implemented in Python and uses pyparsing and mechanize. In > addition to the existing simple command language, twill can easily be > extended with Python. twill also provides a fairly simple and > well-documented wrapper around mechanize. > > twill scripts can be recorded with maxq, although scripts may require > some hand tweaking at the moment. See the twill documentation for > more information. > > twill does not understand JavaScript, I'm sorry to say. > > --titus, titus at caltech.edu > -- > http://mail.python.org/mailman/listinfo/python-list > > From steven.bethard at gmail.com Tue May 31 01:20:22 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 30 May 2005 23:20:22 -0600 Subject: finding indices in a sequence of parentheses In-Reply-To: <1117423019.327925.268370@g49g2000cwa.googlegroups.com> References: <1117423019.327925.268370@g49g2000cwa.googlegroups.com> Message-ID: Raymond Hettinger wrote: > [Steven Bethard] > >>>I have a list of strings that looks something like: >>>lst = ['0', '0', '(*)', 'O', '(*', '*', '(*', '*))', '((*', '*)', '*)'] > > . . . > >>>I want the indices: >>>(2, 2), (4, 7), (6, 7), (8, 9) and (8, 10) > > opener_stack = [] > for i, elem in enumerate(lst): > for c in elem: > if c == '(': > opener_stack.append(i) > elif c == ')': > print opener_stack.pop(), i > Thanks Raymond, this is definitely an elegant solution. It was also easy to add all the error checking I needed into this one. For the curious, my final solution looks something like: def indices(lst): stack = [] for i, elem in enumerate(lst): for c in elem: if c == '(': stack.append(i) elif c == ')' and not stack: raise Exception('")" at %i without "("' % i) elif c == ')': yield stack.pop(), i elif c == 'O' and stack: raise Exception('"O" at %i after "(" at %i' % (i, stack[-1])) elif c == '*' and not stack: raise Exception('"*" at %i without "("' % i) if stack: raise Exception('"(" at %r without ")"' % stack) Thanks again! STeVe From mwm at mired.org Tue May 17 17:38:14 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 17 May 2005 16:38:14 -0500 Subject: trouble with copy/deepcopy References: Message-ID: <86acmt8reh.fsf@guru.mired.org> Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org (Alexander Zatvornitskiy) writes: > ?????? Marc! > > 16 ??? 2005 ? 22:18, Marc 'BlackJack' Rintsch ? ????? ?????? ? All ?????: > > MR> That clears only one dictionary at class level. Which is visible on > MR> both instances. > > MR> class Distribution: > MR> def __init__(self): > MR> self.__gr_on_transp = dict() > MR> self.__ostatok_m = dict() > MR> ... > > MR> This creates *instance variables* which should be deepcopied > MR> without problems. > Hmm. I don't find definition of "class variable" in manual. I try to test it on > such a simple test and find that such variable is NOT shared between copies: Actually, it is shared - but only for reference. If you assign to it, you'll create an instance variable of the same name. As Peter explained, if you remove the instance variable, the class variable becomes visible again. Try this: py> class C: ... q = [] ... py> c1 = C() py> c2 = C() py> c3 = C() py> c1.q.append(1) py> c2.q.append(2) py> c3.q.append(3) py> c1.q, c2.q, c3.q ([1, 2, 3], [1, 2, 3], [1, 2, 3]) py> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steven.bethard at gmail.com Sun May 15 10:25:18 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 15 May 2005 08:25:18 -0600 Subject: A new to Python question In-Reply-To: References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> Message-ID: Fredrik Lundh wrote: > which is one of the things you really love when you link against > underdocumented Fortran programs from C. ("is that parameter > a scalar or an array? crash! oh, an array. how many values does > it expect? crash! oh, a few more, I suppose"). +1 QOTW STeVe From ARyan at co.linn.or.us Thu May 12 16:00:52 2005 From: ARyan at co.linn.or.us (Ryan, Adam) Date: Thu, 12 May 2005 13:00:52 -0700 Subject: Exception value cut off Message-ID: <8292E3D1E5E2EF4A94C36FE80D2443A83A82E7@linnms,> sys.exc_info()[1] returns the first 308 characters of an error message from a module. Is there a way to increase the length so it doesn't get cut off? Cheers, Adam From the.ech0 at gmail.com Tue May 3 08:10:55 2005 From: the.ech0 at gmail.com (ech0) Date: 3 May 2005 05:10:55 -0700 Subject: Py2Exe security In-Reply-To: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> Message-ID: <1115122255.179436.121260@o13g2000cwo.googlegroups.com> someone can sniff the client for the information it sends/receives so its possible to extract the info that way. From bill.mill at gmail.com Thu May 12 13:45:29 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 12 May 2005 13:45:29 -0400 Subject: Python Documentation (should be better?) In-Reply-To: References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> <86sm0sig7k.fsf@guru.mired.org> <17027.34077.234131.161432@montanaro.dyndns.org> Message-ID: <797fe3d405051210455ce20b65@mail.gmail.com> On 5/12/05, Terry Reedy wrote: > > "Skip Montanaro" wrote in message > news:17027.34077.234131.161432 at montanaro.dyndns.org... > > Maybe the Module Index should be renamed "Module/Type Index" and > > embellished > > with the builtin types, so that you'd find "float (builtin)", "string > > (builtin)", "dict (builtin)", etc. in the appropriate alphabetical > > positions. > > +1 > > TJR > +1 Bill Mill bill.mill at gmail.com From steve at holdenweb.com Mon May 2 22:37:40 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 02 May 2005 22:37:40 -0400 Subject: So many things that need to be decided.... In-Reply-To: References: Message-ID: Heather Stovold wrote: > Wow - deciding to program in python sure requires a lot of decisions! > > So far: > > I've decided on python for the programming language. > I've decided on wxpython for the GUI.... > I've decided on DrPython for the Editor.... > > I still need to decide on a database........ I've really only used Access, > and my SQL skills aren't that great. It would also need to be free.... > Any suggestions?? > I'd try sqlite, since you can just install the python extension module (which brings its own copy of the Windows DLL with it - since you mention Access I assume you are no stranger to Windows]. > Am I going to need a program/package for a report writer? or that might > depend on the database I use? > Generally speaking it would probably be a good idea to make sure that none of your other software technologies depend too heavily on one specific database, though this is generic advice which you can ignore to meet other project goals like "easily portable". > I've never had to make so many decisions to program in my life, because I've > generally only had a couple of options, or those options were decided by > other people. > > I really appreciate the help this newsgroup has provided - both for my > previous post - and for the reading of other posts I've done. I'm sure > I'll have a million more questions soon! > As Radio Shack are fond of saying, "You've got questions, we've got answers". Make sure you pass them on. And take Peter Hansen's advice to get elbow-deep in code. regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From rkern at ucsd.edu Fri May 13 13:26:12 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 13 May 2005 10:26:12 -0700 Subject: create words of various lengths In-Reply-To: <1116003875.263029.166190@z14g2000cwz.googlegroups.com> References: <1116002403.374232.210220@g49g2000cwa.googlegroups.com> <1116003875.263029.166190@z14g2000cwz.googlegroups.com> Message-ID: superprad at gmail.com wrote: > Hi Robert, > At first I thought it would be an interesting thing to have a little > swift module to create a database of all words in the dictionary. Okay, take one more step back. Why is it interesting to have such a dictionary? How do you intend to use it? Having answered those questions, why is it interesting to extend this with meaningless collections of symbols? No one can offer you a better method if we don't have a metric to judge whether a method is "better" than another. > But > then I thought y just the words in the dictionary? y not all possible > words like 'and' and 'adn'. Just was inspired with the little idea of > if its an 'and' or 'adn' when u read it in a combination of other words > you read it as 'and' itself. > > "nohting spceific wsa jsut plyaing around wtih ideas " Well, that's a somewhat different problem. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From belred at gmail.com Fri May 6 01:40:34 2005 From: belred at gmail.com (Bryan) Date: Thu, 05 May 2005 22:40:34 -0700 Subject: New Python regex Doc In-Reply-To: <1115328523.852744.110390@f14g2000cwb.googlegroups.com> References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113856843.023012.165500@l41g2000cwc.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> Message-ID: Xah Lee wrote: > Extra point: If the Python command line interface is actually a robust > application, like so-called IDE e.g. Mathematica front-end, then things > are very different. In reality, the Python command line interface is a > fucking toy whose max use is as a simplest calculator and double as a > chanting novelty for standard coding morons. In practice it isn't even > suitable as a trial'n'error pad for real-world programing. > i disagree with this 110%. i write python and jython code everyday at my company and the python interpreter (or command line interface) is always running on my computer whether it's from the command prompt, idle, pythonwin, pyshell, etc.. using the interpreter while you are coding is an invaluable tool and actually helps speed up software development which is opposite of what was stated by xah lee. it allows complete freedom to experiment reducing the amount of bugs that are in the real product. it's also useful to use the pywin modules and experiment with the win32 api interactively, or use the jython interpreter and experiment with some java api without any compilation step. i have never found these interpreters to be anything but very robust and *IT IS SUITABLE* as trial'n'error pad for real-world programming. the above comment can possible only be made by someone who doesn't actually use it for real world programming. bryan From Scott.Daniels at Acm.Org Fri May 20 22:58:24 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Fri, 20 May 2005 19:58:24 -0700 Subject: count files in a directory In-Reply-To: References: Message-ID: <428e9d4f$1@nntp0.pdx.net> James Stroud wrote: > Come to think of it > > file_count = len(os.walk(valid_path)[2]) > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ Somee possible answers are: # files directly in path file_count = len(os.walk(path)[2]) # files and dirs directly in path file_count = len(os.listdir(path)) # files in or below path file_count = 0 for root, dirs, files in os.walk(path): file_count += len(files) # files and dirs in or below path file_count = 0 for root, dirs, files in os.walk(path): file_count += len(files) + len(dirs) --Scott David Daniels Scott.Daniels at Acm.Org From just at xs4all.nl Fri May 6 18:24:07 2005 From: just at xs4all.nl (Just) Date: Sat, 07 May 2005 00:24:07 +0200 Subject: py2exe + svn - the final drama References: <427AD7E8.1060500@open-networks.net> Message-ID: In article , David Bolen wrote: > Are you perhaps trying to update the zip file in-place while it is still > being used by the application? I'm not sure that's a safe operation. I'm sure it's not :) [lots of useful help snipped] the zipimport module has an attr called _zip_directory_cache, which is a dict you can .clear(). Still, reloading modules is hairy at best, its probably easiest to relaunch your app when the .zip file has changed. Just From cjbottaro at alumni.cs.utexas.edu Wed May 11 16:47:11 2005 From: cjbottaro at alumni.cs.utexas.edu (Christopher J. Bottaro) Date: Wed, 11 May 2005 15:47:11 -0500 Subject: Python Documentation (should be better?) References: Message-ID: rbt wrote: > Christopher J. Bottaro wrote: >> Christopher J. Bottaro wrote: >> >> >>>...blah blah blah... >> >> >> Heh, silly me...there is already a huge thread about this...kinda. >> >> The intricacies of the computing term "greedy" aside, yes I think the >> Python >> documentation should generally be better. What that means, I have no >> idea. All I know is that I like PHP's documentation and it should be like >> that. My question is, why is PHP's documentation so good and Python's >> mediocre? > > Because PHP is such a 'thrown together' and 'bolted-on' language. If it > didn't have *outstanding* documentation (which it does BTW), no one > could even begin to understand how they got from a little HTML language > to a kinda/sorta OO language. > > PHP is showing its age... thanks to its docs, it's still *extremely* > useful. Exactly!! See thats what I'm saying. I _think_ its widely accepted that PHP has awesome documentation. And like rbt said, that makes it extremely useful. Why can't Python have documentation like that? The language is awesome, it just needs documentation of the same quality. I'm sorry that I have such a hard time giving specific examples and what not. All I can do (as of now) is kinda report the vibe I get...which is completely useless, I know...=) -- C From ajsiegel at optonline.com Sun May 29 14:44:30 2005 From: ajsiegel at optonline.com (Arthur) Date: Sun, 29 May 2005 14:44:30 -0400 Subject: Case Sensitive, Multiline Comments References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> <8664x5y92g.fsf@guru.mired.org> <429654DA.9050903@lexicon.net> <1117154013.092736.298310@g14g2000cwa.googlegroups.com> Message-ID: On 26 May 2005 17:33:33 -0700, "Elliot Temple" wrote: >Thanks for the link on case sensitivity. I'm curious about the person >who found case sensitivity useful though: what is it useful for? I am curious about why you find case sensitivity annoying. But just mildly curious. Martelli can tell you why Guido keeping case sensitivity in Python was him bowing to the stupidity of the masses. I have been neutral on the subject except to the extent the impetous for going case insensitive would be to statisfy the needs - as Guido uses the word - "non-programmers". a) its probably better to design a programming language around the needs of programmers than around those of non-porgrammers. that much always seemed quite obvious to me. b) it would only help non-programmers who were more comfortable with case insensitivity but hurt non-progammers more comfortable with case sensitivity. That Martelli so strongly favors case insensitivity for his own use, is one of many indications that this is not an issue that cuts along the lines of quantity of programming experience.. That much also seemed pretty obvious, but it didn't seem to stop the folks who wanted case insensitivity from making the non-programmer accessibility issue paramount. and on the flimiest of evidence. Those who prefer sensitivity were anti-accessbility elitists. Damn near Republicans. Classic politics. Thankfully Guido seemed to have lost patience for the whole thing. I think the position is pretty much that Python will be case sensitive becasue it has been case sensitive. Art From mweihs at gmx.at Tue May 17 06:38:10 2005 From: mweihs at gmx.at (Markus Weihs) Date: Tue, 17 May 2005 12:38:10 +0200 Subject: Python forum References: Message-ID: Hi! > I'm going to say a suggestion, why don't you create a forum like the one > of Ruby (http://www.rubyforums.com/)? for the novices this is a great > help, better than a mail list > > It's also worth noting that rubyforums.com has nearly no posts (six > total) because it takes very just a short time working. > > I know that you have python-list, it's both an email and a usenet list. > But I think that a forum is great for the learning. The test is in > gentoo's forums. They are a lot of experienced people answering > questions without any problem and it goes very well If you speak German, there is a forum at www.python-forum.de . There is also an english one at http://python-forum.org/py/index.php, but as you can see, there's not much traffic :-/ Regards, Markus From querypk at gmail.com Wed May 25 18:02:46 2005 From: querypk at gmail.com (querypk at gmail.com) Date: 25 May 2005 15:02:46 -0700 Subject: Improve the performance of a loop Message-ID: <1117058565.920549.221420@g47g2000cwa.googlegroups.com> What is the fastest way to code this particular block of code below.. I used numeric for this currently and I thought it should be really fast.. But, for large sets of data (bx and vbox) it takes a long time and I would like to improve. vbox = array(m) (size: 1000x1000 approx) for b in bx: vbox[ b[1], b[0]:b[2] ] = 0 vbox[ b[3], b[0]:b[2] ] = 0 vbox[ b[1]:b[3], b[0] ] = 0 vbox[ b[1]:b[3], b[2] ] = 0 and vbox is a 2D array where bx is of form [( int,int,int,int),(........) ] From martin at v.loewis.de Mon May 23 13:37:03 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Mon, 23 May 2005 19:37:03 +0200 Subject: No encodings after freezing In-Reply-To: <1116861269.528674.295440@f14g2000cwb.googlegroups.com> References: <1116861269.528674.295440@f14g2000cwb.googlegroups.com> Message-ID: <429214BF.7090505@v.loewis.de> mmf wrote: > text_new = text.encode('utf_8') [...] > But everytime I run this binary the utf-8 encoding cannot be found. > (Also any other encoding like iso8859_15 cannot be found...) > > What am I doing wrong? Codecs are modules (in the encodings package). So if the codecs you need aren't frozen, they aren't available at run-time. OTOH, freeze cannot "see" the import (since it doesn't know that the argument to .encode is really similar to a module name), so it won't include the modules. You need to give it an explicit list of encodings you want to freeze. Most likely, there is some explicit command line argument, but alternatively, you could also put if 0: import encodings.utf_8 import encodings.iso8859_1 # etc into some source file. Regards, Martin From mpnugent at NOSPAMcopper.net Tue May 17 23:40:52 2005 From: mpnugent at NOSPAMcopper.net (Michael P. Nugent) Date: Tue, 17 May 2005 23:40:52 -0400 Subject: A Specific PyGame In-Reply-To: <7Iyie.2326$X92.1859@newsread2.news.pas.earthlink.net> References: <428ab5d7$1_1@newsfeed.slurp.net> <7Iyie.2326$X92.1859@newsread2.news.pas.earthlink.net> Message-ID: <428abb69$1_5@newsfeed.slurp.net> Greg Krohn wrote: > Michael P. Nugent wrote: > >> I am looking for a specific "game" that is really a programming >> environment for young kids. >> >> I believe it implements PyGame, and presents two windows: one is a >> grid with some obstacles, and a character that must traverse the grid; >> another is an interactive editor that encourages a learner to write a >> script to navigate the character around the obstacles. >> >> I saw this within the past week, but I cannot remember or discover >> where. I have revisited a number of PyGame related sites, and Googled >> like crazy, but I'm not finding any visited links that are productive. >> I've also extracted everything out of .mozilla/.../history.dat. As you >> can see, I'm looking for a specific answer to my specific query. >> > > Perhaps you are thinking of GvR (Guido van Robot): > http://gvr.sourceforge.net/ . > > -greg If it were a snake, it woulda' bit me! I even had a bookmark for it, but for some reason was associating it with a Robot Odyssey clone-- written in Java, no less! It has been a disorienting week. Thank you. love the Python community. From http Sun May 22 03:34:20 2005 From: http (Paul Rubin) Date: 22 May 2005 00:34:20 -0700 Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116443474.565264.176640@g44g2000cwa.googlegroups.com> <7xd5rn93zi.fsf@ruckus.brouhaha.com> <7x1x81d5bx.fsf@ruckus.brouhaha.com> <7xacmpgxn1.fsf@ruckus.brouhaha.com> Message-ID: <7x64xbn283.fsf@ruckus.brouhaha.com> Dave Brueck writes: > >>m2crypto (plus some patches to make asynchronous SSL do what we needed). > > That seems to be a nice piece of code, but it's still at version > > 0.13; > > Version numbers are fairly relative, though. In another project we're > using some proprietary, closed source libraries (unrelated to crypto) > that are version 3 and they seem buggier and less stable than m2crypto. Yeah, OpenSSL itself is something like 0.97, which however does sound closer to a final release than 0.13 of anything. > Having said that - I think we probably *would* use it for production > financial transactions - but that's more a matter of closed vs. open > source than Python vs not. That makes some sense; once you have the code in-house and the expertise to evaluate it and maintain it, it's at least no worse than something you wrote yourself. If you just downloaded it and plopped it into your application with your eyes closed, that might be asking for trouble. > > There's also been some traffic on the > > python-crypto list about Zope encountering memory leaks with it. > > Ok... so? I mean, if there's a memory leak, and it's hurting us, we > have options: ... I just mean the memory leak is a symptom that the software isn't yet completely debugged. > Memory leaks aren't exactly unique to Python - according to > bugs.sun.com, there are currently 382 *open* bugs related to memory > leaks in the JDK alone. Are any of those memory leaks in JSSE? It's one thing to have a problem in some noncritical GUI widget, another to have it in the crypto code. From jstroud at mbi.ucla.edu Sat May 7 20:36:39 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sat, 7 May 2005 17:36:39 -0700 Subject: Python Pseudo-Switch Message-ID: <200505071736.39806.jstroud@mbi.ucla.edu> Hello All, Because of my poorly designing a database, I have recently found it necessary to explore the wonders of the Python pseudo-switch: do_case = { "A" : lambda x: x["bob"], "B" : lambda x: x["carol"], "C" : lambda x: "Ted", "D" : lambda x: do_something(x) } my_thing = do_case[get_value_from_thin_air()](adict) How to handle this kind of thing when lambda is removed from the language, beside the obvious def'ing those tiny little functions? James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From andreas at kostyrka.org Tue May 3 09:56:51 2005 From: andreas at kostyrka.org (andreas at kostyrka.org) Date: Tue, 3 May 2005 15:56:51 +0200 Subject: Py2Exe security In-Reply-To: <1115124297.746843.111770@g14g2000cwa.googlegroups.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> <1115124297.746843.111770@g14g2000cwa.googlegroups.com> Message-ID: <20050503135651.GA21228@heaven.kostyrka.org> On Tue, May 03, 2005 at 06:01:33AM -0700, Terje Johan Abrahamsen wrote: > > Simon Brunning wrote: > > On 3 May 2005 05:03:00 -0700, Terje Johan Abrahamsen > wrote: > > > We have created some programs in Python that are to be distributed > > > around. The programs will be made into .exe files by py2exe. > However, > > > in the source there are certain webadresses, logins and passwords > that > > > the programs use, that we would like to keep away from the end > users. > > > They will use them thru the program, but we would like them not to > be > > > extracted and used separately for other purposes. > > > > If your program can access these details, then a suficiently > > determined attacker can access them too, regardless of what you do. > > Yes, I assume so. Luckily it is not national secrets we are trying to > hide. But, how does py2exe compare with for example a program written > in a compiled language like C++? Is it easier to find the info in a > py2exe .exe than a c++ compiled c++? About the same. C++ programs do have their string constants as cleartext in the binary too. Personally I'd be more concerned about the network side (use https and verify the server certificate), and debugging tools that might be able to intercept your traffic anyway. Andreas From dkuhlman at rexx.com Mon May 16 18:32:27 2005 From: dkuhlman at rexx.com (Dave Kuhlman) Date: Mon, 16 May 2005 22:32:27 GMT Subject: Recommended version of gcc for Python? References: <7P5ie.18072$J12.7334@newssvr14.news.prodigy.com> <1116271504.748836.25540@z14g2000cwz.googlegroups.com> Message-ID: <%b9ie.1874$Uv2.19@newssvr13.news.prodigy.com> casevh at comcast.net wrote: > On Ubuntu, I have tried 3.3.4, 3.4.3 and 4.0. Compile and make > test ran successfully with all three. For my benchmark, platform, > and compiler options, 3.4.3 was the fastest by approximately 2%. > > I would normally use the default compiler for your distribution. > So, I'll stay with what I've got (3.3.5) for now. Thanks for the help. Dave -- http://www.rexx.com/~dkuhlman From no at noemail.com Thu May 26 14:39:11 2005 From: no at noemail.com (Jason Gurtz) Date: Thu, 26 May 2005 14:39:11 -0400 Subject: Intellisense and the psychology of typing In-Reply-To: <1117125072.825389.74190@g47g2000cwa.googlegroups.com> References: <1117125072.825389.74190@g47g2000cwa.googlegroups.com> Message-ID: <42961805$1_3@spool9-east.superfeed.net> On 5/26/2005 12:31, andrew.queisser at hp.com wrote: > 1) Intellisense is really just another crutch that does more harm than > good? To me I found the intellisense in VS for C++ was somewhat helpful in my earliest stage of learning where I had to look up how many args a function had. After a while, I found it more convenient to just keep the VS language and std lib docs open in another window. IOW, it started getting in the way. Maybe at times it can save some keystrokes but I kept finding a pattern of start typing something...down arrow...down arrow...down arrow...down arrow...tab...type args. Even worse is the situation were start typing something...downWhoops hit left arrow...hit end...hit backspace...type last letter....down arrow...etc...tab...etc... How egregious!? No thank you; I already use variable names like "myData" instead of "mD" so extra keystrokes are not that big of a deal :) Still I think calling it a crutch might be a bit extreme. Is a book or documentation a crutch too? > 2) Intellisense is really useful but hard to implement well in IDEs for > dynamic languages? Maybe for some people and yes. There was some recent discussion in this very NG about this WRT vim et al. Cheers, ~Jason -- Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com From ccurvey at gmail.com Tue May 3 11:07:06 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 3 May 2005 08:07:06 -0700 Subject: xmlrpclib and decoding entity references Message-ID: <1115132826.795008.320190@z14g2000cwz.googlegroups.com> I'm writing an XMLRPC server, which is receiving a request (from a non-Python client) that looks like this (formatted for legibility): echo Le Martyre de Saint André <BR> avec inscription 'Le Dominiquain.' et 'Le tableau fait par le dominicain, d'après son dessein à... est à Rome, à l'église Saint André della Valle' sur le cadre<BR> craie noire, plume et encre brune, lavis brun rehaussé de blanc sur papier brun<BR> 190 x 228 mm. (7 1/2 x 9 in.) But when my "echo" method is invoked, the value of the string is: Le Martyre de Saint Andr;
avec inscription 'Le Dominiquain.' et 'Le tableau fait par le dominicain, d'apr:s son dessein 2... est 2 Rome, 2 l';glise Saint Andr; della Valle' sur le cadre
craie noire, plume et encre brune, lavis brun rehauss; de blanc sur papier brun
190 x 228 mm. (7 1/2 x 9 in.) Can anyone give me a lead on how to convert the entity references into something that will make it through to my method call? From mahs at telcopartners.com Thu May 12 15:11:15 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Thu, 12 May 2005 12:11:15 -0700 Subject: How "return" no return ? In-Reply-To: <3ehkh2F366o4U1@individual.net> References: <3ehaurF34ak0U1@individual.net><3ehc5tF35eo3U1@individual.net> <3ehkh2F366o4U1@individual.net> Message-ID: Ximo wrote: > I am doing my own interpreter with the Python languaje. > > Do you understand me? > > > > "Fredrik Lundh" escribi? en el mensaje > news:mailman.484.1115919541.29826.python-list at python.org... > >>"Ximo" wrote: >> >> >>>I am doing a interpret of lines and it show me a prompt, and I want if I >>>write a declaration as "int a" my progrtam return de prompt and nothing >>>more, for exemple: >>> >>> You may be looking for the flags argument to the compile function: >>> exec compile("int(3)","","single") 3 >>> exec compile("int(3)","","exec") >>> >>> help(compile) Help on built-in function compile in module __builtin__: compile(...) compile(source, filename, mode[, flags[, dont_inherit]]) -> code object Compile the source string (a Python module, statement or expression) into a code object that can be executed by the exec statement or eval(). The filename will be used for run-time error messages. The mode must be 'exec' to compile a module, 'single' to compile a single (interactive) statement, or 'eval' to compile an expression. The flags argument, if present, controls which future statements influence the compilation of the code. The dont_inherit argument, if non-zero, stops the compilation inheriting the effects of any future statements in effect in the code calling compile; if absent or zero these statements do influence the compilation, in addition to any features explicitly specified. >>> Michael From maxm at mxm.dk Tue May 10 09:14:47 2005 From: maxm at mxm.dk (Max M) Date: Tue, 10 May 2005 15:14:47 +0200 Subject: Merging overlapping spans/ranges Message-ID: <4280b31b$0$198$edfadb0f@dread12.news.tele.dk> I am writing a "find-free-time" function for a calendar. There are a lot of time spans with start end times, some overlapping, some not. To find the free time spans, I first need to convert the events into a list of non overlapping time spans "meta-spans". This nice ascii graph should show what I mean. 1) --- 2) --- 3) --- 4) ----- 5) ----- >> ------- -------- # meta spans I can then iterate through the meta-spans and find non-busy times. I have written the class below, but it is rather O^2, so I wondered if anybody has an idea for a better approach? ###################################### # -*- coding: latin-1 -*- """ 1) --- 2) --- 3) --- 4) ----- 5) ----- >> ------- -------- """ class MetaSpans: """ Populate with a list of span tuples [(start,end)], and it will make "meta" spans, with overlapping spans folded into one span. """ def __init__(self): self.spans = [] def add(self, span): start, end = span overlapping = [span] non_overlapping = [] for spn in self.spans: spn_start, spn_end = spn # span rules for iterated spans starts_before = spn_start <= start ends_after = spn_end >= end is_outside = starts_before and ends_after starts_inside = start <= spn_start <= end ends_inside = start <= spn_end <= end overlaps = starts_inside or ends_inside or is_outside if overlaps: overlapping.append(spn) else: non_overlapping.append(spn) # overlapping spans are changed to one span starts = [] ends = [] for start, end in overlapping: starts.append(start) ends.append(end) min_start = min(starts) max_end = max(ends) non_overlapping.append( (min_start, max_end) ) self.spans = non_overlapping def findFreeTime(self, duration): self.spans.sort() if __name__ == '__main__': ms = MetaSpans() ms.add((0,3)) ms.add((4,7)) ms.add((2,5)) ms.add((9,14)) ms.add((12,17)) print ms.spans from datetime import datetime ms = MetaSpans() ms.add((datetime(2005, 1, 1, 0, 0, 0), datetime(2005, 1, 1, 3, 0, 0))) ms.add((datetime(2005, 1, 1, 4, 0, 0), datetime(2005, 1, 1, 7, 0, 0))) ms.add((datetime(2005, 1, 1, 2, 0, 0), datetime(2005, 1, 1, 5, 0, 0))) ms.add((datetime(2005, 1, 1, 9, 0, 0), datetime(2005, 1, 1, 14, 0, 0))) ms.add((datetime(2005, 1, 1, 12, 0, 0), datetime(2005, 1, 1, 17, 0, 0))) print ms.spans -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From could.net at gmail.com Thu May 19 05:03:34 2005 From: could.net at gmail.com (could ildg) Date: Thu, 19 May 2005 17:03:34 +0800 Subject: What's the use of changing func_name? In-Reply-To: References: <311b5ce105051822477c09c81@mail.gmail.com> <311b5ce1050518231650b3b53e@mail.gmail.com> Message-ID: <311b5ce1050519020323729e26@mail.gmail.com> Thanks to Robert Kern. You mean that though we can change the func_name of a function, but we still can't call it by func_name, and the func_name is only useful in some other circumstances? I also think so now after I have tried so many times on this puzzled func_name property. On 5/19/05, Robert Kern wrote: > could ildg wrote: > > Thank you for your help. > > I know the function g is changed after setting the func_name. > > But I still can't call funciton g by using f(), when I try to do > > this, error will occur: > > > > > >>>>g.func_name="f" > >>>>print g > > > > > > > >>>>f() > > > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'f' is not defined > > > > Since the name of g is changed into f, why can't I call it by using f()? > > Should I call it using f through other ways? Please tell me. Thanks~ > > Others have answered this particular question, but you're probably still > wondering what is the use of changing .func_name if it doesn't also > change the name by which you call it. The answer is that there are tools > that use the .func_name attribute for various purposes. For example, a > documentation generating tool might look at the .func_name attribute to > make the proper documentation. Actually, that's probably *the* biggest > use case because I can't think of any more significant ones. > > -- > Robert Kern > rkern at ucsd.edu > > "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 > From nir at digitalpeers.com Tue May 3 05:57:02 2005 From: nir at digitalpeers.com (Nir Aides) Date: Tue, 03 May 2005 12:57:02 +0300 Subject: Tkinter and Windows XP themes (via manifest files) Message-ID: <42774b17@news.bezeqint.net> Hello, How do I make Tkinter use windows XP themes? ordinary root Tkinter windows ignore the manifest file (which is placed by wxPython for the same purpose) but message dialogs popped with tkMessageBox.Message do use the Windows Theme, so it should be possible. Does anyone has a clue? Thanks, Nir From 550283447739-0001 at t-online.de Tue May 17 14:51:58 2005 From: 550283447739-0001 at t-online.de (Oliver Albrecht) Date: Tue, 17 May 2005 20:51:58 +0200 Subject: Image.putpalette(Colors)? References: Message-ID: Thanks, I've read this page.( out of date ?) http://www.pythonware.com/products/pil/articles/creating-palette-images.htm Very nicely to become answered from the major author and python genius highly personally himself :-D Which I want to do is; convert several "RGB" Images (or "P") with one specified palette (to "P"). Or this (for "P")pattern; if the Source Image has the exact same colors but wrong(other) paletteIds, how can i sort this? With List.sort()? And give each pixel the right paletteId? That is what i mean with similar image (source"RGB" to destinaton"P"). convert() without "WEB"? (sry if i've enough experience with python)>=newbie From harlinseritt at yahoo.com Sun May 8 09:16:16 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 8 May 2005 06:16:16 -0700 Subject: SGMLlib module Message-ID: <1115558176.212693.45280@z14g2000cwz.googlegroups.com> I am trying to use SGMLlib module to extract all links from some data I pulled from the web (via urllib). I have looked at the documentation online and can not make sense of it. As a quick example, how would I get the hyperlinks for an html file? thanks, Harlin From ville at spammers.com Sat May 21 07:09:28 2005 From: ville at spammers.com (Ville Vainio) Date: 21 May 2005 14:09:28 +0300 Subject: moving from c++ to python References: Message-ID: >>>>> "Michael" == Michael writes: Michael> me?? My biggest confusion so far is the lack of pointers Michael> in Python ...... Achtually, python uses pointers for everything. On the contrary there are no "value types" in python. MyClass* c = new MyClass(12,13); is equal to c = MyClass(12,13) There is no equivalent to MyClass c(12,13); because it's not needed. -- Ville Vainio http://tinyurl.com/2prnb From peter at engcorp.com Tue May 10 23:16:46 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 May 2005 23:16:46 -0400 Subject: pyvm -- faster python In-Reply-To: <7xvf5qbir1.fsf@ruckus.brouhaha.com> References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > "Roger Binns" writes: > >>That will rule out all the gui frameworks, SSL, cryptography >>and numerous other packages. Have a look at what happened to >>Prothon. > > > I think it would be enough to retarget SWIG. > > >>What ultimately killed it was the problem of having a decent >>library. > > > Nah, I think people just lost interest. Otherwise, why isn't Jython > dead? I thought Jython had full access to the entire library of standard Java, plus at least the Python parts of the Python standard library... -Peter From rkern at ucsd.edu Sun May 1 05:23:31 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sun, 01 May 2005 02:23:31 -0700 Subject: wxPython: ansi or unicode? In-Reply-To: <42749af0$1_3@rain.i-cable.com> References: <42749af0$1_3@rain.i-cable.com> Message-ID: monkey wrote: > Hi all, which should be install? Really confused @@... Unicode. > Is that mean unicode version used for programming in language other than > English? No. The Unicode version allows the underlying wxWidgets GUI toolkit to use Unicode text. You want this. On certain platforms, older versions of the unicode version of wxPython were somewhat unstable. I believe this has been largely resolved, and the ANSI versions will be going away. I may have some details wrong. If you want an authoritative answer, ask on the wxPython lists. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From ramen at lackingtalent.com Fri May 20 13:43:38 2005 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 20 May 2005 10:43:38 -0700 Subject: OO design question / Transform object in place? In-Reply-To: <1116585815.095195.141750@g43g2000cwa.googlegroups.com> References: <1115825605.654601.137580@f14g2000cwb.googlegroups.com> <50qge.9716$D91.477@fed1read01> <1116585815.095195.141750@g43g2000cwa.googlegroups.com> Message-ID: andy2O at hotmail.com wrote: > Dave Benjamin wrote: > >>I think it's much better for simplify() to return a new object >>and leave the original object unmodified. You can still write: >>expression2 = expression2.simplify() > > A belated thank-you message for your reply to my posting. I took your > advice, and made all the simplify methods return new objects and this > has simplified my code structure a great deal (and any slow down in run > time just doesn't matter!). No problem. Glad it helped. =) > Am I right that to make "expression2.simplify()" return a new object I > will need use copy.copy a lot, as in: > > def simplify(self): > newreturnvalue=copy.copy(self) > # > #....now the code does lots of complicated things > # to newreturnvalue object... > # > return newreturnvalue You could use copy.copy(), as long as you want a shallow copy and you don't want to change from one class to another. However, it may be to your advantage to use the constructor of one or more classes to build the result; this allows you to conditionally pick the result object's class. Also, there may be situations where an object can't be simplified, in which case you can just return "self", and avoid copying entirely. Dave From bdelmee at advalvas.REMOVEME.be Sat May 21 08:34:01 2005 From: bdelmee at advalvas.REMOVEME.be (=?ISO-8859-1?Q?Bernard_Delm=E9e?=) Date: Sat, 21 May 2005 14:34:01 +0200 Subject: import cx_Oracle fails! In-Reply-To: <1116547117.316065.104030@o13g2000cwo.googlegroups.com> References: <1116454404.355741.51730@f14g2000cwb.googlegroups.com> <1116546336.235595.19700@o13g2000cwo.googlegroups.com> <1116547117.316065.104030@o13g2000cwo.googlegroups.com> Message-ID: <428f2b1f$0$1819$6c56d894@reader0.news.be.easynet.net> Hi Daniel, is your processor Itanium or PA? I am having a hard time getting cx_oracle (4.1) and python (2.3.5) to cooperate on an HP-UX 11.23 server (I see you're running 11.11). I can compile both packages with gcc 3.4.3 either in 32-bit (apparently the default) or 64-bit (-mlp64 gcc flag) but python refuses to load the cx_oracle.sl shared lib... Bernard. From slick_mick_00 at hotmail.com Sun May 22 07:26:03 2005 From: slick_mick_00 at hotmail.com (Michael) Date: Sun, 22 May 2005 11:26:03 +0000 (UTC) Subject: Newbie python design question Message-ID: Hi, I'm trying to write a script to parse a .cpp file and begin to create a 'translational unit'. To do this i need to: Go through the file and remove all 'C' comments as /* Comment 1*/ (can be on multiple lines) Go through and remove all 'C++' comments, anything between // and '\n' char. The start at the top, and work the way through, with the following valid terms: #include #include "filename" - copy the contents of filename to this point in the file and continue. #define X Y -Store the term X,Y in DefineDictionary, then later if X is encountered, substitute Y. namespace n { }; -a namespace, can contain classes, functions and sub-namespaces class c { }; -a class. If i were to process this in C++, i would create some form of statemachine, similar to a regex engine... I would just like some ideas on the easiest way to implment this in python!! Regards Mike From adsheehan at eircom.net Mon May 9 11:33:13 2005 From: adsheehan at eircom.net (adsheehan at eircom.net) Date: 9 May 2005 08:33:13 -0700 Subject: M2Crypto SSL memory leaks - fixes or alternatives ?? Message-ID: <1115652793.232733.310800@f14g2000cwb.googlegroups.com> Hi folks, I notice that M2Crypto (a python wrap of OpenSSL) leaks (haemorrhages) memory significantly and affects my long running app very badly. Does anyone know of fixes to this problem? Does anyone recommmend alternatives to M2C ? e.g pyopenssl. I notice that Guido Van Rossum has flamed about this in the past but I am not aware of any resolutions. Thanks Alan From ivoras at fer.hr Sat May 28 06:32:30 2005 From: ivoras at fer.hr (Ivan Voras) Date: Sat, 28 May 2005 12:32:30 +0200 Subject: Software licenses and releasing Python programs for review In-Reply-To: <1117245014.218831.317750@g14g2000cwa.googlegroups.com> References: <1117245014.218831.317750@g14g2000cwa.googlegroups.com> Message-ID: poisondart wrote: > Ultimately I desire two things from the license (but not limited to): > - being able to distribute it freely, anybody can modify it > - nobody is allowed to make profit from my code (other than myself) GPL does something like this, except it doesn't forbid anyone to sell the software. Also, you do realize that if you make it freely distributable and modifiable, you could get into the situations where potential customers say "so why should we buy it from him when we can get it free from X"? From jrastrick at student.usyd.edu.au Wed May 11 02:59:26 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 10 May 2005 23:59:26 -0700 Subject: Merging overlapping spans/ranges In-Reply-To: References: <4280b31b$0$198$edfadb0f@dread12.news.tele.dk> <42813c84.1201907341@news.oz.net> Message-ID: <1115794766.178243.202740@g47g2000cwa.googlegroups.com> Should work fine as far as I can see. Of course, thats not very 'pythonic' - I should probably give at least 10 different unit tests that it passes ;) Its gratifying to know I'm not the only one who needed that final yield. Jim Sizelove wrote: > Bengt Richter wrote: > > On Tue, 10 May 2005 15:14:47 +0200, Max M wrote: > > > > > >>I am writing a "find-free-time" function for a calendar. There are a lot > >>of time spans with start end times, some overlapping, some not. > >> > >>To find the free time spans, I first need to convert the events into a > >>list of non overlapping time spans "meta-spans". > >> > >>This nice ascii graph should show what I mean. > >> > >>1) --- > >>2) --- > >>3) --- > >>4) ----- > >>5) ----- > >> > >> > >>>>------- -------- # meta spans > >> > >>I can then iterate through the meta-spans and find non-busy times. > >> > >>I have written the class below, but it is rather O^2, so I wondered if > >>anybody has an idea for a better approach? > >> > > > > Maybe (not tested beyond what you see ;-) > > It is with some trepidation that I write this message; after hanging > around in c.l.p for the better part of a year, I have come to expect > Bengt's messages to be right-on and error-free. > > However this time... :) > > >>> def mergespans(spans): > > ... start = end = None > > ... for s,e in sorted(spans): > > ... if start is None: start, end = s,e; continue > > ... if s <= end: end = e; continue > > ... yield start, end > > ... start,end = s,e > > ... if start is not None: yield start, end > > ... > > >>> spans = [(0,3), (4,7), (2,5), (9,14), (12,17)] > > >>> list(mergespans(spans)) > > [(0, 7), (9, 17)] > > There can be a problem in mergespans if one span fits inside another: > > >>> spans = [(0,5), (4,7), (2,3), (9,14), (12,17)] > >>> list(mergespans(spans)) > [(0, 3), (4, 7), (9, 17)] > > Here is a revised version (not tested beyond what you see ;-) > >>> def mergespans(spans): > ... start = end = None > ... for s,e in sorted(spans): > ... if start is None: > ... start, end = s,e > ... continue > ... if s <= end: > ... if end < e: > ... end = e > ... continue > ... yield start, end > ... start,end = s,e > ... if start is not None: > ... yield start, end > ... > >>> list(mergespans([(0,5), (4,7), (2,3), (9,14), (12,17)])) > [(0, 7), (9, 17)] > >>> list(mergespans([(0,3), (4,7), (2,5), (9,14), (12,17)])) > [(0, 7), (9, 17)] > > Can anyone find any other errors in this? ;-) > > With humble regards, > Jim Sizelove From mrovner at propel.com Tue May 10 16:38:54 2005 From: mrovner at propel.com (Mike Rovner) Date: Tue, 10 May 2005 13:38:54 -0700 Subject: Merging overlapping spans/ranges In-Reply-To: <4280b31b$0$198$edfadb0f@dread12.news.tele.dk> References: <4280b31b$0$198$edfadb0f@dread12.news.tele.dk> Message-ID: Max M wrote: > I am writing a "find-free-time" function for a calendar. There are a lot > of time spans with start end times, some overlapping, some not. > > To find the free time spans, I first need to convert the events into a > list of non overlapping time spans "meta-spans". > "Almost" linear method (includes .sort() which is afaik N*logN): [Set all priority to 1, or you will get changes in priorities as well.] def merge(p): """ p is a seq of (start, priority, end) returns list of merged events: (start1, pri), (end1, 0), (start2, pri), (end2, 0), ... """ all=[] # list of x, h, up, id for id,(l,h,r) in enumerate(p): all.append((l,h,1,id)) all.append((r,h,0,id)) all.sort() sl = [] # skyline solution slx = slh = 0 # current values vis = {} # active {id:h} for x,h,up,id in all: if up: vis[id]=h if h>slh: sl.append((x,h)) slh=h else: del vis[id] assert h<=slh if h==slh: v = vis.values() if v: h = max(v) else: h = 0 sl.append((x,h)) slh=h slx=x # merge same time events s=dict(sl) sl=s.keys() sl.sort() return [(k,s[k]) for k in sl] From bill.mill at gmail.com Tue May 10 13:39:06 2005 From: bill.mill at gmail.com (Bill Mill) Date: Tue, 10 May 2005 13:39:06 -0400 Subject: Python Graphing Utilities. In-Reply-To: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> References: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> Message-ID: <797fe3d405051010392c00011f@mail.gmail.com> On 5/10/05, Kenneth Miller wrote: > Hello All, > > I am new to Python and i was wondering what graphing utlities would be > available to me. I have already tried BLT and after weeks of unsuccesful > installs i'd like to find something else. Anything someone would recommend? matplotlib is awesome: http://matplotlib.sourceforge.net/ and gnuplot.py is passable: http://gnuplot-py.sourceforge.net/ (a better version of gnuplot.py is available with the excellent ipython interpreter at http://ipython.scipy.org/) All of the above are cross-platform to at least linux and windows. Peace Bill Mill bill.mill at gmail.com From a.schmolck at gmx.net Sat May 14 00:45:54 2005 From: a.schmolck at gmx.net (Alexander Schmolck) Date: Sat, 14 May 2005 05:45:54 +0100 Subject: Python Polymorphism References: <20050512200045.85674.qmail@web52604.mail.yahoo.com> Message-ID: "Fredrik Lundh" writes: > Carlos Moreira wrote: > >> Supose that I want to create two methos (inside a >> class) with exactly same name, but number of >> parameters different: > > that's known as multimethods, or multiple dispatch. No -- multiple dispatch is something entirely different. 'as From ml at dynkin.com Tue May 3 10:46:44 2005 From: ml at dynkin.com (George Yoshida) Date: Tue, 03 May 2005 23:46:44 +0900 Subject: Documenting Python code. In-Reply-To: <1115128200.628997@hqnntp01.autodesk.com> References: <1115128200.628997@hqnntp01.autodesk.com> Message-ID: Isaac Rodriguez wrote: > Python is a dynamically typed language, which makes me think of the > importance of documenting not only the purpose of a particular function or > class method, but also what requirements should be met by the objects passed > as parameters, what will the function return, and what type of erros can > happen. I don't see any of this information in the __doc__ attributes, so I > was wondering if people is using some other way to document their code. I guess you're talking about something like literate programming. If so, doctest module may be useful for that purpose. Doctest can also be used as a unittest. -- george http://www.dynkin.com/ From chenyang2000 at 126.com Fri May 6 09:02:48 2005 From: chenyang2000 at 126.com (=?gb2312?B?s8LR9A==?=) Date: Fri, 6 May 2005 21:02:48 +0800 (CST) Subject: =?gb2312?B?VGtpbnRlciBBcHAgdG8gU3lzdGVtIFRyYXk=?= Message-ID: <427B6AF8.0000D2.25368@m61.126.com> I write a program with Python 2.4 + Tkinter Execute it, there will be a window show something. If I minimize it, it will be minimized to the taskbar. But I would like it to miniminze to the System Tray, this can make taskbar more clear. Would you please tell me how to modify my program. Thanks a lot !! Soure Code : # Display digits of pi in a window, calculating in a separate thread. # Compare with wpi.py in the Demo/threads/wpi.py import sys import time import thread from Tkinter import * class ThreadExample: def __init__(self, master=None): self.ok = 1 self.digits = [] self.digits_calculated = 0 self.digits_displayed = 0 self.master = master thread.start_new_thread(self.worker_thread, ()) self.frame = Frame(master, relief=RAISED, borderwidth=2) self.text = Text(self.frame, height=26, width=50) self.scroll = Scrollbar(self.frame, command=self.text.yview) self.text.configure(yscrollcommand=self.scroll.set) self.text.pack(side=LEFT) self.scroll.pack(side=RIGHT, fill=Y) self.frame.pack(padx=4, pady=4) Button(master, text='Close', command=self.shutdown).pack(side=TOP) self.master.after(100, self.check_digits) def worker_thread(self): while self.ok: self.digits.append(`9`) time.sleep(0.001) def shutdown(self): self.ok =0 self.master.after(100, self.master.quit) def check_digits(self): self.digits_calculated = len(self.digits) diff = self.digits_calculated - self.digits_displayed ix = self.digits_displayed for i in range(diff): self.text.insert(END, self.digits[ix+i]) self.digits_displayed = self.digits_calculated self.master.title('%d digits of pi' % self.digits_displayed) self.master.after(100, self.check_digits) root = Tk() root.option_readfile('optionDB') example = ThreadExample(root) root.mainloop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sebastien.Boisgerault at gmail.com Wed May 4 08:54:43 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 4 May 2005 05:54:43 -0700 Subject: About Encapsulation In-Reply-To: References: Message-ID: <1115211283.929662.127820@f14g2000cwb.googlegroups.com> You mean private, protected, public, that kind of stuff ? They do not exist in Python. Conventionally if you don't want the user of a class to access a method or attribute, you use the prefix _ ; class K(object): _a = 1 def __init__(self, val): self.arg = val self._hidden = 1 def _method(self): pass The _hidden attribute can still be accessed by ... >>> h = K()._hidden ... but hey ! You know you *should* not. It's the "we are all consenting adults" philosophy of programming. By the way, K._method and K._a won't appear in the (py-)doc of the class ... Cheers, SB From rupole at hotmail.com Thu May 19 03:57:00 2005 From: rupole at hotmail.com (Roger Upole) Date: Thu, 19 May 2005 03:57:00 -0400 Subject: soundcard readout on a windows system References: Message-ID: <428c47ab$1_1@spool9-west.superfeed.net> Take a look at the directsound module from Pywin32. I haven't used it myself, but it may be able to do what you need. Roger "Jan Wienhausen" wrote in message news:d6fd1k$bio$1 at rzsun03.rrz.uni-hamburg.de... > Hi, > I would like to read out the soundcard with python on a win system. Is > there any possibillity to do so? > > Thanks, > Jan ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From andreas at kostyrka.org Thu May 19 13:17:16 2005 From: andreas at kostyrka.org (andreas at kostyrka.org) Date: Thu, 19 May 2005 19:17:16 +0200 Subject: SSL (HTTPS) with 2.4 In-Reply-To: <428CC477.6070508@fluent.com> References: <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> <1116521081.100575.70720@f14g2000cwb.googlegroups.com> <428CC477.6070508@fluent.com> Message-ID: <20050519171716.GA16953@heaven.kostyrka.org> Hi! HTTPS over a proxy (CONNECT) hasn't worked for a long time in python (actually it has never worked). A quick glance at the 2.4 Changelog doesn't suggest that this has been fixed. So basically you've got the following options: a) redo your own http/https support. b) look around on the net for some patches to httplib (google is your friend) be aware that these are quite old patches. c) using some external solution, like pycURL. Andreas On Thu, May 19, 2005 at 12:53:11PM -0400, Andrew Bushnell wrote: > Thanks for the update. I will/can keep you posted. I know for a fact we > use a Squid proxy which sounds like what you are using. I am going to > check out the faq you sent and see what it comes up with. I have also > been perusing the net a bit and looking at other client packages and see > if they work, such as cURL etc. > > Thanks, > > Andrew > > Bloke wrote: > > Andrew, > > > > It seems I'm not the only one going nuts here. I have just spent the > > last 4 hrs stepping through the code in the debugger. It seems to get > > stuck somewhere in the socket module (when it calls ssl) but haven't as > > yet figured out exactly where. > > > > I am _very_ interested to find that you have the same prob with a > > non-authenticating proxy. I had considered I was doing something wrong > > with the authentication, but from what you say, and from what I have > > deduced from the code, it is not the authentication that is at fault. > > > > Like you, a standard browser works fine, so I'm inclined to think there > > is something buggy with the way the sockets module talks to the proxy. > > There has been some suggestion that it may me a 'Microsoftish' proxy > > which is at fault, but I believe it is a Squid proxy our company uses. > > > > There is an interesting note here ( > > http://www.squid-cache.org/Doc/FAQ/FAQ-11.html setcion 11.34 ) > > regarding malformed https requests sent through Squid with buggy > > clients. It may be worth looking into. > > > > Anyway, if you have any luck, _please_ let me know - I'm getting > > desparate. > > > > -- > ************************************ > Andrew Bushnell > Lead Development Engineer > Fluent Inc. > 10 Cavendish Court > Centerra Resource Park > Lebanon, NH 03766 > awb at fluent.com > Phone: 603-643-2600, ext. 757 > Fax: 603-643-1721 > www.fluent.com > ************************************ > -- > http://mail.python.org/mailman/listinfo/python-list From Scott.Daniels at Acm.Org Sun May 22 09:28:43 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 22 May 2005 06:28:43 -0700 Subject: Python Polymorphism In-Reply-To: References: <20050512200045.85674.qmail@web52604.mail.yahoo.com> Message-ID: <4290827f$1@nntp0.pdx.net> Joal Heagney wrote: > ... "If you're sick of answering newbie questions, and don't > think you can do so politely, for the sake of the community, > DON'T!" You're not that necessary. +1 QOTW (or at least FAQ) --Scott David Daniels Scott.Daniels at Acm.Org From timothy at open-networks.net Thu May 5 17:38:49 2005 From: timothy at open-networks.net (Timothy Smith) Date: Fri, 06 May 2005 07:38:49 +1000 Subject: Py2Exe security In-Reply-To: <1115249595.645525.233470@z14g2000cwz.googlegroups.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> <1115129613.564775.21660@g14g2000cwa.googlegroups.com> <117f3lk633rbs87@corp.supernews.com> <1115249595.645525.233470@z14g2000cwz.googlegroups.com> Message-ID: <427A9269.3020104@open-networks.net> i used to work in a place that did this exact same thing. they attempted to hide passwords in source code. there is an even bigger problem with this then security of it in source - if someone comprimises the password, how are you going to change it quickly? all those systems will have to update their exe. keep in mind they could get it any other number of ways forcing you to change it. it's the same reason it's not a good idea to put static address's in source. From gerard.blais at gmail.com Mon May 2 15:04:37 2005 From: gerard.blais at gmail.com (Gerard C Blais) Date: Mon, 02 May 2005 15:04:37 -0400 Subject: urllib2 and timeout question Message-ID: I'm trying to get a page from a slow server. and i'm timing out. I've tried socket.setdefaulttimeout9300), and urllib2.socket.setdefaulttimeout(300), and urllib2.socket.setdefauttimeout(300.0), but all seem to give up after 20 seconds. What's the best (or a good) way to increase the timeout? (the url works fine, but slowly, when pasted into a browser) Thanks, Gerry ============ Code below: import time import urllib2 import socket starting_time = time.clock() socket.setdefaulttimeout(300) print "timeout set" lat = 38.836971 lon = -77.378228 starting_width = 20 ending_width = 0.01 index = 0 width = starting_width while width > ending_width: width *= 0.3 index += 1 url = "http://tiger.census.gov/cgi-bin/mapper/map.gif?lat=" + str(lat) + \ "&lon=" + str(lon) + \ "&wid=" + str(width) + \ "&iht=719&iwd=843&&on=majroads&mlat=" + str(lat) + \ "&mlon=" + str(lon) + \ "&msym=redpin&mlabel=SMM&conf=mapnew.con" url_start_time = time.clock() print round(starting_time,0), url try: fd = urllib2.urlopen(url) except: print time.clock(), "timed out" From kay.schluehr at gmx.net Wed May 25 08:10:51 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 25 May 2005 05:10:51 -0700 Subject: open file in dir independently of operating system In-Reply-To: <1117021114.316734.117480@o13g2000cwo.googlegroups.com> References: <1117021114.316734.117480@o13g2000cwo.googlegroups.com> Message-ID: <1117023050.964065.241820@g14g2000cwa.googlegroups.com> Joerg Schuster schrieb: > Hello, > > > I want to open the file 'configuration.smo' that is in directory dir. > Yet, I don't know on which os my program is being run. On Unix I would > say: > > f = open(dir + '/configuration.smo', 'r') > > What is the os-independent version of this line? Did You check this out on Windows? My experience with *nix paths is that they work. >>> open("C:/bla.txt") Kay From rkern at ucsd.edu Wed May 25 21:58:32 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 25 May 2005 18:58:32 -0700 Subject: Checking for a full house In-Reply-To: <1117071824.882035.250710@g49g2000cwa.googlegroups.com> References: <1117071824.882035.250710@g49g2000cwa.googlegroups.com> Message-ID: mwdsmith wrote: > Hi, I'm new to python, and I'm not sure if this is the place to post > this kind of question; so feel free to tell me if I should take this > elsewhere. > > So, to start me off on python, I decided to put together a little > script to test the probabilities of rolling certain combinations of > dice. Below is my code for checking for a full house (when rolling > with 5 dice). A roll is a list, eg [1, 3, 5, 1, 4] (this example is > not a full house) > > def removeAll(element, num2Rem, list): > l = list[:] > for num in range(0, num2Rem): > l.remove(element) > return l > > def isfullHouse(roll): > for die in range(1,7): > if roll.count(die)==3: > l = removeAll(die, 3, roll) > if l[0]==l[1]: > return 1 > return 0 > > My questions is this: is there a better way to do this? A way that's > more natural to python, or just more efficient perhaps? > > ps. A roll of [1, 2, 1, 1, 2] is a full house (three of one kind and > two of another) def isFullHouse(roll): counts = [roll.count(die) for die in range(1,7)] counts.sort() return counts == [0, 0, 0, 0, 2, 3] -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From steve at holdenweb.com Tue May 3 06:49:16 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 May 2005 06:49:16 -0400 Subject: lists in cx_Oracle In-Reply-To: References: <1115047620.602263.180780@o13g2000cwo.googlegroups.com> <1115056746.166202.97140@f14g2000cwb.googlegroups.com> Message-ID: Andrew Dalke wrote: > Steve Holden wrote: > >>Do you think this is a DB-API 3-ish kind of a thing, or would it layer >>over DB-API 2 in a relatively platform-independent manner? > > ... > >>but-you-may-know-better-ly y'rs - steve > > > I am a tyro at this. I had to find some tutorials on SQL > to learn there even was an IN clause for the WHERE statement. > All told I've had about 1 hour experience using DB-API 2. > > I thought this would be a common enough need that others > would have chimed in by now saying "oh yes, you just need > to XYZ" where XYZ is something cleaner than "make a new > string to execute". > I seem to remember from a good while back that there have *been* database (perhaps even specifically Oracle) interface modules that supported a set-style interface in ways similar to your stated requirements, but alas it's a long time ago and the details are dim. Given that we now have a Decimal type, allowing us to fulfil an outstanding DB API wish list item, maybe it's time for DB API 3. Anyone? regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From devrim.erdem at gmail.com Mon May 23 13:28:02 2005 From: devrim.erdem at gmail.com (DE) Date: 23 May 2005 10:28:02 -0700 Subject: Terminating a thread from the parent Message-ID: <1116869282.045234.239040@g14g2000cwa.googlegroups.com> Hello, I have an app with embedded Python. Python scripts create their own threads and I need to terminate these threads at the point where the user wants to leave the application. I use threading.Thread as base classes. I have tried to use call the join method of the python thread objects from C++. But although the call succeeds, the threads don't exit. What is the proper way of doing this ? (e.g. how does the python shell do this ? ) Thanks in advance, Devrim. From mahs at telcopartners.com Fri May 13 13:44:04 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Fri, 13 May 2005 10:44:04 -0700 Subject: Safe eval, or how to get list from string In-Reply-To: <1115999726.286709.140690@f14g2000cwb.googlegroups.com> References: <1115999726.286709.140690@f14g2000cwb.googlegroups.com> Message-ID: bwooster47 at gmail.com wrote: > I've to use ConfigParser. > > It returns values that are exactly in the config file, so get string > variables like: > int1 with quotes and characers: "42" > this is easy to convert to int: > realint = int(int1) > > I've read the tutorial, and the FAQ, and not sure if I missed it, but > other than calling eval (which everyone says is unsafe), I don't know > if there is another way to do this: > string1 has "this is a string" or however complex a string (""" aaa > """). > I can do > realstring = eval(string1) > or > if there is list1 = "[ 'filea', 'fileb', ]", I can get at list by > doing: > reallist = eval(list1) > > is there an easier/simpler method of doing the same thing as realstring > and reallist lines above? > See: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 Michael From guy at r-e-d.co.nz Mon May 9 16:57:52 2005 From: guy at r-e-d.co.nz (Guy Robinson) Date: Tue, 10 May 2005 08:57:52 +1200 Subject: [Python.NET] Announce: Python for .NET 1.0 RC1 released In-Reply-To: References: Message-ID: <427FCED0.6080208@r-e-d.co.nz> Great Stuff!!! >(probably including a few specific > examples of embedding Python for .NET in a .NET application). Cool!! :-) Guy Brian Lloyd wrote: > Hi all - > > I'm happy to announce the release of Python for .NET 1.0 RC1. > You can download it from: > > http://www.zope.org/Members/Brian/PythonNet > > Highlights of this release: > > - Implemented a workaround for the fact that exceptions cannot be > new-style > classes in the CPython interpreter. Managed exceptions can now be > raised > and caught naturally from Python > > - Implemented support for invoking methods with out and ref parameters. > Because there is no real equivalent to these in Python, methods that > have out or ref parameters will return a tuple. The tuple will contain > the result of the method as its first item, followed by out parameter > values in the order of their declaration in the method signature. > > - Fixed a refcount problem that caused a crash when CLR was imported in > an existing installed Python interpreter. > > - Added an automatic conversion from Python strings to byte[]. This > makes > it easier to pass byte[] data to managed methods (or set properties, > etc.) as a Python string without having to write explicit conversion > code. Also works for sbyte arrays. Note that byte and sbyte arrays > returned from managed methods or obtained from properties or fields > do *not* get converted to Python strings - they remain instances of > Byte[] or SByte[]. > > - Added conversion of generic Python sequences to object arrays when > appropriate (thanks to Mackenzie Straight for the patch). > > - Added a bit of cautionary documentation for embedders, focused on > correct handling of the Python global interpreter lock from managed > code for code that calls into Python. > > - PyObject.FromManagedObject now correctly returns the Python None > object > if the input is a null reference. Also added a new AsManagedObject > method to PyObject, making it easier to convert a Python-wrapped > managed > object to the real managed object. > > - Created a simple installer for windows platforms. > > > All known bugs have also been fixed - thanks to all who have sent in issue > reports and patches for past releases. > > At this point, the only thing I plan to do before a 1.0 final is fix any > new issues and add to the documentation (probably including a few specific > examples of embedding Python for .NET in a .NET application). > > Enjoy! ;) > > > Brian Lloyd brian at zope.com > V.P. Engineering 540.361.1716 > Zope Corporation http://www.zope.com > -- Robinson eDesign, P/F: +64 7 866 0626 Rings Beach, M: 021 238 0839 -ltd coverage RD2, E: guy at r-e-d.co.nz Whitianga. New Zealand From strombrg at dcs.nac.uci.edu Tue May 31 21:26:57 2005 From: strombrg at dcs.nac.uci.edu (Dan Stromberg) Date: Wed, 01 Jun 2005 01:26:57 GMT Subject: ignoring SIGPIPE in a python script? Message-ID: I have a python script that sometimes gets a SIGPIPE signal, and errors out. And I want it to just terminate as though it had hit EOF. I'm running: signal.signal(signal.SIGPIPE,signal.SIG_IGN) ...in the main function, but the script is still erroring out on sigpipe when the consumer to its producer terminates early. Am I going to have to code in a handful of exceptions, and then conditionalize what happens in those exception handlers, to get the desired behavior? ISTR hearing that although bash notifies one of SIGPIPE errors, tcsh generally silently ignores them. From this, I conclude that it might be reasonable for my script to ignore SIGPIPE. Thanks! From manu.1982 at gmail.com Fri May 27 04:26:05 2005 From: manu.1982 at gmail.com (Manu) Date: 27 May 2005 01:26:05 -0700 Subject: ftplib fails when directory name contains spaces In-Reply-To: <1117141499.924280.19140@z14g2000cwz.googlegroups.com> References: <1117141499.924280.19140@z14g2000cwz.googlegroups.com> Message-ID: <1117182365.284394.166540@f14g2000cwb.googlegroups.com> Oops..It was my mistake :(. Directory name with spaces work by default. From theller at python.net Wed May 25 08:01:03 2005 From: theller at python.net (Thomas Heller) Date: Wed, 25 May 2005 14:01:03 +0200 Subject: open file in dir independently of operating system In-Reply-To: References: <1117021114.316734.117480@o13g2000cwo.googlegroups.com> Message-ID: <3fj7nvF81tj6U1@individual.net> Gerald Klix schrieb: > Hi, > it`s > > import os > f = open( os.path.join( dir , 'configuration.smo' ), 'r' ) *nix-heads everywhere? For a text file, I would prefer: f = open( os.path.join( dir , 'configuration.smo' ), 'U' ) and for a binary file: f = open( os.path.join( dir , 'configuration.smo' ), 'rb' ) That way it also works on Windows. Thomas > > Joerg Schuster schrieb: > >> Hello, >> >> >> I want to open the file 'configuration.smo' that is in directory dir. >> Yet, I don't know on which os my program is being run. On Unix I would >> say: >> >> f = open(dir + '/configuration.smo', 'r') >> >> What is the os-independent version of this line? >> >> (I have read the manual of the module os, but I didn't see how to do >> it.) >> >> >> J?rg Schuster >> > From exogen at gmail.com Sat May 14 15:24:27 2005 From: exogen at gmail.com (Brian Beck) Date: Sat, 14 May 2005 15:24:27 -0400 Subject: Returning Date As String ? In-Reply-To: References: Message-ID: Peter Moscatt wrote: > I am wanting to return the system date using the following: > > date.today() > > How would I then convert this to a string ? Use the strftime method. The formatting directives are documented here: http://docs.python.org/lib/module-time.html Example: date.today().strftime("%B %d, %Y") -- Brian Beck Adventurer of the First Order From skip at pobox.com Tue May 3 10:57:11 2005 From: skip at pobox.com (Skip Montanaro) Date: Tue, 3 May 2005 09:57:11 -0500 Subject: atexit not being executed In-Reply-To: References: Message-ID: <17015.37191.253238.398725@montanaro.dyndns.org> Chris> I tried looking through the documentation ... Always a good first step... Chris> ... and came across atexit. I tried putting this into my code and Chris> it never seems to actually process the atexit.register(....) Chris> function thus leaving me stranded. My question is what might be Chris> the reason for this happening ... You didn't post any code, so I can only guess, however, if your program exits other than by calling Py_Finalize (that is, if your program crashes or you kill it forcefully), I don't think your registered exit functions will be called. If that's not the situation, post some code so people can see if you're using the module correctly. Skip From jeffh at activestate.com Sun May 15 22:47:06 2005 From: jeffh at activestate.com (Jeff Hobbs) Date: Sun, 15 May 2005 19:47:06 -0700 Subject: BLT with TCL/TK 8.4.9 and Python 2.4 In-Reply-To: References: Message-ID: <428809AA.3020904@activestate.com> Kenneth Miller wrote: > Has anyone acheived this? There is no reason why Tkinter couldn't load BLT (from the Tcl side). You could wrap it up into a Tkinter-style widget, or just drive it through lower level evals. -- Jeff Hobbs, The Tcl Guy http://www.ActiveState.com/, a division of Sophos From turbos10 at interia.pl Sun May 29 14:57:36 2005 From: turbos10 at interia.pl (turbos10) Date: Sun, 29 May 2005 20:57:36 +0200 Subject: double w pythonie? References: Message-ID: w turbos10 napisa?(a): > Witam! > Z jaka precyzja python dokonuje obliczen zmiennoprzecinkowych. Czy > jest w pythonie typ podwojnej precyzji (double z c). sorry! -- Uwagi o b??dach ortograficznych czy interpunkcyjnych, oraz wszelkie s?owne utarczki za?atwiaj listami prywatnymi. From jacob at cd.chalmers.se Mon May 23 10:58:41 2005 From: jacob at cd.chalmers.se (Jacob Hallen) Date: 23 May 2005 14:58:41 GMT Subject: Optimise Europython competition References: Message-ID: In article , Carl Friedrich Bolz wrote: >Jacob Hallen wrote: >> 2. A track should be continuous. Each track that is continuous gives you >> 10 points. > >What exactly do you mean by "continuous track"? Continuous means that from the time of the first talk in the track until all talks in the track have been given, there will be a talk from the track in each time slot (in exceptional cases there can be an empty time slot inserted to make things fit, but usually that is not needed.) The main reason for this rule is that some people only come for a few talks in a specific track, and they don't want to have to stay 3 days because we scheduled some on Monday morning and the rest on Wednesday morning. Last year we even had 2 people driving down from Norway, paying the 270 Euro on-site fee, just to listen to a single talk. They then had a chat with the speaker and went home, quite happy with their conference. Jacob Hall?n -- From fredrik at pythonware.com Thu May 12 14:11:47 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 May 2005 20:11:47 +0200 Subject: Python Documentation (should be better?) References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> Message-ID: Christopher J. Bottaro wrote: > My idea for a manual's table of contents: > > 1. Variables python doesn't have variables. the corresponding construct is described in chapter 4 in the language reference. > 2. Conditional and Branching Constructs chapter 6 and 7 in the language reference: > 3. Looping Constructs chapter 7 in the language reference. > 4. Functions chapter 5 for function calls (functions are just one of many kinds of callable objects). chapter 7 in the language reference for definitions. > 5. Modules chapter 6 in the language reference for use. chapter 8 in the language reference for definitions. > 6. Classes chapter 5 in the language reference for use (classes are just one of many kinds of callable objects, and instances are just one of many kinds of objects with attributes). chapter 7 in the language reference for definitions. > 7. Exceptions chapter 4 in the language reference. > 8. Built-in > 8.1 Functions chapter 2.1 in the library reference (titled "Built-in Functions") > 8.2 Types chapter 2.3 in the library reference (titled "Built-in Types") so everything you asked for can be the language reference manual and the first two chapters of the library reference manual, in pretty much the same order as you wanted it (the exceptions chapter is the exception) > (i.e. not in a manual, but the library reference). if a reference manual is not a manual, we have a terminology problem. From fredrik at pythonware.com Thu May 12 06:54:55 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 May 2005 12:54:55 +0200 Subject: TAKE_FOCUS References: <428229E6.4040900@anvilcom.com> Message-ID: "phil" wrote: > WM_TAKE_FOCUS does not work on WinXP ?? > I was sure I had used that on win before. > Works on Linux. > > I have a function I need to run when the window > gets the focus. How do you do that in Tkinter > on Win32? binding the event should work. (and make sure that the takefocus option is set) From foobar at mystery.org Mon May 9 18:43:37 2005 From: foobar at mystery.org (Sean Burke) Date: Mon, 09 May 2005 22:43:37 GMT Subject: Language documentation ( was Re: Computing Industry shams) References: <1115509201.680334.140840@f14g2000cwb.googlegroups.com> <874qdezh76.fsf@kafka.homenet> <1415322.AzhuxSBQdk@yahoo.com> Message-ID: alex goldman writes: > vermicule wrote: > > > > > What is so hard to understand ? > > Should be perfectly clear even to a first year undergraduate. > > > > As for "greedy" even a minimal exposure to Djikstra's shortest path > > algorithm would have made the concept intuitive. And from memory, > > that is the sort of thing done in Computing 101 and in Data Structures > > and Algorithms 101 > > > > It seems to me that you want the Python doc to be written for morons. > > And that is not a valid complaint. > > He's right actually. If we understand the term "greedy" as it's used in > graph search and optimization algorithms, Python's RE matching actually IS > greedy. No, you're just confused about the optimization metric. In regexes, "greedy" match optimizes for the longest match, not the fastest. And this is common regex terminology - man perlre and you will find discussion of "greedy" vs. "stingy" matching. -SEan From fredrik at pythonware.com Thu May 12 06:44:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 May 2005 12:44:07 +0200 Subject: Destructor Woes, was Advice needed on __del__ References: <427FBAD4.3070004@anvilcom.com> <42800279.3B26FFF3@pauahtun.org> Message-ID: "flupke" wrote: >> Then i got a tip that you can register a function that needs to be >> called when the object is going to be deleted. >> For instance to register a function __exit, you do this: >> class line: >> def __init__(s,glob,argl,color=''): >> atexit.register(s.__exit) > I don't know what's wrong in your example. Here it works (doesn't help > you of course). I would first try with an easy example an try to test > the atexit functionality like that. It seems that the problem you are > having isn't related to the atexit part. do you (or whoever gave you the tip) have the slightest idea what atexit does? From f.geiger at vol.at Sat May 21 03:42:10 2005 From: f.geiger at vol.at (F. GEIGER) Date: Sat, 21 May 2005 09:42:10 +0200 Subject: [pysqlite] How do I use pysqlite in a multi-threading env.? References: Message-ID: "Gerhard Haering" schrieb im Newsbeitrag news:mailman.239.1116573867.8733.python-list at python.org... I've completely rewritten the db handling stuff, which formerly did too much behind the scenes (explicit is better than implicit...). Now everything looks much better. No unexpected errors and - most important - locking works as expected. I have no idea yet, what went wrong with the former (probably more pythonic) solution. It always did it with MySQL as backend. Anyway, I'm quite happy now, that I can work on a db, that is incorporated into the app itself. Thanks for your help, Gerhard! And, sorry for the troubles... Kind regards Franz GEIGER From cdkrug at worldnet.att.net Wed May 4 21:21:25 2005 From: cdkrug at worldnet.att.net (Charles Krug) Date: Thu, 05 May 2005 01:21:25 GMT Subject: Has anyone built a file reader for NIST IHEad? Message-ID: List: I'm playing with some image algorithms and one of the examples discusses fingerprint comparison. The NIST has fingerprint sample files for download, in NIST IHead format. Has anyone built a reader for that format? Thanks Charles From steven.bethard at gmail.com Thu May 26 16:22:04 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 26 May 2005 14:22:04 -0600 Subject: "...Learning with Python" ...a property that addition andmultiplication have... In-Reply-To: References: <1117067025.233387.323910@z14g2000cwz.googlegroups.com> Message-ID: GMane Python wrote: > string repetition can not repeat a value negative times: > 'hello' * -3 is invalid. Well, it's not invalid: py> 'a' * -1 '' py> 'a' * -42 '' but you could definitely say that S * N1 == S * N2 does not imply that N1 == N2 STeVe From jason.mobarak at gmail.com Sun May 8 00:50:01 2005 From: jason.mobarak at gmail.com (Jason Mobarak) Date: 7 May 2005 21:50:01 -0700 Subject: Python Pseudo-Switch In-Reply-To: References: Message-ID: <1115527801.791201.310760@g14g2000cwa.googlegroups.com> James Stroud wrote: > Hello All, > > Because of my poorly designing a database, I have recently found it necessary > to explore the wonders of the Python pseudo-switch: > > do_case = { "A" : lambda x: x["bob"], > "B" : lambda x: x["carol"], > "C" : lambda x: "Ted", > "D" : lambda x: do_something(x) } > class CaseThing: def pref_A (self, x): return x["bob"] def pref_B (self, x): return x["carol"] def pref_C (self, x); return "Ted" def pref_D (self, x) return do_something(x) def getThing (self, x): attr = getattr(self, 'pref_%s' % (x,)) if attr is not None: return attr else: raise SomeError("Thing %s does not exist" % (x,)) my_thing = CaseThing().getThing(get_value_from_thin_air)(adict) You can do something similar with method decorators for more complex strings than what's allowed for python method names. > my_thing = do_case[get_value_from_thin_air()](adict) > > > How to handle this kind of thing when lambda is removed from the language, > beside the obvious def'ing those tiny little functions? > > James > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ From correiajREMOVECAPS at hotmail.com Sat May 21 13:56:31 2005 From: correiajREMOVECAPS at hotmail.com (J Correia) Date: Sat, 21 May 2005 17:56:31 GMT Subject: How to receive events (eg. user mouse clicks) from IE References: <1116476411.853695.235670@g14g2000cwa.googlegroups.com> <428c3cbe$1_1@spool9-west.superfeed.net> <1116529345.146032.91880@f14g2000cwb.googlegroups.com> <428cf5a9$1_1@spool9-west.superfeed.net> <1116537405.495521.252570@f14g2000cwb.googlegroups.com> <428f5882$1_2@spool9-west.superfeed.net> Message-ID: "Roger Upole" wrote in message news:428f5882$1_2 at spool9-west.superfeed.net... > There does appear to be some sort of conflict between the two event > hooks. I wasn't seeing it before since IE was getting google from my > browser cache and it was coming up almost instantaneously. As soon > as I switched the URL to a page that loads slowly, I got the same > result. > > Adding win32gui.PumpWaitingMessages() to the wait loop > seems to allow both event hooks to run without blocking each other. > > Roger I added that line to the wait loop and while it does indeed speed it up dramatically (in 10 tests: min = 13 sec; max = 33, ave ~ 20 secs) it's still nowhere near the 1-2 secs it takes without hooking the IE events. I also can't explain the wide differences between min and max times since they seem to occur randomly (e.g. min occurred on 7th run, max on 4th). I assume that that response time won't be adequate for the original poster's needs, due to the slowdown in browsing for his users. Jose From siona at chiark.greenend.org.uk Tue May 10 10:25:05 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 10 May 2005 15:25:05 +0100 (BST) Subject: Advice needed on __del__ References: Message-ID: <5as*qedOq@news.chiark.greenend.org.uk> =?ISO-8859-1?Q?Andr=E9_Roberge?= wrote: >If I need to have the user call Evil.destroy() as Evil >is getting out of scope, it would miss the whole point >of teaching about the natural way scope and namespace >work. The problem, it seems to me, is that in Python "scope" applies to names, but you're trying to apply it to objects. A name going out of scope shouldn't be assumed to have much of an impact on the object it referred to, and by emphasising too close a link between name and object I think you're more likely to run into trouble later on. As was pointed out upthread, Python isn't C++. (Speaking as someone who's been bitten by a very similar issue due to Java not being C++ either.) -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From blake.garretson at gmail.com Wed May 25 10:44:58 2005 From: blake.garretson at gmail.com (Blake Garretson) Date: Wed, 25 May 2005 10:44:58 -0400 Subject: Localized Type Inference of Atomic Types in Python In-Reply-To: <4293B4A6.8030002@ocf.berkeley.edu> References: <4293B4A6.8030002@ocf.berkeley.edu> Message-ID: <6d1f445d05052507446cb33e54@mail.gmail.com> On 5/24/05, Brett C. wrote: > > My thesis, "Localized Type Inference of Atomic Types in Python", was > successfully defended today for my MS in Computer Science at the > California > Polytechnic State University, San Luis Obispo. With that stamp of approval > I > am releasing it to the world. You can grab a copy at > http://www.drifty.org/thesis.pdf . > That is one beautiful document. Seriously nice LaTeX work here. The content is nice too (mostly over my head), but I thoroughly enjoyed the beautiful typesetting, TOC, PDF outline, links, footnotes, etc. -- Blake T. Garretson --- http://blakeg.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From rschroev_nospam_ml at fastmail.fm Sun May 1 06:37:45 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Sun, 01 May 2005 10:37:45 GMT Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> Message-ID: Roel Schroeven wrote: > Dan Bishop wrote: > > >>Dan Bishop wrote: >> >>Correction: Now I'm stuck on Level 11. I think I'm supposed to do >>something with the pixels in the image, but what? > > > Me too. There's a new image on the website now (still the same name though); I solved the riddle now :-) There's no level 12 yet though. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From awb at fluent.com Thu May 19 12:53:11 2005 From: awb at fluent.com (Andrew Bushnell) Date: Thu, 19 May 2005 12:53:11 -0400 Subject: SSL (HTTPS) with 2.4 In-Reply-To: <1116521081.100575.70720@f14g2000cwb.googlegroups.com> References: <1116392416.139727.84630@g49g2000cwa.googlegroups.com> <428AD4D1.8030405@v.loewis.de> <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> <1116521081.100575.70720@f14g2000cwb.googlegroups.com> Message-ID: <428CC477.6070508@fluent.com> Thanks for the update. I will/can keep you posted. I know for a fact we use a Squid proxy which sounds like what you are using. I am going to check out the faq you sent and see what it comes up with. I have also been perusing the net a bit and looking at other client packages and see if they work, such as cURL etc. Thanks, Andrew Bloke wrote: > Andrew, > > It seems I'm not the only one going nuts here. I have just spent the > last 4 hrs stepping through the code in the debugger. It seems to get > stuck somewhere in the socket module (when it calls ssl) but haven't as > yet figured out exactly where. > > I am _very_ interested to find that you have the same prob with a > non-authenticating proxy. I had considered I was doing something wrong > with the authentication, but from what you say, and from what I have > deduced from the code, it is not the authentication that is at fault. > > Like you, a standard browser works fine, so I'm inclined to think there > is something buggy with the way the sockets module talks to the proxy. > There has been some suggestion that it may me a 'Microsoftish' proxy > which is at fault, but I believe it is a Squid proxy our company uses. > > There is an interesting note here ( > http://www.squid-cache.org/Doc/FAQ/FAQ-11.html setcion 11.34 ) > regarding malformed https requests sent through Squid with buggy > clients. It may be worth looking into. > > Anyway, if you have any luck, _please_ let me know - I'm getting > desparate. > -- ************************************ Andrew Bushnell Lead Development Engineer Fluent Inc. 10 Cavendish Court Centerra Resource Park Lebanon, NH 03766 awb at fluent.com Phone: 603-643-2600, ext. 757 Fax: 603-643-1721 www.fluent.com ************************************ From rganesan at myrealbox.com Tue May 3 00:03:47 2005 From: rganesan at myrealbox.com (Ganesan Rajagopal) Date: 03 May 2005 09:33:47 +0530 Subject: Python Challenge ahead [NEW] for riddle lovers References: Message-ID: >>>>> "darren" == darren kirby writes: > quoth the Ganesan Rajagopal: >> I am stuck on level 3. I've tried every re that I can think of. Some body >> give me a clue. >> >> Ganesan >> >> -- >> Ganesan Rajagopal >>>> t = /text of page source.../ >>>> re.findall('[a-z][A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]', t) > You should get ten results. Consider all ten together to get your > solution... Ah, thanks. I tried having both sides identical, no results. Then I tried the above re but stopped at the first result :-(. Ganesan -- Ganesan Rajagopal From mcaloney at cs.queensu.ca Tue May 3 22:23:57 2005 From: mcaloney at cs.queensu.ca (Chris McAloney) Date: Tue, 3 May 2005 22:23:57 -0400 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: <3dg5isF6qe1nhU1@news.dfncis.de> <1f7befae05043000165448b8d@mail.gmail.com> Message-ID: On Tue, 3 May 2005, Tim Peters wrote: > Hmm. I've been staring at that one 18 hours a day since last Friday, I'm very relieved to hear that I'm not the only one, then. > > I've decoded the first message to get the hint for the next level. > > It's not nice to humilate your elders in public, Chris. No humiliation was intended -- I was simply trying to use this fact as a form of currency to hopefully barter myself a useful hint. ;-) -chris From fredrik at pythonware.com Mon May 9 08:37:10 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 9 May 2005 14:37:10 +0200 Subject: Exception in Python 2.3.3 Interpreter References: <1114434259.853654.272420@z14g2000cwz.googlegroups.com> Message-ID: "Saravanan D" wrote: > 03 023ffaa4 1e013182 00000000 055b1250 00637470 python23!cmp_outcome(int op > = 88026108, struct _object * v = 0x00000001, struct _object * w = > 0x00000000)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880] > 04 023ffb18 1e016ba4 014f3318 00000002 0099f170 python23!eval_frame(struct > _frame * f = 0x053f2bfc)+0x542 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c > @ 1965] > 05 023ffb30 1e016a69 0099f170 023ffb7c 00000002 > python23!fast_function(struct _object * func = , struct > _object *** pp_stack = , int n = , > int na = , int nk = )+0x94 the above doesn't look very healthy. does your application involve non-standard extensions (including extensions you've written your- self)? does the extensions contain callbacks into Python code? From gvandyk.nospam at agileworks.net Tue May 31 01:57:05 2005 From: gvandyk.nospam at agileworks.net (Gerrit van Dyk) Date: Tue, 31 May 2005 07:57:05 +0200 Subject: eric3 question In-Reply-To: References: Message-ID: Alexander Zatvornitskiy wrote: > Hello All! > > I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a trouble. I > use this code: > print "enter q to quit, or smthing else to continue" > while not sys.stdin.readline()=="q": > smthing(else) > Try using raw_input() instead of the sys.stdin.readline(). raw_input() is the preferred way of getting console input. Like this: print "enter q to quit, or smthing else to continue" while not raw_input() == 'q': smthing(else) Or you can do it this way: while not raw_input("enter q to quit, or smthing else to continue: ") smthing(else) Gerrit van Dyk From jello at comics.com Fri May 6 08:45:48 2005 From: jello at comics.com (rzed) Date: Fri, 06 May 2005 08:45:48 -0400 Subject: Setting the corner color in rotated PIL images References: Message-ID: [Following up] > ----- Original Message ----- > From: "rzed" > Newsgroups: comp.lang.python > To: > Sent: Sunday, May 01, 2005 1:17 PM > Subject: Setting the corner color in rotated PIL images > > >> I'm using PIL to generate some images which may be rotated at >> the user's option. When they are rotated, the original image is >> cropped in the new image (which is fine), and the corners are >> black (which is not, in this case). I can't find any documented >> way to change the default fill color (if that's what it is) for >> the corners, and PIL also doesn't seem to support a flood fill. >> I have created a flood fill in Python, which works but which >> markedly slows image generation. >> "Anthra Norell" wrote in news:mailman.91.1115117893.6583.python-list at python.org: > I just had the same problem the other day. I solved it by > starting out with an image large enough to retain enough white > area following the rotation. > > Frederic > I found another method that doesn't require the larger size and cropping :) but does require two copies of the original image :( (sort of). I copy the image and rotate the copy, then I create an all-white image of the same size as the original and rotate it by the same amount. Then I use ImageChops composite() to combine the rotated copy, the original copy, and the black-and-white version (parameters in that order). The black corners of the b/w version serve as a mask to paste the original corners onto the copy. It still seems like a lot of trouble to go to, but I don't think there is a ready solution otherwise. I think there's a C-code memset of all zeroes that underlies the black corners thing, and that's not likely to change. -- rzed From franz.steinhaeusler at utanet.at Tue May 3 02:32:56 2005 From: franz.steinhaeusler at utanet.at (Franz Steinhaeusler) Date: Tue, 03 May 2005 08:32:56 +0200 Subject: Which IDE is recommended? References: <426f90ac$1_2@rain.i-cable.com> <9f7v619jhigbtoksslnr88f4idoc6ejvu3@4ax.com> <1115039282.069052.287920@o13g2000cwo.googlegroups.com> Message-ID: <1l6e71ph78oui1a50udo2cf50eic6m47q4@4ax.com> On Mon, 02 May 2005 19:25:57 -0700, Bryan wrote: >dcrespo wrote: >>>But I personally recommend DrPython. (Not only, I'm a member of the >>>project). >> >> >> I saw this message and downloaded DrPython. It's very good: I like the >> class/functions browser while I'm coding... but I can't find the >> autocompletion feature you talk, and I think this feature is very >> important. Where it is? >> >> Daniel >> > >i saw this message too and i've been using it for the last couple days, but i >don't see the class/functions browser you are talking about. where is it??? > >thanks, > >bryan Did you try: Menu View => "Toggle Source Browser"? -- Franz Steinh?usler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ From rrr at ronadam.com Mon May 9 23:19:33 2005 From: rrr at ronadam.com (Ron Adam) Date: Mon, 09 May 2005 23:19:33 -0400 Subject: __brace__ (PEP?) In-Reply-To: <200505081629.03520.jstroud@mbi.ucla.edu> References: <200505081629.03520.jstroud@mbi.ucla.edu> Message-ID: <42802845.4050109@ronadam.com> James Stroud wrote: > Hello All, > > If "__call__" allows anobject() and "__getitem__" allows anobject[arange], why > not have "__brace__" (or some other, better name) for anobject{something}. > Such braces might be useful for cross-sectioning nested data structures: > > anary = [[1,2,3],[4,5,6]] > > anary{2} ==> [3,6] I could see possibly using it as a user defined container designator, but it wouldn't quite work like your examples. If you used the leading name in the same way as the 'r' in raw strings to differentiate a new container type. class j(User_Container): # what ever news/inits needed def anary(self, arg): # code for anary method jamesnewcontainer = j{[1,2,3],[4,5,6]} jamesnewcontainer.anary(2) ==> [3,6] >>>jamesnewcontainer j{[1,2,3],[4,5,6]} And this would work as well. >>>j{[4,3,2],[1,2,3],[5,4,3]}.anary(1) [3,2,4] It doesn't add anything new, but it could make working with custom storage objects easier. > Also, if this exists already, I apologize because I have not seen it in any > Python code before and I wouldn't know what to call it for googling. There might be cases of dictionary use ambiguity. But I can't think of any at the moment. _Ron From bill.mill at gmail.com Mon May 9 13:41:57 2005 From: bill.mill at gmail.com (Bill Mill) Date: Mon, 9 May 2005 13:41:57 -0400 Subject: Does anybody know the status of PyCon recordings? Message-ID: <797fe3d40505091041501d1f3d@mail.gmail.com> Hey all, There was a lot of talk on this list about recording pycon 2005 talks, but I never saw any messages saying that they'd actually been recorded. The wiki page ( http://www.python.org/moin/PyConDC2005/TalkRecording ) doesn't give links to any recordings. Does anybody know if these recordings exist and, if so, where they are? Peace Bill Mill bill.mill at gmail.com From mwm at mired.org Thu May 26 18:04:53 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 26 May 2005 17:04:53 -0500 Subject: Pyrex: step in for loop References: <3fmtshF8hj7vU1@individual.net> Message-ID: <86oeaxwsmy.fsf@guru.mired.org> "Luis P. Mendes" writes: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > I'm trying to improve speed in a module and substituted the pythonic > 'for in range()' for 'for i from min < i < max:' > > But, I need to define a step for the i variable. How can I do it? > > for example, how do I iterate through 80000 to 140000 with step 10000? guru% pydoc range Help on built-in function range in module __builtin__: range(...) range([start,] stop[, step]) -> list of integers Return a list containing an arithmetic progression of integers. range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0. When step is given, it specifies the increment (or decrement). For example, range(4) returns [0, 1, 2, 3]. The end point is omitted! These are exactly the valid indices for a list of 4 elements. so it's for i in range(80000, 140000, 10000): ... http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From timothy at open-networks.net Mon May 16 19:28:08 2005 From: timothy at open-networks.net (Timothy Smith) Date: Tue, 17 May 2005 09:28:08 +1000 Subject: Python on a public library computer In-Reply-To: <87r7g6rbz0.fsf@pobox.com> References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> Message-ID: <42892C88.6090609@open-networks.net> John J. Lee wrote: >"anton.vredegoor at gmail.com" writes: > > > >>Here's my situation: >> >>I'm typing this in a public library on a computer with OS windows 2000 >>server. I can run Internet explorer, word, excel and powerpoint, that's >>it. Maybe java, but it seems to be flaky. >> >>I want to run python scripts from this computer. At home I have a >>multi-computer network (from better times) but no internet access >> >> >[...] > >Why not Jython? > > >John > > how locked down is the computer? there's a few (brave) public access unix shell providers out there. if you could run telnet you could use them From jerf at jerf.org Thu May 5 23:02:06 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Thu, 05 May 2005 23:02:06 -0400 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> <117lmgrjssnlf04@corp.supernews.com> Message-ID: On Fri, 06 May 2005 02:44:43 +0000, Grant Edwards wrote: > On 2005-05-05, Jeremy Bowers wrote: > >> Since I think he mentioned something about predicting how much space it >> will take to print out, my suggestion is to run through whatever >> printing routines there are and get a string out, > > A step which will require him to tell the printing routine how many digits > he wants printed. Not necessarily; consider the str() of a float in Python, especially given the "significant digits" aspect (it may be ill-defined, but I can think of several well-defined ways to mean that, where str() embodies one of them). The easiest way to tell how long the number will be when str prints it out is to simply ask it. In C++, this may be harder, as your output software may insist on rendering everything directly, with no way to reach in and tell what it did. Imagine the standard IOStreams, without the ability to stream into a string. Now it's a lot harder to tell. So if you've got something "smart" like the default str() in Python, you may not be able to tell in advance what it is going to do, short of trying to manually reverse engineer it. I've tried that a few times, and in each instance, I can get 95-99%... but I never quite make it to 100%, usually because I find a bug somewhere and can't figure out how to characterize and replicate it. (The biggest of these so far was when I tried to reconstruct Tk's wrapping in a text widget, so I could tell how many screen lines the given piece of text I produced would consume, whereupon I discovered Tk didn't correctly wrap all Unicode characters... it correctly (as far as I could see) reported their widths, but happily let the characters run right off the right edge of the widget under certain circumstances I could never characterize without putting in even more effort than I cared to. The bugs aren't always *important*, one can imagine the opposite problem of wrapping a little too quickly, and it could be years before anyone notices if it's just a few pixels off in the right direction, but it'll still screw you up if you try to replicate it.) From lam at pcigeomatics.com Mon May 2 09:22:44 2005 From: lam at pcigeomatics.com (Thierry Lam) Date: Mon, 2 May 2005 09:22:44 -0400 Subject: Reading output from standard out Message-ID: Let's say I have a python program which prints output to standard out, let's call it HelloApp. How do I capture these outputs from the python GUI tkinter? For example, I want to call HelloApp from my GUI program and I want to send the output live to a tkinter text area. Thanks Thierry -------------- next part -------------- An HTML attachment was scrubbed... URL: From qwweeeit at yahoo.it Mon May 9 14:55:21 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 9 May 2005 11:55:21 -0700 Subject: Strip white spaces from source In-Reply-To: References: <1115590492.587606.108810@z14g2000cwz.googlegroups.com> Message-ID: <1115664921.611530.85510@f14g2000cwb.googlegroups.com> Hi Richie, thank you for your answer. Your solution is interesting but does not take into account some white spaces (like those after the commas, before or after mathematical operands etc...). Besides that I'm a almost a newbie in Python, and I have the very old programmers' habits (I don't use classes...). But I have solved nevertheless my problem (with the help of Alex Martelli and his fab method of "tokenize.generate_tokens(cStringIO.StringIO(string).readline" I have read in a clp answer of Alex to a question of Gabor Navy). If someone is interested (I think nobody...) I can give my solution. Bye. From jabel at plus.net Fri May 27 04:32:16 2005 From: jabel at plus.net (John Abel) Date: Fri, 27 May 2005 09:32:16 +0100 Subject: Running a python program during idle time only In-Reply-To: <4296D2E3.8060605@hathawaymix.org> References: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> <1116869538.611233.264960@g14g2000cwa.googlegroups.com> <5j64x9gz09.fsf@idiom.com> <4296D2E3.8060605@hathawaymix.org> Message-ID: <4296DB10.7070001@plus.net> Shane Hathaway wrote: >Mike Meyer wrote: > > >>On a completely different topic, this looks like the wrong way to solve >>the problem. You want to update a search engine based on changes to the >>underlying file system. The right way to do this isn't to just keep >>rescanning the file system, it's to arrange things so that your scanner >>gets notified of any changes made to the file system. I did something like >>this for my web site search engine, but that's hooked into the SCM that's >>used for propogating changes to the web site. I know someone is working >>on patches to the FreeBSD kernel to make this kind of thing work. It would >>seem that some of the "backup" facilities that worked by keeping a mirror >>of the disk on separate media would have to have used such hooks, but maybe >>not. >> >> > >I think you're right that filesystem change notification is what Carlos >needs. > >If you're interested in using Linux, Carlos, "inotify" is a new kernel >module that can notify your program of filesystem changes. It's not >folded into the mainline kernel yet, but it's a clean patch. > >http://www.edoceo.com/creo/inotify/ > >I don't know if Windows has anything like it. I'd be interested to hear >if it does. > >Shane > > As an alternative to inotify there's this http://oss.sgi.com/projects/fam/, with various libraries ( Perl, Python, etc ). J From anybutbush at hotmail.com Wed May 11 11:59:44 2005 From: anybutbush at hotmail.com (hans) Date: 11 May 2005 08:59:44 -0700 Subject: tes, no reply In-Reply-To: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> References: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> Message-ID: <1115827184.537831.312210@g49g2000cwa.googlegroups.com> zzzzzzzzzzzzzzzzzzzzz From Sebastien.Boisgerault at gmail.com Wed May 11 15:54:10 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 11 May 2005 12:54:10 -0700 Subject: optparse Message-ID: <1115841250.764632.296820@g47g2000cwa.googlegroups.com> Any idea why the 'options' object in # optparse stuff (options, args) = parser.parse_args() is not/couldn't be a real dict ? Or why at least it does not support dict's usual methods ? The next move after a parse_args is often to call a method 'do_stuff' with the args and options and I'd like to use a call such as: do_stuff(args, **options) This function signature is handy if you also need sometimes to call 'do_stuff' from the Python interpreter. Cheers, SB From bogus@does.not.exist.com Thu May 19 09:45:02 2005 From: bogus@does.not.exist.com () Date: Thu, 19 May 2005 13:45:02 -0000 Subject: No subject Message-ID: #! rnews 2056 Newsgroups: comp.lang.python Path: news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!border2.nntp.ams.giganews.com!nntp.giganews.com!fi.sn.net!newsfeed2.fi.sn.net!newsfeed3.funet.fi!newsfeed1.funet.fi!newsfeeds.funet.fi!newsfeed1.swip.net!swipnet!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp From: Harry George Subject: Re: ElementTree and xsi to xmlns conversion? X-Nntp-Posting-Host: cola2.ca.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Lines: 43 Sender: hgg9140 at cola2.ca.boeing.com Organization: The Boeing Company References: Mime-Version: 1.0 Date: Thu, 19 May 2005 13:24:58 GMT Xref: news.xs4all.nl comp.lang.python:378110 "Fredrik Lundh" writes: [snip] > > are you sure? the prefix shouldn't matter; it's the namespace URI that's important. > if you're writing code that depends on the namespace prefix rather than the name- > space URI, you're not using namespaces correctly. when it comes to namespaces, > elementtree forces you to do things the right way: > > http://www.jclark.com/xml/xmlns.htm > > (unfortunately, the XML schema authors didn't understand namespaces so they > messed things up: > http://www.w3.org/2001/tag/doc/qnameids-2002-04-30 > to work around this, see oren's message about how to control the namespace/prefix > mapping. in worst case, you can manually insert xsi:-attributes in the tree, and rely on > the fact that the default writer only modifies universal names) > > > > > First, thanks for ElementTree and cElementTree. Second, I've read the docs and see a lot of examples for building trees, but not a lot for traversing parsed trees. Questions: 1. Is there a good idiom for namespaces? I'm currently doing things like: UML='{href://org.omg/UML/1.3}' .... packages=ns2.findall(UML+'Package') 2. Is there a similar idiom which works for Paths? I've tried: packages=pkg1.findall(UML+'Namespace.ownedElement/'+UML+'Package') but haven't found the right combination, so I do step-at-a-time descent. -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 294-4718 From vcsekhar007 at yahoo.com Sat May 7 08:47:11 2005 From: vcsekhar007 at yahoo.com (Vijay Chandra Sekhar Parepalli) Date: Sat, 7 May 2005 05:47:11 -0700 (PDT) Subject: Outlook-Python Issue Message-ID: <20050507124711.12414.qmail@web60712.mail.yahoo.com> Hi there, Can any one please help in getting me Python-Outlook programming issueclarified. I just wanted to do the following using Python: 1)Open a New Oulook Mail Window 2) Fill the field: to-email address and Write somebody to it.(I DON#8217;t want to send it automatically) That#8217;s all. But, I am getting an error when I try toinitiate the MAPI-Session using object = win32com.client.Dispatch("Outlook.Application") ns =object.GetNamespace("MAPI") mapi =win32com.client.dynamic.Dispatch("MAPI.session") Error I see is : File "C:\Program Files\GNU\WinCvs2.0\Macros\TemplateCvsMacro.py", line 140, in SendMAPIMail mapi = win32com.client.Dispatch("MAPI.session") File"C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 95,in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File"C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 91,in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File"C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 79,in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,pythoncom.IID_IDispatch) pywintypes.com_error:(-2147221005, 'Invalid class string', None, None) Can any one please help me in this regard. Thanks, Sekhar __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From usenet at gungfu.de Sun May 15 09:52:39 2005 From: usenet at gungfu.de (=?iso-8859-1?q?Steffen_Gl=FCckselig?=) Date: 15 May 2005 06:52:39 -0700 Subject: Precision? Message-ID: <1116165159.269252.117830@g14g2000cwa.googlegroups.com> Hello, I've just wanted to check Python's abilities as a calculator and this is what came out: >>> 1.0 + 3.0 + 4.6 8.5999999999999996 Ehm, how could I get the intuitively 'correct' result of - say - 8.6? ;-) best regards Steffen From paul at f7.net Mon May 30 11:32:03 2005 From: paul at f7.net (Paul English) Date: Mon, 30 May 2005 11:32:03 -0400 Subject: No subject Message-ID: <200505301532.j4UFW3D31310@f7.net> Thanks for sending me email, but please click the following link or else my mail server will not deliver your message to me: http://blade.f7.net/cr.cgi/pme/python-list at python.org.1 I use this system to prevent spam. Once you click the above link, you will be added to the whitelist and not be challenged again. Thanks, Paul -- ps, see http://blade.f7.net for more information about this system. From eurleif at ecritters.biz Tue May 31 15:11:08 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Tue, 31 May 2005 19:11:08 GMT Subject: working with pointers In-Reply-To: References: Message-ID: Michael wrote: > a=2 > b=a > b=0 That's more or less equivalent to this C++ code: int *a; int *b; a = new int; *a = 2; b = a; b = new int; *b = 0; From tjreedy at udel.edu Sun May 15 14:54:12 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2005 14:54:12 -0400 Subject: Precision? References: <1116165159.269252.117830@g14g2000cwa.googlegroups.com> Message-ID: "Steffen Gl?ckselig" wrote in message news:1116165159.269252.117830 at g14g2000cwa.googlegroups.com... >>>> 1.0 + 3.0 + 4.6 > 8.5999999999999996 > > Ehm, how could I get the intuitively 'correct' result of - say - 8.6? >>> str(1.0+4.6+3.0) '8.6' See Lib Ref 2, Builtin functs, repr() and str(), Lan Ref (or tutorial) section on % formating, and probably a few FAQ entries. Terry J. Reedy From tjreedy at udel.edu Wed May 11 22:08:21 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2005 22:08:21 -0400 Subject: Python Documentation (vs PHP stuff) References: Message-ID: "Christopher J. Bottaro" wrote in message news:d5tqi2$d8l$2 at sea.gmane.org... > rbt wrote: >> Because PHP is such a 'thrown together' and 'bolted-on' language. If it >> didn't have *outstanding* documentation (which it does BTW), no one >> could even begin to understand how they got from a little HTML language >> to a kinda/sorta OO language. >> >> PHP is showing its age... thanks to its docs, it's still *extremely* >> useful. > > Exactly!! See thats what I'm saying. I _think_ its widely accepted that > PHP has awesome documentation. And like rbt said, that makes it > extremely > useful. Why can't Python have documentation like that? The language is > awesome, it just needs documentation of the same quality. Because of these two posts (and a few others) extolling the PHP documentation, I decided to take a look for myself to see what the fuss was about and whether I could get any ideas on how to improve Python's docs. I typed "PHP manual" in my Google bar and the first link was just what I hoped for, the PHP site manual. First observation: the PHP manual is a combined 'kitchen-sink' volume that combines material that Python separates: tutorial, language reference, library reference, and doc for some 3rd party packages. Hmm, perhaps the 3 official volumes would be better integrated if combined into one manul with three parts. But the difference itself between one volume with many parts and many volume is not critical in itself. Next, I picked the Array chapter in the Functions section. It starts with a Unix man-style intro. Ok, but not 'awsome'. Next come the defined constants, which don't mean much out of the context of the function where used, so this part functions as an index of names. Then there is a long alphabetical list of function name/links with a one-line description of each. Gee, there seem to be a lot of different sort functions. Finally, 80% of the chapter/page consists of a thrown-together mish-mash of unsorted. unedited comments and questions. Some seem like the equivalent of Python cookbook entries, but others are like run-of-the mill comp.lang postings. So the Python equivalent of this 'document' would include the Python Cookbook, the Python Wiki, and some of the c.l.p archives. Onward to the page for sort(), which bizarrely (to me) rekeys the 'array'. Then there is a cross-reference to the 9 other sort pages. Is there, I wonder, anyplace where all 10 sort functions are discussed together? This time, 90% of the page is user junk. Randomly clicking down, I find someone complaining about sort dumping his keys, just as the top entry said (but without the big warning box that such data destruction needs). Sorry, PHP doc fans: to me, this sort of inflated, noisey bloatware is wretched, not outstanding. Conclusion 1: if PHP is anything as awful as the manual, it is not for me. Conclusion 2: the somewhat spare style of the Python docs matches the somewhat spare style of the language itself. (My goodness, only one list sort method!). Since this style agrees with me, I would not want it to change too much. Conclusion 3: some people would apparently be happier with the Python docs if they were combined into one Python Manual. This could be done as a virtual anthology by writing a combined Table of Contents (with links) and an Introduction discussing the various 'Parts' and their interrelationships. It would not have to be limited to PSF material either. I might even take a stab at it if I ever feel sufficiently ambitious and energetic. Terry J. Reedy From bronger at physik.rwth-aachen.de Sat May 21 05:14:01 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Sat, 21 May 2005 11:14:01 +0200 Subject: IDLE 1.0.5 crashs on Windows References: <87ekc1ymu8.fsf@wilson.rwth-aachen.de> Message-ID: <87acmpym92.fsf@wilson.rwth-aachen.de> Hall?chen! Torsten Bronger writes: > I've installed Python 2.3.5, IDLE 1.0.5 on a Win2k box and have > fatal Windows errors with a trivial script. You can see a > screenshot of the problem at > . At http://www-users.rwth-aachen.de/torsten.bronger/idle_error2.png you see another error that I get when the soucecode looks slightly different. Sometimes it really crashes with a memory access error. My IDLE has gone mad, hasn't it? Tsch?, Torsten. -- Torsten Bronger, aquisgrana, europa vetus From bdesth.quelquechose at free.quelquepart.fr Fri May 13 15:40:35 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Fri, 13 May 2005 21:40:35 +0200 Subject: Python Documentation (should be better?) In-Reply-To: References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> <428276e8$0$318$626a14ce@news.free.fr> Message-ID: <4284fddf$0$6237$636a15ce@news.free.fr> Ivan Van Laningham a ?crit : (snip) > BTW, my "tortured method" is quicker than Bruno's, because to use his > method I'd have to start the interactive interpreter. > "start the interactive interpreter" ??? What do you mean, "start the interactive interpreter" ??? It's *always* started as a part of your development environnement, and not more than one keystroke away, isn't it ??? From sklass at pointcircle.com Sat May 21 14:53:34 2005 From: sklass at pointcircle.com (rh0dium) Date: 21 May 2005 11:53:34 -0700 Subject: Parsing XML - Newbie help Message-ID: <1116701614.858127.105550@g47g2000cwa.googlegroups.com> Hi all, I am relatively new to python and certainly new to XML parsing. Can some show me how to get the product text out of this? Really I want to know this has 2 processors and the are AMD Opteron(tm) Processor 250 I have gotten this far... class HWParser: def __init__(self): if os.path.isfile(LSHW): lshw=Exec.Exec(LSHW) lshw.execute('-xml') else: print "lshw does not exist", LSWH return "Unknown" self.data = lshw.read() self.error = lshw.error() self.exit = lshw.poll() if self.error: print "Error Exist", self.error return else: self.xml = minidom.parseString(self.data) self.xml.normalize() def p (self): print self.xml.toxml() If anyone can help me out that would be great! --- CPU AMD Opteron(tm) Processor 250 Advanced Micro Devices [AMD] 5 cpu at 0 15.5.10 CPU0 2400000000 3000000000 64 1600000000 mathematical co-processor FPU exceptions reporting virtual mode extensions debugging extensions page size extensions time stamp counter model-specific registers 4GB+ memory addressing (Physical Address Extension) machine check exceptions compare and exchange 8-byte on-chip advanced programmable interrupt controller (APIC) fast system calls memory type range registers page global enable machine check architecture conditional move instruction page attribute table 36-bit page size extensions multimedia extensions (MMX) fast floating point save/restore streaming SIMD extensions (SSE) streaming SIMD extensions (SSE2) fast system calls no-execute bit (NX) multimedia extensions (MMXExt) 64bits extensions (x86-64) multimedia extensions (3DNow!Ext) multimedia extensions (3DNow!) CPU AMD Opteron(tm) Processor 250 Advanced Micro Devices [AMD] 3 cpu at 1 15.5.10 CPU1 2400000000 3000000000 64 1600000000 mathematical co-processor FPU exceptions reporting virtual mode extensions debugging extensions page size extensions time stamp counter model-specific registers 4GB+ memory addressing (Physical Address Extension) machine check exceptions compare and exchange 8-byte on-chip advanced programmable interrupt controller (APIC) fast system calls memory type range registers page global enable machine check architecture conditional move instruction page attribute table 36-bit page size extensions multimedia extensions (MMX) fast floating point save/restore streaming SIMD extensions (SSE) streaming SIMD extensions (SSE2) fast system calls no-execute bit (NX) multimedia extensions (MMXExt) 64bits extensions (x86-64) multimedia extensions (3DNow!Ext) multimedia extensions (3DNow!) From cgarciaf at lucent.com Mon May 9 08:32:31 2005 From: cgarciaf at lucent.com (Carlos Garcia) Date: Mon, 9 May 2005 14:32:31 +0200 Subject: memory leak Message-ID: <066901c55493$2dc4b900$ba565887@1068801y07c0j> Hi All, I have a memory leak in an application that uses the Python.exec() method multiple times, i can see in jprobe that instance of classes org.python.pycode._pyx* and org.python.proxies.* dynamically created during an exec are not cleaned by the garbage collector. Any idea about what can i do? Thanks, Carlos ========================================================== Carlos Garc?a Phone : +34 91 714 8796 Lucent Technologies e-mail : cgarciaf at lucent.com Avenida de Bruselas , 8 - 28108 Alcobendas (Madrid) ========================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From kay.schluehr at gmx.net Tue May 31 19:10:35 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 31 May 2005 16:10:35 -0700 Subject: What's wrong with Zope 3 ? Message-ID: <1117581035.584193.310060@g47g2000cwa.googlegroups.com> The last downloadable release is from november 2004. The Windows installer is configured for Python 2.3(!). The Zope.org main page announces Zope 2.8 beta 2. Is it stillborn? Kay From claird at lairds.us Mon May 16 16:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Mon, 16 May 2005 20:08:03 GMT Subject: Faster GUI text control References: Message-ID: In article , Jeremy Bowers wrote: >On Fri, 13 May 2005 15:44:24 -0500, none wrote: > >> I'm trying to decide what is the best replacement for the control. I >> was originally planning on redoing the GUI with wxpython, but I've seen >> people indicate I would have the same problem. > >Honestly, if this is important to you, the best thing to do is try all the >ones relevant to your platform; generally creating a window with a text >widget and loading it with "a whole lotta text", as appropriate to your >app, is fairly easy; it is not true that once you've tried one GUI toolkit >you've tried them all, but each one is easier than the last, and >generally, you can: > >* Use the tutorial up to where they place a widget. > >* Jump to the reference manual where they describe the text widget and >insert it instead. > >* Fill the widget with a bunch of text. ("some string\n"*100000 or >something works well.) > >* Start the program and go. > >Not counting downloading, an hour each, tops. (The only tricky one that I >am aware of is that GTK insists that text widgets have to be in a Scrolled >Window to get a scrollbar on them.) > >The problem is that if you're really looking for performance, it may >differ based on the characteristics of the text and the quality of the >target computer, the platform (which you don't mention; GTK may scream in >Linux and make you scream in Windows...), etc., and there may be no one >person who can give you a firm "This is the best solution for your >situation" answer. The known Tkinter symptoms, incidentally, have more to do with *removing* content from a text than adding them. Any exercises, therefore, should not only load data into a text or near-text, but also remove them. From steve at REMOVETHIScyber.com.au Sun May 15 07:59:01 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 15 May 2005 21:59:01 +1000 Subject: Modifying a built-in function for logging purposes References: <1116098593.970438.219860@g47g2000cwa.googlegroups.com> <1116108841.429602.257380@o13g2000cwo.googlegroups.com> Message-ID: On Sat, 14 May 2005 15:14:01 -0700, qwweeeit wrote: > Hi Greg, > thank for your replay, but I didn't succeed in any way. You must > consider however that I'm not a Python "expert"... Can you post what you did and what results you got? Because Greg's trick worked for me. See below. > IMHO, it must be a script that change part of the interpreter, and > substitute a new module (py) in the place of the standard one (py or > pyc). The standard module must be saved in order to be able to undo the > changes and go back to the normal behaviour. The problem is that I don't > know if the built-in functions like open (or file) are written in Python > or in C and, besides that, if they can be modified. Why do you think it matters if they are written in Python or C or any other language for that matter? Almost everything in Python is a first-class object. That means you can rebind functions, methods, classes, and any other object. You can't rebind statements like print. But open is just an object: py> open py> print open("Something.txt", "r").read() some text in a file py> py> save_open = open >>> save_open py> py> def open(pathname, mode): ... print "The pathname is: " + pathname ... print "The mode is: " + mode ... return save_open(pathname, mode) ... py> contents = open("Something.txt", "r").read() The pathname is: Something.txt The mode is: r py> contents 'some text in a file' > Other solutions > which modify the source to be logged, are not solutions, because it is > far simpler to introduce here and there print statements... Bye. Introducing print statements is good for quick-and-dirty debugging. For more serious work, you should investigate the debug module. -- Steven From doodle4 at gmail.com Tue May 31 14:08:53 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 31 May 2005 11:08:53 -0700 Subject: array concatenation Message-ID: <1117562933.545487.249580@g47g2000cwa.googlegroups.com> Hello, I have 2 arrays defined with different typecodes. a = array('B', '\0', 6) b = array('L', '\0', 526) for i in range( 6): a[i] = 0xFF for i in range( 520): b[i] = 0xCCCCCCCC How do i concatenate these two arrays so that, i get b = 0xff 0xff 0xff 0xff 0xff 0xff 0xCCCCCCCC 0xCCCCCCCC ................................................... ................................................... 0xCCCCCCCC I need an array because i am using a buffer_info method. -Ashton From martin at v.loewis.de Tue May 17 15:07:13 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 17 May 2005 21:07:13 +0200 Subject: reference counting and file objects In-Reply-To: <7xoeb94r3j.fsf@ruckus.brouhaha.com> References: <7xoeb94r3j.fsf@ruckus.brouhaha.com> Message-ID: <428a40e1$0$29930$9b622d9e@news.freenet.de> Paul Rubin wrote: >>Consider the function above. Do I need the fp.close(), or will the >>file be closed automatically when fp goes out of scope and its >>reference count drops to zero? > > In CPython, fp gets closed when it leaves scope. One issue is that when the function terminates through an exception, the file stays open as long as the traceback is available, which exists until the next exception is raised (and thus replaces this traceback). If the function terminates normally (i.e. through return), it is as you say. Regards, Martin From kretino at net.hr Tue May 17 04:36:03 2005 From: kretino at net.hr (s) Date: Tue, 17 May 2005 10:36:03 +0200 Subject: Lex Python Message-ID: I am using bumblebee software PARSER GENERATOR to make a C file from LEX regular definitions. I want to compile that C file with VS .NET but I have problems. I am working this for Python regular definitions. Does somebody know how to configure a project to work? Or maybe somone havde done all this and can hel me in that way.I need this help soon as possible. Thanks From "none\" at (none) Sat May 14 15:40:29 2005 From: "none\" at (none) (none) Date: Sat, 14 May 2005 14:40:29 -0500 Subject: Faster GUI text control In-Reply-To: References: Message-ID: That's a good point about the amount of text available at once. As long as I could swap the visible section fast enough that might be a good solution. This will run mostly on Windows, but I'd like for it to be equally usable on Linux. From mj at zopatista.com Wed May 4 16:54:03 2005 From: mj at zopatista.com (Martijn Pieters) Date: Wed, 04 May 2005 22:54:03 +0200 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <877jihc7qv.fsf@uwo.ca> References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> <8764y29x3m.fsf@uwo.ca> <877jihc7qv.fsf@uwo.ca> Message-ID: <4279366B.6070800@zopatista.com> Dan Christensen wrote: > Any hints for level 13? I know how to make a call, but don't know "who" > to call. I haven't figured this one out yet either. Rather frustrating really. All the hints I've been given so far is to rmember the solution for level 12. Banging-my-head-against-it-didn't-help-either-ly yours, Martijn Pieters -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 264 bytes Desc: OpenPGP digital signature URL: From ville at spammers.com Mon May 16 10:02:11 2005 From: ville at spammers.com (Ville Vainio) Date: 16 May 2005 17:02:11 +0300 Subject: Ruby blocks finally coming to python? (was Re: python-dev Summary for 2005-04-16 through 2005-04-30 References: Message-ID: Just wanted to draw the attention by changing the subject line - see parent and especially: Tony> ---------------- Tony> PEP 340 Proposed Tony> ---------------- Tony> In the end, Guido decided that what he really wanted as a solution to Tony> `The Control Flow Management Problem`_ was the simplicity of something Tony> like generators that would let him write locking() as something like:: Tony> def locking(lock): Tony> lock.acquire() Tony> try: Tony> yield Tony> finally: Tony> lock.release() Tony> and invoke it as something like:: Tony> block locking(lock): Tony> CODE -- Ville Vainio http://tinyurl.com/2prnb From john at castleamber.com Thu May 12 02:19:24 2005 From: john at castleamber.com (John Bokma) Date: 12 May 2005 06:19:24 GMT Subject: Python Documentation (should be better?) References: <428276e8$0$318$626a14ce@news.free.fr> Message-ID: Ivan Van Laningham wrote: > Hi All-- > > John Bokma wrote: >> >> Ivan Van Laningham wrote: >> >> > Python docs are not as good as PHP docs. >> >> Oh my. I hope you are just making that up. PHP documentation is >> guesstimated on how PHP works on average. Add the online comments >> clutter and you probably are better off reading the source. >> > > I didn't write that; I was riffing on Christopher's contention that > Python's docs ought to be awesome, which I think ought to be true. Apologies for the misquoting :-) I couldn't even imagine that the statement could be true in anyway. I've read the introduction, and Dive into Python, which I highly recommend, and I liked what I read :-). -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html From exarkun at divmod.com Fri May 13 08:04:22 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 13 May 2005 12:04:22 GMT Subject: wxTimer problem In-Reply-To: Message-ID: <20050513120422.15422.1297260667.divmod.quotient.36467@ohm> On Fri, 13 May 2005 14:57:26 +0800, Austin wrote: >I wrote a GUI program on windows. (python & wxPython) >One function is to refresh the data from the COM Object continously. >In the beginning, I used the thread.start_new_thread(xxx,()) >But no matter how i try, it will cause the win32com error. > >After that, i use the wx.Timer to do the refresh function. >It works fine, but i find one problem. >I think timer should be independant, just like thread, but wxTimer doesn't. > >1. Does python have timer function( not included by thread)? >2. About the wxTimer, does any parameter to let it be independent? > What does "independent" mean? Jp From saravanand at vsnl.net Mon May 9 04:30:55 2005 From: saravanand at vsnl.net (Saravanan) Date: 9 May 2005 01:30:55 -0700 Subject: Exception in Python 2.3.3 Interpreter Message-ID: <1115627455.511797.7590@o13g2000cwo.googlegroups.com> Hello, Im running Python Application as a Windows Service (using windows extensions). But, sporadically the application crashes (crash in Python23.dll) and this stops the service. This problem cann't be reproduced easily in my system and the call stack generated by the application is given below. Please note that the call stack generation is taken from crash dump file. The crash occured at the following line: c = strcmp(vname, wname) (object.c) # ChildEBP RetAddr Args to Child 00 023ffa58 1e05c6da 055b1250 00637470 00000000 python23!default_3way_compare(struct _object * v = 0x053f2bfc, struct _object * w = 0x00000001)+0x102 [F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 689] 01 023ffa74 1e05c5ee 055b1250 00637470 00000000 python23!do_richcmp(struct _object * v = 0x1e0b9fb8, struct _object * w = 0x00000000, int op = 0)+0x4a 02 023ffa94 1e0174d9 055b1250 00637470 00000000 python23!PyObject_RichCompare(struct _object * v = 0x053f2bfc, struct _object * w = 0x00000001, int op = 0)+0x1ae [F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 1044] 03 023ffaa4 1e013182 00000000 055b1250 00637470 python23!cmp_outcome(int op = 88026108, struct _object * v = 0x00000001, struct _object * w = 0x00000000)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880] 04 023ffb18 1e016ba4 014f3318 00000002 0099f170 python23!eval_frame(struct _frame * f = 0x053f2bfc)+0x542 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 1965] 05 023ffb30 1e016a69 0099f170 023ffb7c 00000002 python23!fast_function(struct _object * func = , struct _object *** pp_stack = , int n = , int na = , int nk = )+0x94 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520] 06 023ffb5c 1e014b65 00a280d0 00000002 00000008 python23!call_function(struct _object *** pp_stack = 0x00000001, int oparg = 0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458] 07 023ffbcc 1e016ba4 006ea160 00000001 0099f1b0 python23!eval_frame(struct _frame * f = )+0x1f25 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117] 08 023ffbe4 1e016a69 0099f1b0 023ffc30 00000001 python23!fast_function(struct _object * func = , struct _object *** pp_stack = , int n = , int na = , int nk = )+0x94 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520] 09 023ffc10 1e014b65 00a280d0 00000001 00000000 python23!call_function(struct _object *** pp_stack = 0x00000000, int oparg = 0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458] 0a 023ffc80 1e015b6f 006cf6d0 00000000 00a1df9c python23!eval_frame(struct _frame * f = )+0x1f25 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117] 0b 023ffcac 1e040978 0096b720 00000001 006cf6d0 python23!PyEval_EvalCodeEx(struct PyCodeObject * co = , struct _object * globals = , struct _object * locals = , struct _object ** args = , int argcount = , struct _object ** kws = , int kwcount = , struct _object ** defs = , int defcount = , struct _object * closure = )+0x70f [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2663] 0c 023ffcf0 1e0078ec 009788b0 00a1df90 00000000 python23!function_call(struct _object * func = 0x1e0baa50, struct _object * arg = 0x0096b720, struct _object * kw = 0x00954390)+0x138 [F:\Python-2.3.3\Python-2.3.3\Objects\funcobject.c @ 512] 0d 023ffd04 1e01be03 009788b0 00a1df90 00000000 python23!PyObject_Call(struct _object * func = 0x1e0d7608, struct _object * arg = 0x00000001, struct _object * kw = 0x00a280d0)+0x1c [F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755] 0e 023fff24 1e0078ec 00a20f08 00671030 00000000 python23!instancemethod_call(struct _object * func = 0x1e0d7608, struct _object * arg = 0x00000001, struct _object * kw = 0x00a280d0)+0x133 [F:\Python-2.3.3\Python-2.3.3\Objects\classobject.c @ 2433] 0f 023fff38 1e016827 00a20f08 00671030 00000000 python23!PyObject_Call(struct _object * func = 0x77e4a990, struct _object * arg = 0x01415bd8, struct _object * kw = 0x00000000)+0x1c [F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755] 10 023fff50 1e080c77 00a20f08 00671030 00000000 python23!PyEval_CallObjectWithKeywords(struct _object * func = 0x77e4a990, struct _object * arg = 0x01415bd8, struct _object * kw = 0x00000000)+0xa7 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3346] 11 023fff70 1e080675 013d8ba0 00000000 014161a8 python23!t_bootstrap(void * boot_raw = 0x77e4a990)+0x37 [F:\Python-2.3.3\Python-2.3.3\Modules\threadmodule.c @ 183] 12 023fff84 77bc90a2 0086f32c 00000000 00000000 python23!PyThread_get_thread_ident(void)+0x5 [F:\Python-2.3.3\Python-2.3.3\Python\thread_nt.h @ 213] 13 023fffb8 77e4a990 01415bd8 00000000 00000000 msvcrt!_endthread+0xa6 14 023fffec 00000000 77bc9032 01415bd8 00000000 kernel32!BaseThreadStart+0x34 Any clues about the problem ? - Saravanan D From andre.roberge at gmail.com Fri May 20 11:42:41 2005 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Fri, 20 May 2005 12:42:41 -0300 Subject: ANN: new release of RUR-PLE available In-Reply-To: References: Message-ID: Michael Hoffman wrote: > Andr? Roberge wrote: > >>Version 0.8.6a is now available. > > > You might see a bit more interest if you briefly explain what RUR-PLE > is, and where to find it. Oops.. sorry about that. RUR - a Python Learning Environment. Its purpose is to provide an environment where people with no prior experience can learn computer programming (using Python of course!). RUR-PLE currently requires that both Python and wxPython be installed. More information can be found at http://rur-ple.sourceforge.net From steven.bethard at gmail.com Wed May 4 21:12:24 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 04 May 2005 19:12:24 -0600 Subject: min max of a list In-Reply-To: <1115245476.036508.273930@g14g2000cwa.googlegroups.com> References: <1115245476.036508.273930@g14g2000cwa.googlegroups.com> Message-ID: querypk at gmail.com wrote: > If this is the list. > > values = [ 0, 72, 0, 4, 9, 2, 0, 0, 42, 26, 0, 282, > 23, 0, 101, 0, 0, 0, 0, 0] > > as we can see there are peaks in the list.that is 0,72,0 is a > group(triangle) with peak 72.then 0, 4, 9, 2, 0, 0 with peak > 9 and 0, 42, 26, 0 with 42 and so on... > what I want is the left and right bound index of each bin(triangle).The > list could as big as possible.So some heurestic algorithm which could > first find max in the list and look for local maxima and minima and > group its adjcent bounds.Then find next max and group the bins and so > on. > > so that we can get > > [[0,2],[2,7],[7,10],[10,13]] > ( indexes of the bounds in the values list). so first group [0,2] > correspond to 0,72,0 in the values list and so on... > Hope I am clear. Not exactly your output, but hopefully you can tailor it to your needs: py> values = [0, 72, 0, 4, 9, 2, 0, 0, 42, 26, 0, 282, 23, 0, 101, 0, 0, 0, 0, 0] py> def isnonzero((index, val)): ... return val != 0 ... py> import itertools py> for nonzero, vals in itertools.groupby(enumerate(values), isnonzero): ... if nonzero: ... vals = list(vals) ... start = vals[0][0] - 1 ... end = vals[-1][0] + 1 ... print [start, end], "values: ", values[start:end+1] ... [0, 2] values: [0, 72, 0] [2, 6] values: [0, 4, 9, 2, 0] [7, 10] values: [0, 42, 26, 0] [10, 13] values: [0, 282, 23, 0] [13, 15] values: [0, 101, 0] Note that the real work is done by itertools.groupby. Zero terms are grouped together and ignored; non-zero terms are gathered together in lists. STeVe From flupke at nonexistingdomain.com Fri May 20 06:17:26 2005 From: flupke at nonexistingdomain.com (flupke) Date: Fri, 20 May 2005 10:17:26 GMT Subject: cddb and mci produce an ImportError In-Reply-To: References: Message-ID: flupke wrote: I finally succeeded in making a proper mci.dll that works. I will document what i did in the coming days and place it here. I developed the dll with DevC++. Anyway, it all works :) Benedict From gmayer at cs.bgu.ac.il Wed May 4 16:44:18 2005 From: gmayer at cs.bgu.ac.il (Mayer) Date: 4 May 2005 13:44:18 -0700 Subject: annonymous functions -- how to Message-ID: <1115239458.776800.240080@g14g2000cwa.googlegroups.com> Hello: I would like to define a very large annonymous function, one with several statements in sequence. I know how to define annonymous functions, but I don't know how to define a sequence of statements in their body. Can this be done in Python? If so, how? Thanks, Mayer From usenet at terabytemusic.cjb.net Wed May 18 08:38:15 2005 From: usenet at terabytemusic.cjb.net (DJTB) Date: Wed, 18 May 2005 14:38:15 +0200 Subject: processing a Very Large file References: <118k530sl6kve5c@corp.supernews.com> Message-ID: <118mdpo7h6rskb7@corp.supernews.com> Tim Peters wrote: > >> tuple_size = int(splitres[0])+1 >> path_tuple = tuple(splitres[1:tuple_size]) >> conflicts = Set(map(int,splitres[tuple_size:-1])) > > Do you really mean to throw away the last value on the line? That is, > why is the slice here [tuple_size:-1] rather than [tuple_size:]? > Thanks, you saved me from another bug-hunting hell... (In a previous test version, split returned a '\n' as the last item in the list...) > > You could manually do something akin to Python's "string interning" to > store ints uniquely, like: > > int_table = {} > def uniqueint(i): > return int_table.setdefault(i, i) > > Then, e.g., > >>>> uniqueint(100 * 100) is uniqueint(100 * 100) > True >>>> uniqueint(int("12345")) is uniqueint(int("12345")) > True > > Doing Set(map(uniqueint, etc)) would then feed truly shared int > (and/or long) objects to the Set constructor. > I've implemented this and it does seem to work, thanks. Stan. From curi at curi.us Fri May 27 15:30:31 2005 From: curi at curi.us (Elliot Temple) Date: Fri, 27 May 2005 12:30:31 -0700 Subject: Get number of lines in file In-Reply-To: <1117221428.788567.10060@f14g2000cwb.googlegroups.com> References: <1117221428.788567.10060@f14g2000cwb.googlegroups.com> Message-ID: <3376ECFF-9CC7-4A2B-8BA3-22C46EB2E892@curi.us> On May 27, 2005, at 12:17 PM, ssmith579 at aol.com wrote: > I have read in a file and need to get the number of lines. > > cpn_file = open('Central Part number list.txt') > cpn_version = cpn_file.read().split('\n') > > I want to know the number of elements in cpn_version. Could you use: count_lines = len(cpn_file.readlines()) -- Elliot Temple http://www.curi.us/ --- [This E-mail scanned for viruses by Declude Virus] From chase at youknowwho.com Sun May 29 22:55:10 2005 From: chase at youknowwho.com (Joseph Chase) Date: Mon, 30 May 2005 02:55:10 GMT Subject: Monitoring Outgoing Connections? Message-ID: Is it possible to write a client within Python that would trigger some sort of callback interface when the user is attempting to make an outgoing TCP/IP connection? I'd like to accomplish this on a Windows XP box. Is this something that could be accomplished with the Twisted framework, or am I going to have to dive in the platform specific API? TIA. From steven.bethard at gmail.com Mon May 16 13:00:53 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 16 May 2005 11:00:53 -0600 Subject: python-dev Summary for 2005-04-16 through 2005-04-30 In-Reply-To: <1116258692.305537.244260@g49g2000cwa.googlegroups.com> References: <1116258692.305537.244260@g49g2000cwa.googlegroups.com> Message-ID: Kay Schluehr wrote: > but PEP 340 is already withdrawn by the BDFL. > There won't be any Ruby-like blocks because they hide control flow. Well, there won't be any blocks that can perform *arbitrary* control flow, but it does look like we might have blocks that can perform try/finally-like acquisition and release code. More on this in the next summary. STeVe From ramen at lackingtalent.com Fri May 6 13:40:58 2005 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 06 May 2005 10:40:58 -0700 Subject: annonymous functions -- how to In-Reply-To: References: <1115239458.776800.240080@g14g2000cwa.googlegroups.com><42795acb.685370470@news.oz.net><1115264804.625020.203800@f14g2000cwb.googlegroups.com> <2fNee.10965$fI.8507@fed1read05> Message-ID: Fredrik Lundh wrote: > Dave Benjamin wrote: > >>>so name them all "func" or "next" or something, so you don't have >>>to think. once the object is bound, the name is irrlevant. >> >>Sure, you could do this, but then you'd have multiple functions at >>different nesting levels with the same name, which would be confusing. > > "I don't wanna try that", you mean. No, I mean, "I have an imagination". But for the sake of argument, here, I'll try that: def add_thingy(): def func(thingy_id): print 'got thingy id:', thingy_id def funnc(doodad_id): print 'got doodad id:', doodad_id def func(thingy_doodad): print 'thingy doodad created, froobling...' frooble(thingy_doodad) print 'froobling complete' with_new_thingy_doodad(thingy_id, doodad_id, func) with_next_doodad_id(func) with_next_thingy_id(func) This function now has an infinite loop. Can you spot the reason? > because if you had done so, you would have noticed that "multiple > functions with the same name" doesn't have to be any more confusing > than "multiple print statements" or "multiple if statements" (as long as > you're not using bad names on purpose, of course). I have noticed. It is more confusing. That's the whole point. >>>there's also: >>> >>> def add_thingy(self): >> >>What object is "self"? Are we defining a method at this point? > > if you have a problem with methods, you shouldn't use Python. No, I was asking you to clarify, are we rewriting "add_thingy" to be a method, and if so, what class is it a method of, and what are its responsibilities? Because it seems like this example now shares data through an instance, but this data is not required for any other method, so it will add clutter to the instance namespace. If anything, it seems that "add_thingy" should be moved into another class at this point, in which case it follows that every method that needs to do this sort of asynchronous communication would likewise be moved to a new class. This is fine, I suppose, but it's a lot more verbose. >>> yield get_new_thingy_id; thingy_id = self.result >> >>What is "get_new_thingy_id"? A function? To whom are we yielding here? > > I could have sworn that you mentioned event-driven programming > in your original post. if that's still what you're doing, the answers > are "a token" and "the event source". I am just trying to make sense of your example. I am still talking about event-programming. Here are the events: 1. Program A sends program B a message, saying, "I need a thingy ID". 2. B sends A a message, "Here's a thingy ID: 42". 3. A sends B a message, "I need a doodad ID". 4. B sends A a message, "Here's a doodad ID: 43". 5. A sends B a message, "Make a thingy doodad with IDs 42 and 43". 6. B sends A a message, "Thingy doodad created". 7. A sends B a message, "Now, frooble the thingy doodad". I don't know what parts of this transcript you would consider "tokens". And I'm also not sure how generators can provide an alternative solution to this problem. I am genuinely interested. Dave From dave at pythonapocrypha.com Wed May 18 13:54:31 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Wed, 18 May 2005 11:54:31 -0600 Subject: Is Python suitable for a huge, enterprise size app? In-Reply-To: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> Message-ID: <428B8157.9080005@pythonapocrypha.com> john67 wrote: > The company I work for is about to embark on developing a commercial > application that will cost us tens-of-millions to develop. [snip] > Right now it looks like Java is the language of choice that the app > will be developed in. However, I have been looking and reading a lot > about Python recently and it seems to me that Python could handle it. > The big attraction to me is the developer productivity. It seems that > if Python can handle it, then we could gain a huge savings by using > Python instead of Java from a productivity standpoint alone. > > So, given the very general requirements in the first paragraph, do you > think that Python could handle it? Yes. Python has good database support, it works well on a wide range of platforms, and it's great at tying together different processes, machines, etc. - for example, it's fairly easy to get Python to access C code, dynamic libraries, system APIs, and external programs. It's easier to test than Java code as well, and the overal cost of change is lower. The concise nature of the language means that what would otherwise be a "huge" enterprise app in Java might just be a "large" enterprise app in Python - the project will not reach that unwieldy size as quickly, if ever. The Google archives of this group have this topic covered in various ways many times over - IMO Python is great for smallish apps, but its advantage over e.g. Java actually *increases* with the size of the app. If you go the Python route, two of the main obstacles will be: 1) mindshare - getting people on board, getting them to overcome biases one way or another, convincing them to really take the time to come up to speed on Python. 2) reducing the complexity of what you think you need to build. I don't know how to better describe this, but in Java, for example, I'd have whole bunches custom classes to do various tasks but the Python equivalent collapsed into a single module. Anyway, I predict that it'll take you some time to convince yourself that you simply won't need to build all of the same components as you otherwise would, or that they'll often be vastly simpler. -Dave From gigi-s at bigfoot.com Mon May 30 04:52:28 2005 From: gigi-s at bigfoot.com (Gigi) Date: Mon, 30 May 2005 01:52:28 -0700 Subject: __getattribute__ and __getattr__ In-Reply-To: References: Message-ID: <429AD44C.50506@bigfoot.com> Terry Reedy wrote: > "Gigi" wrote in message > news:d7dgd4$29v$1 at sea.gmane.org... > >>Hi, >>In the Python documentation regarding __getattribute__ (more attribute >>access for new style classes) it is mentioned that if __getattribute__ >>is defined __getattr__ will never be called (unless called explicitely). >>Here is the exact citation: > > > Discrepancy reported in > > https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1204734&group_id=5470 > > Guido declared behavior right and doc wrong and in need of correction. > > Terry J. Reedy > > > Thanks for your reply. It definitely clears the issue. I'm writing an article to Dr. Dobbs about the Python object model and I wouldn't want to be inaccurate. I fill a little like Leibnitz :-) . It's a curious coincidence that two separate people notice the same documentation issue that lingere for such a long time in such a short time span. Thanks, Gigi From philippe at philippecmartin.com Mon May 16 14:24:56 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Mon, 16 May 2005 18:24:56 GMT Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever sepa References: <1116096706.696830.275140@g44g2000cwa.googlegroups.com> <86sm0nd4bn.fsf@guru.mired.org> Message-ID: No need to, just give the guy a glass of water and he'll fix it for you Mike Meyer wrote: > rockon02 at senet.com.au (Mike brown) writes: > >> In article , "Bubba" >> wrote: >> >>> I'm so glad you've decided what everyone believes.... >>> >> >> >> >> Some of us don't. >> >> >> >> >> >> Believe that is. >> >> >> >> >> >> In anything in particular. > > > Everybody should believe in something. > > > > > > > I believe I'll have another beer. > > > I use code below: 1) frame receive too many maximize events on create and on close child window - why? 2) how to catch key events for wxMDIParentFrame ? 3) childWin.SetSize() in OnMaximize send additional maximize event (?) 4) wxMDIChildFrame is initially visible! 5) sorry for english :) 6) wxPython 2.5.4.1 (Windows) ################################################################ import wx #---------------------------------------------------------------------- class MyParentFrame(wx.MDIParentFrame): def __init__(self): wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400), style=wx.DEFAULT_FRAME_STYLE|wx.FRAME_NO_WINDOW_MENU) self.winCount = 0 self.CreateStatusBar() self.MainTb=self.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT) biblioBut=wx.Button(self.MainTb,1231,label="&Biblio") newWndBut=wx.Button(self.MainTb,1213,label="&NewWnd") wx.EVT_BUTTON(self,newWndBut.GetId(), self.OnNewWindow) self.MainTb.AddControl(biblioBut) self.MainTb.AddSeparator() self.MainTb.AddControl(newWndBut) self.MainTb.Realize() self.SetToolBar(self.MainTb) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDownParent) def OnKeyDownParent(self, event): print "OnKeyDownParent" def OnKeyDownChild(self, event): print "OnKeyDownChild" def OnClose(self, evt): self.GetActiveChild().Close(True) def OnMaximize(self, event): childWin = event.GetEventObject() win = childWin.GetParent() print "maximize "+self.GetTitle() childWin.SetSize(wx.Size(win.GetClientSize().GetWidth(),win.GetClientSize().GetHeight()-1)) childWin.SetPosition(wx.Point(0,-1*win.GetClientAreaOrigin().y+1)) event.Skip() def OnNewWindow(self,event): self.winCount = self.winCount + 1 win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount) win.Maximize() #win.Show() # !!!!!!!!!!!!!!!!!! MainTb=win.CreateToolBar(wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT) SBut=wx.Button(MainTb,1213,label="&Func") MainTb.AddControl(SBut) MainTb.Realize() win.SetToolBar(MainTb) win.Bind(wx.EVT_MAXIMIZE, self.OnMaximize) win.Bind(wx.EVT_KEY_DOWN, self.OnKeyDownChild) win.Show(True) #---------------------------------------------------------------------- if __name__ == '__main__': class MyApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() frame = MyParentFrame() frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(False) app.MainLoop() From sxanth at ceid.upatras.gr Fri May 13 11:51:15 2005 From: sxanth at ceid.upatras.gr (Stelios Xanthakis) Date: Fri, 13 May 2005 18:51:15 +0300 Subject: pyvm -- faster python In-Reply-To: References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> <1115791624.856252.247890@z14g2000cwz.googlegroups.com> <7x1x8el18e.fsf@ruckus.brouhaha.com> <1115876410.813839.222080@g43g2000cwa.googlegroups.com> Message-ID: <4284CCF3.10308@ceid.upatras.gr> Armin Steinhoff wrote: >>> Is there a working version of lwc ??? >>> >> >> pyvm is written in lwc-2.0 which is not yet released because >> nobody's using it. > > > As you mentioned it ... lwc-2.0 is used for pyvm. So it is used :) > > Do you have an idea when lwc-2.0 will be releast ? > > Everyone who are interested in pyvm will need it ... > It will be included together with pyvm. Normally if you want to just compile pyvm you do not need lwc, it's a preprocessor that generates C from C++ and the C for pyvm will be pre-generated. You'd need lwc for modifying/hacking pyvm. Stelios From apardon at forel.vub.ac.be Tue May 3 09:55:22 2005 From: apardon at forel.vub.ac.be (Antoon Pardon) Date: 3 May 2005 13:55:22 GMT Subject: sorting list and then return the index of the sorted item References: <1115127433.984686.99060@f14g2000cwb.googlegroups.com> Message-ID: Op 2005-05-03, Antoon Pardon schreef : > Op 2005-05-03, custard_pie schreef : >> I need help sorting a list...I just can't figure out how to sort a list >> and then return a list with the index of the sorted items in the list >> for example if the list I want to sort is [2,3,1,4,5] >> I need [2,0,1,3,4] to be returned >> Can someone help please.... >> > > Something like this: > >>>> lst = [2,3,1,4,5] >>>> inx = range(len(lst)) >>>> inx.sort(lambda x,y: lst[x] - lst[y]) >>>> print inx > [2, 0, 1, 3, 4] > Something a bit more usefull in general: >>> lst = [2,3,1,4,5] >>> inx = range(len(lst)) >>> inx.sort(lambda x,y: cmp(lst[x],lst[y])) >>> print inx [2, 0, 1, 3, 4] -- Antoon Pardon From lbates at syscononline.com Fri May 20 20:29:38 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 20 May 2005 19:29:38 -0500 Subject: performance of Nested for loops In-Reply-To: <1116628510.816306.31390@g43g2000cwa.googlegroups.com> References: <1116628510.816306.31390@g43g2000cwa.googlegroups.com> Message-ID: <428E80F2.7060309@syscononline.com> You can use xrange(N) that way Python doesn't have to build the 10000 item lists 20000 times. Other than that one would need to know why you would call do_job1 and do_job2 10000 times each inside a 10000 iteration loop. Most VERY large performance gains are due to better algorithms not code optimization. Larry Bates querypk at gmail.com wrote: > Is there a better way to code nested for loops as far as performance is > concerned. > > what better way can we write to improve the speed. > for example: > N=10000 > for i in range(N): > for j in range(N): > do_job1 > for j in range(N): > do_job2 > From elrei69 at yahoo.es Thu May 12 11:48:05 2005 From: elrei69 at yahoo.es (Ximo) Date: Thu, 12 May 2005 17:48:05 +0200 Subject: How "return" no return ? References: <3ehaurF34ak0U1@individual.net> Message-ID: <3ehc5tF35eo3U1@individual.net> I am doing a interpret of lines and it show me a prompt, and I want if I write a declaration as "int a" my progrtam return de prompt and nothing more, for exemple: >>> 2+2 4 >>> int a >>> Then I'm finding that de function which execute "int a" return me nothing, and no >>> int a None >>> "Joseph Garvin" escribi? en el mensaje news:mailman.472.1115911936.29826.python-list at python.org... > Ximo wrote: > >>Hello, I want that the return sentence don't return anything, how can I do >>it?. If i do only return it returns None, and pass don't run too. >> >>Can anyone help me?, thanks. >>XIMO >> >> >> >> > Returning None is the same as returning nothing. What exactly are you > trying to do? From mrmaple at gmail.com Wed May 18 17:15:21 2005 From: mrmaple at gmail.com (James Carroll) Date: Wed, 18 May 2005 17:15:21 -0400 Subject: speeding up Python script In-Reply-To: <118n5l557ften8a@corp.supernews.com> References: <3evgolF56gtkU3@individual.net> <118n5l557ften8a@corp.supernews.com> Message-ID: It looks like your algorithm really does iterate over all values for six variables and do lots of math.. then you can't do any better than implementing the inner loop in C. It does look like you have some functions that are being called that are also in python, and it would be interesting to see if just one of those was the culprit. If so, you might be able to replace just one of those calls with something faster. I'm no expert, but I have used swig once or twice, I might be able to help. What do you think? If you are going through all the data just to find a minimum or something, then you might be able to get away with not visiting all of the values of all six variables. Some sort of gradient descent minimization is probably already out there written in C ready to be used. -Jim On 5/18/05, Grant Edwards wrote: > On 2005-05-18, Luis P. Mendes wrote: > > > I have a 1000 line python script that takes many hours to > > finish. It is running with six inside 'for' loops. > From news at NOwillmcguganSPAM.com Tue May 3 09:21:36 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 03 May 2005 14:21:36 +0100 Subject: Py2Exe security In-Reply-To: <1115124297.746843.111770@g14g2000cwa.googlegroups.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> <1115124297.746843.111770@g14g2000cwa.googlegroups.com> Message-ID: <42777ae1$0$2061$db0fefd9@news.zen.co.uk> Terje Johan Abrahamsen wrote: >>If your program can access these details, then a suficiently >>determined attacker can access them too, regardless of what you do. > > > Yes, I assume so. Luckily it is not national secrets we are trying to > hide. But, how does py2exe compare with for example a program written > in a compiled language like C++? Is it easier to find the info in a > py2exe .exe than a c++ compiled c++? > Its not the exe file you need to be concerned about, its the pyc files that are created with it. I imagine the strings will be in plain text form, just like compiled C++. As others have pointed out, it would be impossible to prevent an attacker from discovering information inside the app. The best you can do is obfuscate the strings somehow and 'un-obfuscate' them when the app runs. That way they at least wont be obvious. Take a look at my signature for an example! Will McGugan -- http://www.willmcgugan.com "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz" ] ) From black.bird at NOSPAMtiscali.it Tue May 3 02:41:27 2005 From: black.bird at NOSPAMtiscali.it (Michele Ferretti) Date: Tue, 03 May 2005 06:41:27 GMT Subject: WordPress Python Library 1.0 In-Reply-To: <1115086696.356342.76870@f14g2000cwb.googlegroups.com> References: <1115086696.356342.76870@f14g2000cwb.googlegroups.com> Message-ID: Cappy2112 wrote: > If you wan't explain what WordPress is, can you at least supply a link > for a page that's in English? > WordPress is most diffused blog engine: http://www.wordpress.org My library is a client for connect to WP installation. -- Michele Ferretti ICQ#: 14491159 Skype: m.ferretti79 black DOT bird AT tiscali DOT it www.blackbirdblog.it From prabapython at yahoo.co.in Thu May 12 06:31:59 2005 From: prabapython at yahoo.co.in (praba kar) Date: Thu, 12 May 2005 11:31:59 +0100 (BST) Subject: reg mail sending without smtp module In-Reply-To: 6667 Message-ID: <20050512103159.78166.qmail@web8403.mail.in.yahoo.com> Dear All, From this below answer I got clear idea for mail sending Module. I am expecting this kind of answer . Thank you for your immediate response. --- Mike Meyer wrote: > praba kar writes: > > In Php we can build a Mail Message by > > Mail_mime class and send this message by > > Mail::Factory's class send Method. Here Php > > doesn't use any smtp modules. Like that > > In Python I used email.Message class to > > build Mail Message and Now I am searching > > modules to send this message as mail. > > Python isn't PHP. In python, the standard way to > send a message is > with the smtp module. If you do an "import this" in > a python > interpreter, it will tell you (among other things) > "There should be > one-- and preferably only one --obvious way to do > it." The smtp module > is that way. Since smtp is also how mail is sent > around the internet, > this makes a lot of sense. > > Now, the PHP mail command uses the system's sendmail > binary (at least > on Unix). You can do that by hand using the > subprocess module in 2.4, > or os.system or os.popen or something similar on > earlier versions of > Python. All this really does is asks sendmail to put > a message in the > queue from the command line, rather than via the > smtp port. It's > probably slower than talking to the already running > smtp daemon. > > On Windows, the PHP mail command connects to an smtp > server - which is > exactly what smtplib does. > > -- > Mike Meyer > http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, > email for more information. > -- > http://mail.python.org/mailman/listinfo/python-list > ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From a-steinhoff at web.de Tue May 17 09:43:42 2005 From: a-steinhoff at web.de (Armin Steinhoff) Date: Tue, 17 May 2005 15:43:42 +0200 Subject: PyXML/expat and the empty elements Message-ID: Hi all, is it possible to get the name of an empty element specified by ... the expat parser seems only to recognize the form Regards Armin From steven.bethard at gmail.com Sat May 14 16:43:52 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sat, 14 May 2005 14:43:52 -0600 Subject: A new to Python question In-Reply-To: <1116102355.715816.192840@z14g2000cwz.googlegroups.com> References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> Message-ID: M.E.Farmer wrote: > I said exactly what I meant, the parentheses around the values creates > a tuple that you have no reference to! It also has a side effect of > binding the names inside the tuple to a value and placing them in the > local namespace( implicit tuple unpacking ). It might be the "same" as > no parens but it isn't very clear. If you want a tuple make it > explicit, if you want individual names make it explicit. It actually is the same, and I don't think implicit or explicit is the difference you should be citing here. The parentheses are fully optional -- they don't change the semantics at all: py> t = (4, 5) py> a = t py> a is t True py> a = (b, c) = t py> a is t True py> a = b, c = t py> a is t True In all cases, "a" still gets assigned the tuple (4, 5). Whether or not you put the parentheses around "b, c" is fully a matter of style. I don't know the implementation enough to know whether or not a tuple is actually created when "b" and "c" are bound to their values, but I'd be willing to bet that whatever happens to "(b, c)" is exactly the same as what happens to "b, c". STeVe From steven.bethard at gmail.com Wed May 11 16:52:06 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 11 May 2005 14:52:06 -0600 Subject: Python Documentation (should be better?) In-Reply-To: References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> Message-ID: Ivan Van Laningham wrote: > The Python docs are not ideal. I can never remember, for instance, > where to find string methods (not methods in the string module, but > methods with '') Hmmm... Well going to http://docs.python.org/ and typing "string methods" into the search box gives, as the first hit: http://docs.python.org/lib/string-methods.html Even if you just search for "string", that URL is the second hit, and pretty clearly the right one from the title. STeVe From zlatozar at gmail.com Mon May 16 03:23:41 2005 From: zlatozar at gmail.com (zlatozar) Date: 16 May 2005 00:23:41 -0700 Subject: Have you tried eric3 ? In-Reply-To: References: <200505141008.00398.nicolas.girard@nerim.net> Message-ID: <1116228221.501549.306280@z14g2000cwz.googlegroups.com> If you haven't tried PyDev(Eclipse plug-in) I'd encourage you to take a look. Here is URL: http://pydev.sourceforge.net/ From lbates at syscononline.com Mon May 16 16:09:20 2005 From: lbates at syscononline.com (Larry Bates) Date: Mon, 16 May 2005 15:09:20 -0500 Subject: Problem listing services with wmi In-Reply-To: References: Message-ID: <4288FDF0.7040007@syscononline.com> Might not be the problem but try without the leading spaces before your method calls. for s in c.Win32_Service (): should be for s in c.Win32_Service(): -Larry Jean-S?bastien Guay wrote: > Hello, > > I'm pretty new to Python, though I have a fair bit of experience with > C/C++, Java, Perl, PHP and others. > > I installed Tim Golden's wmi module > (http://tgolden.sc.sabren.com/python/wmi.html), in the hopes it would > help me list and work with services on my Win32 machine. Now, everything > seems fine except for one thing : Listing services! > > I tried running a couple of the examples on Tim's more examples page in > the python shell (for example, List all running processes, Show the > percentage free space for each fixed disk, Show the IP and MAC addresses > for IP-enabled network interfaces, etc.) and they worked fine. But when > I try to run the first example which is on the first page above, I get > an error. The code is : > > import wmi > > for s in c.Win32_Service (): > if s.State == 'Stopped': > print s.Caption, s.State > > > and I get : > > Traceback (most recent call last): > File "", line 1, in ? > File "G:\Python-2.4\Lib\site-packages\wmi.py", line 404, in __call__ > return self.wmi.query (wql) > File "G:\Python-2.4\Lib\site-packages\wmi.py", line 583, in query > raise WMI_EXCEPTIONS.get (hresult, x_wmi (hresult)) > wmi.x_wmi: -2147217398 > > (the exception seems to be thrown on the "for s in..." line) > I have only found one discussion in this newsgroup's archives that seems > to talk about this problem > (http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/19fa91ea1a1ff160/0364b7cd22d73483?q=WMI_EXCEPTIONS&rnum=1#0364b7cd22d73483) > and the fix they suggest there (calling pythoncom.CoInitialize () before > instantiating the WMI object) doesn't seem to work in this case. In > other words, this code : > > import wmi > import pythoncom > > pythoncom.CoInitialize () > c = wmi.WMI () > for s in c.Win32_Service (): > if s.State == 'Stopped': > print s.Caption, s.State > > gives me the same result as above. > > Could someone please point me in the right direction to find out what's > wrong? > > Thanks in advance, > > J-S > From bokr at oz.net Fri May 13 19:55:36 2005 From: bokr at oz.net (Bengt Richter) Date: Fri, 13 May 2005 23:55:36 GMT Subject: How to find the classname of an object? (was Python Documentation) References: <4283fda8.18221170@news.oz.net> <1116002227.923231.309150@f14g2000cwb.googlegroups.com> <4284f28c.80913136@news.oz.net> <1116021553.771015.320200@g14g2000cwa.googlegroups.com> Message-ID: <42853387.97548507@news.oz.net> On 13 May 2005 14:59:13 -0700, "Matt" wrote: > >Bengt Richter wrote: [...] >> I'm afraid inheriting explicitly from object will make the exception >unraisable. >> Exceptions are still based on "classic" classes for some reason that >> I don't know enough about to explain. >> >> So if you were hoping to use .mro() with old-style classes to see the >> old-style inheritance chain, as opposed to new-style inheritance that >> underlies access to special entities involved in the implementation >of the old, sorry ;-/ >> >> At least that's the way it looks to me, without digging in that part >of the code. >> >> Regards, >> Bengt Richter > >D'oh! So I tested the .mro() functionality but not the >Exception-raisableness (?). > >It seems unintuitive to me as to why inheriting from "object" would >prevent something that also inherited from "Exception" from being >raised. Does anyone have insight into why this happens? > I googled for some discussion and found something straight from the BDFL: http://mail.python.org/pipermail/python-dev/2005-January/051098.html with a lot of interesting followup. Don't know what the status of the patch is now. Regards, Bengt Richter From Scott.Daniels at Acm.Org Tue May 3 15:41:00 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 May 2005 12:41:00 -0700 Subject: sorting list and then return the index of the sorted item In-Reply-To: References: <1115127433.984686.99060@f14g2000cwb.googlegroups.com> Message-ID: <4277cdc8$1@nntp0.pdx.net> Duncan Booth wrote: > custard_pie wrote: > >>I need help sorting a list...I just can't figure out how to sort a list >>and then return a list with the index of the sorted items in the list >>for example if the list I want to sort is [2,3,1,4,5] >>I need [2,0,1,3,4] to be returned > > ... >>>>v = [2, 3, 1, 4, 5] >>>>import operator >>>>[ i for (i,j) in sorted(enumerate(v), key=operator.itemgetter(1))] > > [2, 0, 1, 3, 4] > Or, to get fancy with Python 2.4: result = sorted(range(len(v)), key=v.__getitem__) Make a list of indices, and says the sort key is "over there" to sorted. --Scott David Daniels Scott.Daniels at Acm.Org From tgm2tothe10thpower at replacetextwithnumber.hotmail.com Wed May 25 09:47:07 2005 From: tgm2tothe10thpower at replacetextwithnumber.hotmail.com (Thomas G. Marshall) Date: Wed, 25 May 2005 13:47:07 GMT Subject: What are OOP's Jargons and Complexities? References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> <1117003340.900449.124180@o13g2000cwo.googlegroups.com> Message-ID: Xah Lee coughed up: > The Rise of "Static" versus "Instance" variables You are clearly unable to form a proper argument, *AND* you have irritated nearly everyone frequently. Ah....the blessed silence.... From http Wed May 11 22:53:29 2005 From: http (Paul Rubin) Date: 11 May 2005 19:53:29 -0700 Subject: Python Documentation (should be better?) References: <1115839271.271071.32710@z14g2000cwz.googlegroups.com> <1115841659.470657.33320@o13g2000cwo.googlegroups.com> Message-ID: <7xk6m5b1ee.fsf@ruckus.brouhaha.com> "S?bastien Boisg?rault" writes: > "Manual" == scope of the *Lib Reference* + informal style of the > *Tutorial*, I don't care whether the style is formal or informal, the manual should document the complete interface of the language and library and right now it doesn't do anything like that. From raghulj at gmail.com Thu May 26 10:00:21 2005 From: raghulj at gmail.com (Raghul) Date: 26 May 2005 07:00:21 -0700 Subject: converting jpg to pdf Message-ID: <1117116021.652260.66260@g14g2000cwa.googlegroups.com> Hi friends Is it possible to convert jpg to pdf in python. I need a program to convert jpg format file to pdf. Is there any sample or any library to do that? Pls guide me. Thanks in advance From mwh at python.net Thu May 19 13:05:16 2005 From: mwh at python.net (Michael Hudson) Date: Thu, 19 May 2005 17:05:16 GMT Subject: What's the use of changing func_name? References: <311b5ce105051822477c09c81@mail.gmail.com> <311b5ce1050518231650b3b53e@mail.gmail.com> Message-ID: Robert Kern writes: > could ildg wrote: > > Thank you for your help. > > I know the function g is changed after setting the func_name. > > But I still can't call funciton g by using f(), when I try to do > > this, error will occur: > > > > > >>>>g.func_name="f" > >>>>print g > > > > > >>>>f() > > Traceback (most recent call last): > > File "", line 1, in ? > > NameError: name 'f' is not defined > > > > Since the name of g is changed into f, why can't I call it by using f()? > > Should I call it using f through other ways? Please tell me. Thanks~ > > Others have answered this particular question, but you're probably > still wondering what is the use of changing .func_name if it doesn't > also change the name by which you call it. The answer is that there > are tools that use the .func_name attribute for various purposes. For > example, a documentation generating tool might look at the .func_name > attribute to make the proper documentation. Actually, that's probably > *the* biggest use case because I can't think of any more significant > ones. Error messages! Cheers, mwh -- There are two kinds of large software systems: those that evolved from small systems and those that don't work. -- Seen on slashdot.org, then quoted by amk From davidb at mcs.st-and.ac.uk Tue May 31 08:26:00 2005 From: davidb at mcs.st-and.ac.uk (davidb at mcs.st-and.ac.uk) Date: 31 May 2005 05:26:00 -0700 Subject: scripting browsers from Python In-Reply-To: <1117525953.255166.234420@g14g2000cwa.googlegroups.com> References: <1117525953.255166.234420@g14g2000cwa.googlegroups.com> Message-ID: <1117542360.436302.207150@o13g2000cwo.googlegroups.com> Michele Simionato wrote: > I would like to know what is available for scripting browsers from > Python. > For instance, webbrowser.open let me to perform GET requests, but I > would like to do POST requests too. I don't want to use urllib to > emulate a browser, I am interested in checking that browser X really > works as intended with my application. Any suggestion? For Konqueror running on KDE, you can use DCOP to control the browser. There are a couple of different, but related, Python modules that you can use to do this. See the following page for more information: http://developer.kde.org/language-bindings/python/ I believe this approach has been used quite successfully with other KDE applications: http://www.kde-apps.org/content/show.php?content=18638 You should still be able to automate the browser with just popen2 and the "dcop" command line tool if you are really desperate. I once had to resort to this ad-hoc approach in the distant past but, these days, I'd recommend one of the above modules instead. David From grante at visi.com Tue May 3 10:46:12 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 03 May 2005 14:46:12 -0000 Subject: Py2Exe security References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> <1115129613.564775.21660@g14g2000cwa.googlegroups.com> Message-ID: <117f3lk633rbs87@corp.supernews.com> On 2005-05-03, mahasamatman wrote: > I suggest You to use base 64 encoded strings > something like > password = 'aGlkZGVuX3Bhc3N3b3Jk\n' > password = pasword.decode("base64") That will delay the attacker for a few minutes. -- Grant Edwards grante Yow! Do you like "TENDER at VITTLES"? visi.com From gmayer at cs.bgu.ac.il Wed May 18 20:17:50 2005 From: gmayer at cs.bgu.ac.il (Mayer) Date: 18 May 2005 17:17:50 -0700 Subject: help with generators Message-ID: <1116461870.130411.9280@g43g2000cwa.googlegroups.com> Hello: I need some help in understanding generators. I get them to work in simple cases, but the following example puzzles me. Consider the non-generator, "ordinary" procedure: def foo(n): s = [] def foo(n): if n == 0: print s else: s.append(0) foo(n - 1) s.pop() s.append(1) foo(n - 1) s.pop() foo(n) foo(n) prints all n-bit-wide binary numbers as a list. I would now like to create a generator for such numbers: def bin(n): s = [] def bin(n): if n == 0: yield s else: s.append(0) bin(n - 1) s.pop() s.append(1) bin(n - 1) s.pop() return bin(n) yet this doesn't work as expected. Can someone please explain why? Thanks, Mayer Goldberg From simon.dahlbacka at gmail.com Tue May 17 08:51:01 2005 From: simon.dahlbacka at gmail.com (simon.dahlbacka at gmail.com) Date: 17 May 2005 05:51:01 -0700 Subject: logging problems In-Reply-To: References: Message-ID: <1116334261.953335.307340@g14g2000cwa.googlegroups.com> I tried moving the import traceback to the start of the file (logging/__init__.py) but that did not seem to have any effect? I suppose the fix was in version 1.26 in cvs? From bokr at oz.net Mon May 16 13:28:31 2005 From: bokr at oz.net (Bengt Richter) Date: Mon, 16 May 2005 17:28:31 GMT Subject: question about the id() References: <428809fc.62d7a08a.1cfe.ffffd7ef@mx.gmail.com> <873bsnxhe0.fsf@hector.domek> Message-ID: <4288d546.86043504@news.oz.net> On Mon, 16 May 2005 18:30:47 +0200, Peter Dembinski wrote: >Skip Montanaro writes: > >> kyo> Can someone explain why the id() return the same value, and >> kyo> why these values are changing? >> >> Instance methods are created on-the-fly. > >So, the interpreter creates new 'point in address space' every time >there is object-dot-method invocation in program? Yes, but you can save the result of the obj.method expression (that's what it is, an expression). E.g., bound_method = obj.method after that, you can write bound_method() or obj.method() (of course, you can pass arguments too, depending on the signature, remembering that the "self" instance parameter is already bound in and does not need to be passed again to a bound method) The obj.method() call will re-evaluate the obj.method expression, and the bound_method() call will just call the previously created bound method. BTW, a typical performance optimization (not done automatically by python) is to hoist unchanging-value expressions out of loops, and obj.method is often such an expression, so you will this strategy when people try to squeeze extra performance from their programs. Regards, Bengt Richter From peter at engcorp.com Tue May 10 08:17:34 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 May 2005 08:17:34 -0400 Subject: sync dir's In-Reply-To: References: <428043D7.8030203@open-networks.net> <428060FA.8070207@open-networks.net> <20050510091012.GA16575@mylene.ghaering.de> Message-ID: Timothy Smith wrote: > Gerhard Haering wrote: >> http://osx.freshmeat.net/projects/pysync/ >> > pysync hasn't been worked on in years by the looks of it. no new > releases since 03. and the last release was for 2.1, so i'm dubious > about it working at all? the windows installer doesn't work either. You can (apparently) contact the maintainer ("ABO") for windows binaries if you need them. He is also on the librsync project, which has as its latest news "0.9.6 released", and the release in 2003 of pysync was intended to update it to use librsync 0.9.6. That suggests to me this is more a case of "things work" than a case of "dead project". In any case, pysync itself doesn't even have code to walk the directory tree or send data, just the delta/patch code, so unless you plan to build the other parts for yourself it may not be what you need. (On the other hand, if you need just the delta/patch code, it sounds like it should work fine.) I haven't tried it myself (yet). -Peter From dreamingpython at 163.com Wed May 25 00:44:15 2005 From: dreamingpython at 163.com (ÒÊÃÉɽÈË) Date: Wed, 25 May 2005 12:44:15 +0800 Subject: Has ComboBox ctrl in Tkinter? Message-ID: i have not find the ComboBox in Tkinter,has it? where to get the doc about how to use combobox ctrl? From bokr at oz.net Sat May 14 18:04:02 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 14 May 2005 22:04:02 GMT Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> Message-ID: <42866cb8.177725696@news.oz.net> On 14 May 2005 13:25:55 -0700, "M.E.Farmer" wrote: >I said exactly what I meant, the parentheses around the values creates >a tuple that you have no reference to! It also has a side effect of I don't understand what you are saying, or meaning ;-) BTW, the function call has nothing to do with what happens on the left hand side of the assignment. It is only the result of the function call that counts, so we could as well use a literal or other expression. This is a matter of unpacking a sequence according to the left hand target. E.g., >>> iter([1,2,3]) >>> a,b,c = iter([1,2,3]) >>> d,e,f = [1,2,3] >>> g,h,i = 'GHI' >>> [a,b,c,d,e,f,g,h,i] [1, 2, 3, 1, 2, 3, 'G', 'H', 'I'] Ok, now looking at the code for the assignment to a,b,c vs to (a,b,c): >>> import dis >>> dis.dis(compile('(a,b,c) = iter([1,2,3])','','exec')) 1 0 LOAD_NAME 0 (iter) 3 LOAD_CONST 0 (1) 6 LOAD_CONST 1 (2) 9 LOAD_CONST 2 (3) 12 BUILD_LIST 3 15 CALL_FUNCTION 1 18 UNPACK_SEQUENCE 3 21 STORE_NAME 1 (a) 24 STORE_NAME 2 (b) 27 STORE_NAME 3 (c) 30 LOAD_CONST 3 (None) 33 RETURN_VALUE >>> dis.dis(compile('a,b,c = iter([1,2,3])','','exec')) 1 0 LOAD_NAME 0 (iter) 3 LOAD_CONST 0 (1) 6 LOAD_CONST 1 (2) 9 LOAD_CONST 2 (3) 12 BUILD_LIST 3 15 CALL_FUNCTION 1 18 UNPACK_SEQUENCE 3 21 STORE_NAME 1 (a) 24 STORE_NAME 2 (b) 27 STORE_NAME 3 (c) 30 LOAD_CONST 3 (None) 33 RETURN_VALUE I don't see anything in the code about creating a tuple that you have no reference to. To see the unpacking of "GHI" so as to get rid of the function call red herring: >>> dis.dis(compile('a,b,c = "GHI"','','exec')) 1 0 LOAD_CONST 0 ('GHI') 3 UNPACK_SEQUENCE 3 6 STORE_NAME 0 (a) 9 STORE_NAME 1 (b) 12 STORE_NAME 2 (c) 15 LOAD_CONST 1 (None) 18 RETURN_VALUE >>> dis.dis(compile('(a,b,c) = "GHI"','','exec')) 1 0 LOAD_CONST 0 ('GHI') 3 UNPACK_SEQUENCE 3 6 STORE_NAME 0 (a) 9 STORE_NAME 1 (b) 12 STORE_NAME 2 (c) 15 LOAD_CONST 1 (None) 18 RETURN_VALUE ISTM the assignment part starts with UNPACK_SEQUENCE and all the code looks the same. BTW, UIAM it is the commas that define tuples, so the outermost parens are really expression parens more than tuple syntax. But note that you can have nested tuple structure as target, and that does change the unpacking code (and what it expects to have available to unpack): >>> (x,(y,z)) = 'XYZ' Traceback (most recent call last): File "", line 1, in ? ValueError: too many values to unpack >>> (x,(y,z)) = 'X','YZ' >>> x 'X' >>> y 'Y' >>> z 'Z' >>> (x,(y,z)) = [1, [2,3]] >>> x 1 >>> y 2 >>> z 3 >>> dis.dis(compile('(x,(y,z)) = 0','','exec')) 1 0 LOAD_CONST 0 (0) 3 UNPACK_SEQUENCE 2 6 STORE_NAME 0 (x) 9 UNPACK_SEQUENCE 2 12 STORE_NAME 1 (y) 15 STORE_NAME 2 (z) 18 LOAD_CONST 1 (None) 21 RETURN_VALUE Obviously we can't unpack the zero, but the code doesn't know that until it tries it, so we can look at what the left hand side code is independent of the right hand side. >binding the names inside the tuple to a value and placing them in the >local namespace( implicit tuple unpacking ). It might be the "same" as >no parens but it isn't very clear. If you want a tuple make it >explicit, if you want individual names make it explicit. OTOH, you might want a mix: >>> a, tup, (b,c), d = ['A', ('a', 'tuple'), 'BC', 'Sandra'] >>> a 'A' >>> tup ('a', 'tuple') >>> b 'B' >>> c 'C' >>> d 'Sandra' Or with gratuitous _outer_ parens: >>> (a, tup, (b,c), d) = ['A', ('a', 'tuple'), 'BC', 'Sandra'] >>> a 'A' >>> tup ('a', 'tuple') >>> b 'B' >>> c 'C' >>> d 'Sandra' >>> dis.dis(compile("a, tup, (b,c), d = ['A', ('a', 'tuple'), 'BC', 'Sandra']",'','exec')) 1 0 LOAD_CONST 0 ('A') 3 LOAD_CONST 6 (('a', 'tuple')) 6 LOAD_CONST 3 ('BC') 9 LOAD_CONST 4 ('Sandra') 12 BUILD_LIST 4 15 UNPACK_SEQUENCE 4 18 STORE_NAME 0 (a) 21 STORE_NAME 1 (tup) 24 UNPACK_SEQUENCE 2 27 STORE_NAME 2 (b) 30 STORE_NAME 3 (c) 33 STORE_NAME 4 (d) 36 LOAD_CONST 5 (None) 39 RETURN_VALUE Regards, Bengt Richter From flupke at nonexistingdomain.com Thu May 26 19:00:19 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 26 May 2005 23:00:19 GMT Subject: using timeit for a function in a class In-Reply-To: <429635b9$1_3@newspeer2.tds.net> References: <429635b9$1_3@newspeer2.tds.net> Message-ID: <7ysle.102305$D24.5938321@phobos.telenet-ops.be> Kent Johnson wrote: > flupke wrote: > >> >> Hi, >> >> i tried to use timeit on a function in a class but it doesn't do what >> i think it should do ie. time :) >> In stead it starts printing line after line of hello time test! >> What am i doing wrong in order to time the f function? > > > Hmm, by default Timer.timeit() calls the function being timed 1000000 > times. That's a lot of "hello time test" =:-) > > Kent Hehe, thanks Kent. Need to drink more coffee and train the eyes more, a new goal in life :) print t.timeit(1) did the trick. Regards, Benedict From devrick88 at gmail.com Thu May 5 11:19:31 2005 From: devrick88 at gmail.com (rickle) Date: 5 May 2005 08:19:31 -0700 Subject: dictionary comparison Message-ID: <1115306371.818120.150340@f14g2000cwb.googlegroups.com> I'm trying to compare sun patch levels on a server to those of what sun is recommending. For those that aren't familiar with sun patch numbering here is a quick run down. A patch number shows up like this: 113680-03 ^^^^^^ ^^ patch# revision What I want to do is make a list. I want to show what server x has versus what sun recommends, and if the patch exists, but the revision is different, I want to show that difference. Here are some sample patches that sun recommends: 117000-05 116272-03 116276-01 116278-01 116378-02 116455-01 116602-01 116606-01 Here are some sample patches that server x has: 117000-01 116272-02 116272-01 116602-02 So there are some that are the same, some that sun recommends that server x doesn't have, and some where the patch is the same but the revision is different. I've thrown the data into dictionaries, but I just can't seem to figure out how I should actually compare the data and present it. Here's what I have so far (the split is in place because there is actually a lot more data in the file, so I split it out so I just get the patch number and revision). So I end up with (for example) 116272-01, then split so field[0] is 116272 and field[1] is 01. def sun(): sun = open('sun-patchlist', 'r') for s in sun: sun_fields = s.split(None, 7) for sun_field in sun_fields: sun_field = sun_field.strip() sun_patch = {} sun_patch['number'] = sun_fields[0] sun_patch['rev'] = sun_fields[1] print sun_patch['number'], sun_patch['rev'] sun.close() def serverx(): serverx = open('serverx-patchlist', 'r') for p in serverx: serverx_fields = p.split(None, 7) for serverx_field in serverx_fields: serverx_field = serverx_field.strip() serverx_patch = {} serverx_patch['number'] = serverx_fields[0] serverx_patch['rev'] = serverx_fields[1] print serverx_patch['number'], serverx_patch['rev'] serverx.close() if __name__=='__main__': sun() serverx() Right now I'm just printing the data, just to be sure that each dictionary contains the correct data, which it does. But now I need the comparison and I just can't seem to figure it out. I could probably write this in perl or a shell script, but I'm trying really hard to force myself to learn Python so I want this to be a python script, created with only built-in modules. Any help would be greatly appreciated, Rick From steven.bethard at gmail.com Mon May 30 12:23:45 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Mon, 30 May 2005 10:23:45 -0600 Subject: how to convert string to list or tuple In-Reply-To: References: <1117383768.099922.308760@o13g2000cwo.googlegroups.com> Message-ID: Duncan Booth wrote: > Steven Bethard wrote: > >>But you can try it at home if you set __builtins__ to something other >>than the default: >> >>py> eval("""__import__("os").system('echo "hello"')""", >>dict(__builtins__=None)) >>Traceback (most recent call last): >> File "", line 1, in ? >> File "", line 0, in ? >>NameError: name '__import__' is not defined >> [snip] >> >>I know there have been security holes in this technique before, but I >>looked at the archives, and all the old ones I found have been >>patched. >> (Or at least I wasn't able to reproduce them.) > > I guess you are referring to things like this not working when you use eval > with an empty __builtins__: > > eval('''[ cls for cls in {}.__class__.__bases__[0].__subclasses__() > if '_Printer' in `cls` > ][0]._Printer__setup.func_globals['__builtins__']['__import__']''', > dict(__builtins__=None)) > > That gets blocked because func_globals is a 'restricted attribute', so I > can't get directly at __import__ that way Among other things, yes, that's one of the big ones. func_globals is inaccessible. Also, IIRC the file constructor is inaccessible. > but what I can do is to access > any new style class you have defined and call any of its methods with > whatever arguments I wish. Any new style class that I've defined? Or just any one I pass in as part of dict(__builtins__=None, ...)? If the former, could you elaborate? If the latter, then yes, I can see the problem. However for the case where all you pass in is dict(__builtins__=None), is there still a risk? Note that in the OP's case, all that is necessary is constant parsing, so no names need to be available. STeVe From axel at white-eagle.co.uk Sun May 8 01:03:29 2005 From: axel at white-eagle.co.uk (axel at white-eagle.co.uk) Date: Sun, 08 May 2005 05:03:29 GMT Subject: New Python regex Doc References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113856843.023012.165500@l41g2000cwc.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> <1115423751.016177.250650@o13g2000cwo.googlegroups.com> <1115444726.627426.172260@g14g2000cwa.googlegroups.com> <1115508491.462229.294020@o13g2000cwo.googlegroups.com> Message-ID: In comp.lang.perl.misc Xah Lee wrote: > Let me expose one another fucking incompetent part of Python doc, in > illustration of the Info Tech industry's masturbation and ignorant > nature. > Note the need to inject the high-brow jargon ???greedy??? here as a > latch on sentence. > ???never greedy???? What is greedy anyway? > ???Greedy???, when used in the context of computing, describes a When used in terms of Usenet, I think it can be applied in the sense of 'a troll who is greedy for attention'. Hence the saying 'do not feed the troll'. Axel From michele.simionato at gmail.com Tue May 31 03:52:33 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 31 May 2005 00:52:33 -0700 Subject: scripting browsers from Python Message-ID: <1117525953.255166.234420@g14g2000cwa.googlegroups.com> I would like to know what is available for scripting browsers from Python. For instance, webbrowser.open let me to perform GET requests, but I would like to do POST requests too. I don't want to use urllib to emulate a browser, I am interested in checking that browser X really works as intended with my application. Any suggestion? Michele Simionato From timothy at open-networks.net Tue May 10 01:17:11 2005 From: timothy at open-networks.net (Timothy Smith) Date: Tue, 10 May 2005 15:17:11 +1000 Subject: sync dir's Message-ID: <428043D7.8030203@open-networks.net> what would be the best tool to use to sync my local dir with a remote one, say off a http resorce (although i'm open to other options there) i haven't gotten any feed back on my problems with loading pysvn on win98, and i can apprechiate if the dev's are too busy/can't be bothered with win98. but i still need to find a solution that can achieve the same result, and i'm starting to look for other options. From tdelaney at avaya.com Tue May 3 19:35:53 2005 From: tdelaney at avaya.com (Delaney, Timothy C (Timothy)) Date: Wed, 4 May 2005 09:35:53 +1000 Subject: problem in the compiler ? Message-ID: <338366A6D2E2CA4C9DAEAE652E12A1DE025204D8@au3010avexu1.global.avaya.com> Glauco Silva wrote: > My code is like this: > > MyClass() > > class MyClass: > def __init__(self): > btn = RadioButton(command=self.Function) > def Function(self): > print "Enter in the function" > > When a do this, the function 'Function' is call. And i don?t want > this. What?s wrong ? Are you absolutely sure this is the exact code? As it is this will not work - it will fail with a NameError. You need to post a working piece of code that exhibits the behaviour, and include the exact error message (if any). Tim Delaney From glenn at connectfree.co.uk Sun May 1 15:48:43 2005 From: glenn at connectfree.co.uk (Glenn Pierce) Date: Sun, 01 May 2005 20:48:43 +0100 Subject: Wrapping c functions Message-ID: <4275329B.6040603@connectfree.co.uk> Hi I have been trying to wrap a c library called FreeImage for python and am having trouble with a couple of functions. One function is FreeImage_Load which takes parameters (enum, const char*, int) I have wrapped the function with the following code static PyObject * freeimage_load(PyObject *self, PyObject *args) { int format, flags; char* filename = "None"; FIBITMAP *dib = NULL; if (!PyArg_ParseTuple(args, "isi", &format, filename, &flags)) return NULL; dib = FreeImage_Load(format, filename, flags); return Py_BuildValue("o", dib); } However I am getting a segmentation fault at PyArg_ParseTuple. Also I have little Idea what to return from the function. FIBITMAP * is an opaque pointer that I pass to other FreeImage functions, I pretty certain Py_BuildValue("o", dib) is wrong. There is also the function unsigned char *FreeImage_GetBits(FIBITMAP *dib); I and not sure how to return the bits to python. I would probably like to display an image with the gtk function drawable.draw_rgb_image(*gc*, *x*, *y*, *width*, *height*, *dith*, *rgb_buf*, *rowstride*) here the RGB Image data is packed in a string as a sequence of 8-bit RGB pixel triplets but I have no idea how to get from unsigned char * to that. Any advice would be greatly appreciated. Thanks From mforal at gmail.com Thu May 26 12:37:42 2005 From: mforal at gmail.com (mitchell) Date: 26 May 2005 09:37:42 -0700 Subject: Store doctest verbose results to a variable Message-ID: <1117125462.847390.112790@g49g2000cwa.googlegroups.com> Is it possible to store doctest's verbose output to a variable? For example: import doctest, my_test_module a = doctest.testmod(my_test_module) The contents of 'a' is the tuple of passed and failed results. I tried passing verbose mode to the testmod function, but 'a' is still a tuple. Any help is greatly appreciated. From peter at engcorp.com Mon May 16 04:35:07 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 May 2005 04:35:07 -0400 Subject: Detect console close In-Reply-To: References: Message-ID: new pip wrote: > In Windows, when I double click on my .py file, the program runs with > a console. How can I detect when the console is closed? Any code > samples are appreciated. When the console has closed, your program has already exited, if I understand you correctly (which isn't certain: the question seems vague). How would you expect to "detect" this with code if your code is no longer running? Maybe you should also explain what you're really trying to accomplish, as there maybe other ways of doing it, or other solutions to your problem. -Peter From bcarey at ix.netcom.com Wed May 25 11:59:48 2005 From: bcarey at ix.netcom.com (bc) Date: 25 May 2005 08:59:48 -0700 Subject: pygame 1.6 for windows (python2.4) In-Reply-To: <4293a405$0$23946$db0fefd9@news.zen.co.uk> References: <1116959151.370529.261690@g49g2000cwa.googlegroups.com> <429380c5$0$24449$da0feed9@news.zen.co.uk> <1116969098.442603.193670@g43g2000cwa.googlegroups.com> <4293a405$0$23946$db0fefd9@news.zen.co.uk> Message-ID: <1117036788.611345.11030@g49g2000cwa.googlegroups.com> Got it! Thank you so much for your much appreciated help. Bill Carey From f.geiger at vol.at Wed May 18 11:46:40 2005 From: f.geiger at vol.at (F. GEIGER) Date: Wed, 18 May 2005 17:46:40 +0200 Subject: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindingssupplied. The current statement uses 0, and there are -1 supplied. References: Message-ID: Thank you Gerhard, "Gerhard H?ring" schrieb im Newsbeitrag news:mailman.117.1116363917.8733.python-list at python.org... > F. GEIGER wrote: > > Arrgh, sorry for that post! > > > > self._dbc.execute(q, data) > > > > where data is None, works with MySQL. For SQLite I have to write > > > > if data is not None: > > self._dbc.execute(q, data) > > else: > > self._dbc.execute(q) > > No, you have to write: > > self._dbc.execute(q, (data,)) > > in both drivers. > > i. e. the second parameter to execute *must* be a sequence. Some drivers > (maybe MySQLdb, too) automatically correct the wrong call and transform a: > Okay, that makes sense. > execute(sql, single_param) > > into a > > execute(sql, (single_param,)) > > for you if they notice that "!PySequence_Check(single_param)". > > pysqlite 2 does not do this. > > HTH, > > -- Gerhard Many thanks again Franz From nemesis at nowhere.invalid Fri May 27 17:48:43 2005 From: nemesis at nowhere.invalid (Nemesis) Date: Fri, 27 May 2005 21:48:43 GMT Subject: [ANN] XPN 0.4.6 References: <20050527210213.3341.45078.XPN@orion.homeinvalid> <4297929b$0$150$e4fe514c@news.xs4all.nl> Message-ID: <20050527215116.4147.91986.XPN@orion.homeinvalid> Mentre io pensavo ad una intro simpatica "Irmen de Jong" scriveva: >> XPN (X Python Newsreader XPN) is a multi-platform newsreader with >> Unicode support. It has features like scoring/actions, X-Face and Face >> decoding, muting of quoted text, newsrc import/export, find article and >> search in the body, spoiler char/rot13, random taglines, and >> configurable attribution lines. > > Wow, nice work! Thanks. > I'm using Thunderbird and am very happy with that, but > looking quickly at your website it seems that XPN is a very > nice application. Will it work on windows? It's not > immediately clear to me... Yes of course. You have thre options on Windowns: 1) You have already installed Python + GTK + pyGTK. In this case just use XPN source version. 2) You have installed GTK but not Python (I don't think this is your case ^__-). In this case you can use the binary version without GTK (the one large 2 MByte). 3) You don't have GTK and Python. In this case simply use the binary version (the larger one). -- I'm not unemployed... I'm a consultant. |\ | |HomePage : http://nem01.altervista.org | \|emesis |XPN (my nr): http://xpn.altervista.org From lbates at syscononline.com Fri May 13 14:13:09 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 13 May 2005 13:13:09 -0500 Subject: property, how to use it? In-Reply-To: References: <20050514012648.C48572886F@mail.iame.cn> Message-ID: <4284EE35.5070908@syscononline.com> class Age: def __init__(self, years=None): if years is None: self.years=0 else: self.years=years def __setattr__(self, key, value): if key == "years": if value < 0: print "ERROR-Years cannot be less than zero, setting to zero" self.years=0 return self.__dict__[key]=value return if __name__=="__main__": a=Age() # # Following will print zero because it is the default # print a.years # # Try to set negative # a.years=-1 # # Other attributes work just fine # a.yyy=10 Larry Bates Steve wrote: > Hi, > > Read this: > http://www.python.org/2.2.3/descrintro.html#property > > If you still don't understand or are confused about it's usage, ask here. > > Hint: Suppose you need to create an Age class with a 'years' attribute > and ensure that, (assuming I create an object a = Age()) > 1) when one tries to access 'a.years', a '0' would be returned even if > the value was not set or was set to a negative value, and > > 2) If a value is assigned to the 'years' attribute, we should check > for negative values. > > HTH > Regards > Steve From "myname" at example.invalid Sun May 29 10:07:57 2005 From: "myname" at example.invalid (VK) Date: Sun, 29 May 2005 16:07:57 +0200 Subject: Copy paste in entry widget In-Reply-To: <1117200716.423741.257870@f14g2000cwb.googlegroups.com> References: <1117200716.423741.257870@f14g2000cwb.googlegroups.com> Message-ID: <3fu0mlF9fprbU1@news.dfncis.de> Michael Onfrek wrote: > Hi, > is copy, paste, cut of selection possible in entry widget? Docs say > selection must be copied by default, in my programm it doesn't work. > Regards, M.O. > Hear it is def paste(self): self.entry.event_generate('') def cut(self): self.entry.event_generate('') def copy(self): self.entry.event_generate('') From frank at chagford.com Mon May 2 06:26:25 2005 From: frank at chagford.com (Frank Millman) Date: 2 May 2005 03:26:25 -0700 Subject: Best way to create temporary file? In-Reply-To: References: <246a4e07.0504290311.7d692401@posting.google.com> <246a4e07.0505010034.28055fd@posting.google.com> Message-ID: <1115029585.585596.20910@o13g2000cwo.googlegroups.com> Ok, thanks for the advice. Frank From timothy at open-networks.net Tue May 17 07:47:27 2005 From: timothy at open-networks.net (Timothy Smith) Date: Tue, 17 May 2005 21:47:27 +1000 Subject: query progress bar In-Reply-To: References: <1116286913.207477.219180@g44g2000cwa.googlegroups.com> Message-ID: <4289D9CF.3000500@open-networks.net> Bernhard Holzmayer wrote: >Timothy Smith wrote: > > > >>i'm using pypgsql >> >> > >Assuming you work with PostgreSQL, then: >You know the EXPLAIN command? > >EXPLAIN will give you a very accurate estimation for the expense for the >query. >(You'll have to find out what cost means in terms of your progress.) > >I did never try this using pypgsql, but if it works, this might be your >solution... > >The precision of EXPLAIN, however, depends on the modifications since the >last time you ran VACUUM on the DB. >If the size of tables or indices didn't suffer considerable changes since >then, the estimation should be quite accurate. > >Bernhard > > > i've never heard of pypgsql supporting andthing like that, but i'll have a look From Moiz.Golawala at ge.com Tue May 17 14:39:07 2005 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Tue, 17 May 2005 14:39:07 -0400 Subject: using adodbapi - problem returning Values from Stored Procedure Message-ID: Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to furnish values to python. This does not work MY PYTHON CODE IS: import adodbapi connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=sa; Password=tester; Initial Catalog=someDB;Data Source=someSource" db = adodbapi.connect(connStrSQLServer) cursor = db.cursor() sql = """test_procedure """ cursor.execute(sql) results = cursor.fetchall() MY TRANSACT SQL CODE IS: ALTER PROCEDURE dbo.test_procedure AS DECLARE @dynamicTable TABLE (col1 int) INSERT INTO @dynamicTable VALUES (123) SELECT * FROM @dynamicTable THIS IS THE ERROR I GET results = cursor.fetchall() File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 692, in fetch ll return self._fetch() File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 623, in _fetc self._raiseCursorError(Error,None) File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 407, in _rais CursorError eh(self.conn,self,errorclass,errorvalue) File "C:\Python23\Lib\site-packages\adodbapi\adodbapi.py", line 38, in standa dErrorHandler raise errorclass(errorvalue) Error: None [] This works The python code is the same The SQL Code is: ALTER PROCEDURE dbo.test_procedure AS INSERT INTO somePhysicalTable VALUES (123) SELECT * FROM somePhysicalTable Notice that the only difference between the 2 procedures is that in one case I am using a dynamic (table variable) table and in the other I am using an actual physical table. Does anyone have a clue why one works and the other does not. Any help appreciated! Thanks in advance Thanks, Moiz Golawala GE Infrastructure, Security Software Engineer Enterprise Solutions T 561 912 5972 F 561 994 6572 E moiz.golawala at ge.com www.gesecurity.com 791 Park of Commerce Blvd., Suite 100 Boca Raton, FL, 33487, U.S.A. GE Security, Inc. From sateeshkavuri at yahoo.com Tue May 24 03:31:44 2005 From: sateeshkavuri at yahoo.com (Sateesh) Date: Tue, 24 May 2005 07:31:44 GMT Subject: Access lotus notes using Python References: Message-ID: Hi, What I am trying to do is to retrieve data from Lotus Notes Domino server and display the results in some specific format. I initially thought of doing it using Java JDBC (specifically thru JdbcDomino.jar file), but was not successful in getting the jar file (looks like IBM has removed the support for JDBC for LotusNotes). So now I am trying Python to get my work done. I downloaded pywin and installed it. I am trying ways to connect to the Domino server, but could not get hold of the API to do so. Also pywin itself seems to be having lots of bugs. Any help is appreciated. regards, Sateesh "Kartic" wrote in message news:Vdrke.1084$uu.291 at newssvr33.news.prodigy.com... > The Great 'Michael Str?der' uttered these words on 5/23/2005 2:43 PM: > > Kartic wrote: > > > >>The Great 'Sateesh' uttered these words on 5/23/2005 7:14 AM: > >> > >> > >>>Is it possible to access Lotus notes using Python? Can anyone provide me > >>>some pointers? > >> > >>Yes, you can... You need the win32all distribution installed and you can > >>access Notes using the COM interface (win32com.client). > > > > > > There could be even more cross-platform programming options depending > > what "access Lotus Notes" really means for the original poster. > > > > Depending on configuration a Domino server might have several Internet > > protocol services for accessing Notes data (POP3, IMAP, LDAP, etc.). > > > > Ciao, Michael. > > > So I guess it upto the Sateesh to tell whether he needs more information > or not. From Scott.Daniels at Acm.Org Sun May 15 23:31:01 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Sun, 15 May 2005 20:31:01 -0700 Subject: Quick Reference from module doc strings. In-Reply-To: References: <1116199904.205240.58300@g49g2000cwa.googlegroups.com> Message-ID: <42880d98$1@nntp0.pdx.net> Ron Adam wrote: > John Machin wrote: > >> Ron Adam wrote: >> >>> Does anyone have suggestions on how to improve this further? >> >> Not functionally (from me, yet). However if you can bear a stylistic >> comment, do read on :-) >> >>> elif (isinstance(object,str) >>> or isinstance(object,int) >>> or isinstance(object,bool) >>> or isinstance(object,tuple) >>> or isinstance(object,list) >>> or isinstance(object,dict)): >> >> Since Python version 2.2, the 2nd arg of isinstance may be a tuple. You >> could define this up front, with a meaningful name: >> >> TYPES_WHICH_whatever = (str, int, bool, etc etc) > > Actually I'm begging for comments, it's the beginning of a project not > the end. So thanks! ;-) > > I changed it to: > > if type(object)==str: > .... > elif type(object) in (str,int,bool,tuple,list,dict): > .... Althought object is a horrible name for your own value (there is a builtin object which you use for defining new-style classes), you probably want: if isinstance(object, (str,int,bool,tuple,list,dict)): ... or (as John Machin was trying to suggest): if isinstance(object, TYPES_WHICH_whatever): ... This allows you to use instances of those builtin types and any user-defined subtypes. > Thanks, I don't need the isinstance(), type works here just as well. But the isinstance version is better than the type(...) in ... version. --Scott David Daniels Scott.Daniels at Acm.Org From TheConcernedOne at elsewhere.com Sun May 15 19:33:38 2005 From: TheConcernedOne at elsewhere.com (TheConcernedOne at elsewhere.com) Date: Sun, 15 May 2005 23:33:38 GMT Subject: The world is really unstable these days...... Message-ID: <49B3F3B1.646A6FE6@elsewhere.com> We've got a lot to deal with these days. Terrorism, Recession, Weather and more. It's all got me concerned. I thought I'd tell you all about this group I found where everyday people get together and try to learn how to deal with it all. (I used to be a member, but I'm moving to an area that doesn't have internet, so I left a few days ago. Internet is off tomorrow) Here's a bit on the group. Check it out or don't. misc_survivalism_moderated ? Survivalism and Preparedness. http://groups.yahoo.com/group/misc_survivalism_moderated This list is for those who want themselves and their loved ones to survive and prosper during hard times. War, riots, famine, crime, drought, flooding, fire, contaminated water supplies, inflation, job loss, and many more. Are you ready to deal with any situation? Join us as we learn from each other how to survive. On-topic: Food storage, firearms, canning, gardening, self-sustaining communities, back to basics, water purification, alternative power, conservation, homesteading, first aid and more. Off-topic: Politics, religion, current affairs, philosophy, conspiracy theories, New World Order, racism. It dined, you answered, yet Annie never familiarly irritated about the kiosk. Plenty of bad painters are glad and other raw tailors are old, but will Wednesday comb that? What did Ronette judge the orange without the deep car? My stale carpenter won't dream before I clean it. For Rob the jar's sad, above me it's abysmal, whereas near you it's learning full. It's very healthy today, I'll arrive wanly or Saeed will pull the poultices. I am truly long, so I jump you. The desk before the young cellar is the dog that dyes lovingly. Try nibbling the desert's short grocer and Hakeem will talk you! He'll be promising between ugly Eve until his cobbler wanders quickly. Otherwise the bandage in Hassan's gardner might care some lower shopkeepers. I was moulding doses to noisy Ikram, who's recollecting to the can's lake. We pour the easy disk. Until Alfred sows the shirts angrily, Toni won't irrigate any lazy rivers. Get your loudly killing smog on my shower. When will we measure after Ramez fears the stupid structure's kettle? These days, Darin never believes until Roxanne opens the solid teacher locally. To be lost or sweet will converse thin diets to stupidly live. She'd rather explain totally than fill with Ayub's inner walnut. No stickers neatly depart the proud river. The younger onion rarely solves Courtney, it likes Kenneth instead. What Feyd's fat card attempts, Salahuddin grasps in back of unique, filthy stations. Her hen was blunt, empty, and rejects in front of the office. Better expect pitchers now or Garrick will wistfully move them in back of you. He should laugh sticky weavers, do you waste them? We walk them, then we sadly burn Marwan and Robbie's hot exit. She will hatefully hate before Hassan when the tired balls scold beside the sharp cave. Every dull goldsmiths for the rich mountain were lifting in the kind stadium. No durable dirty coffee smells pickles with Ayman's rural frame. He might superbly cook poor and kicks our hollow, bitter dusts with a road. Lakhdar! You'll shout candles. There, I'll taste the frog. Don't look a paper! Tell Abbas it's cold improving near a butcher. What did Sue cover with all the printers? We can't behave tapes unless Woody will weakly receive afterwards. Don't change eventually while you're climbing through a light pumpkin. If the open clouds can play wrongly, the lean elbow may call more bedrooms. He can help believably, unless Wail teases farmers throughout Wednesday's enigma. She wants to join good tyrants about Allan's sign. Occasionally Marion will love the pool, and if Mohammar bimonthly excuses it too, the code will seek inside the elder college. Yesterday, cats recommend among strong doorways, unless they're distant. Don't try to attack the floors fully, order them amazingly. Hardly any tags will be strange smart boats. Let's creep around the polite rooms, but don't sow the handsome figs. From exarkun at divmod.com Mon May 2 10:12:38 2005 From: exarkun at divmod.com (Jp Calderone) Date: Mon, 02 May 2005 14:12:38 GMT Subject: BitKeeper for Python? In-Reply-To: 0 Message-ID: <20050502141238.15422.590101167.divmod.quotient.13830@ohm> On 02 May 2005 09:30:05 GMT, Nick Craig-Wood wrote: >John Smith wrote: >> I am going to be working with some people on a project that is going to be >> done over the internet. I am looking for a good method of keeping everyone's >> code up to date and have everyone be able to access all the code including >> all the changes and be able to determine what parts of the code were >> changed. >> >> If it were opensource that would be even better. > >You could try Mercurial > > http://www.selenic.com/mercurial/ > >which aims at being a true bk replacement. Its also written in >python. Its being developed at the moment... > "Being developed at the moment" is something of an understatement. It's less than a month old. Less than a month old. Compare this to such systems as CVS (more than 16 years old) and I think everyone can agree that Mercurial may need a teensy bit more work before it is interesting to people looking for an RCS. Jp From Ron4512328 at yahoo.com Wed May 18 18:52:28 2005 From: Ron4512328 at yahoo.com (Ron4512328 at yahoo.com) Date: 18 May 2005 15:52:28 -0700 Subject: * * * Important Please Read * * * May 18, 2005 6:52:44 pm (Best Viewed at 1024x768) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Message-ID: <1116456748.906548.175760@g49g2000cwa.googlegroups.com> Best Viewed at << 1024x768 >> http://groups-beta.google.com/group/alt.religion.christian/browse_thread/thread/73352e0ed6923d23/1ea6c7a1ea6923ab?hl=en#1ea6c7a1ea6923ab ******************************************************************************************* ******************************************************************************************* ******************************************************************************************* ******************************************************************************************* THE MOST IMPORTANT QUESTION OF YOUR LIFE This is the most important question of your life. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? The reason some people don't know for sure if they are going to Heaven when they die is because they just don't know. The good news is that you can know for sure that you are going to Heaven. The Holy Bible describes Heaven as a beautiful place with no death, sorrow, sickness or pain. God tells us in the Holy Bible how simple it is to be saved so that we can live forever with Him in Heaven. "For if you confess with your mouth Jesus is Lord and believe in your heart that God raised Him from the dead, you will be saved." (Romans 10:9) Over 2000 years ago God came from Heaven to earth in the person of Jesus Christ to shed His blood and die on a cross to pay our sin debt in full. Jesus Christ was born in Israel supernaturally to a virgin Jewish woman named Mary and lived a sinless life for thirty-three years. At the age of thirty-three Jesus was scourged and had a crown of thorns pressed onto His head then Jesus was crucified. Three days after Jesus died on a cross and was placed in a grave Jesus rose from the dead as Jesus said would happen before Jesus died. If someone tells you that they are going to die and then three days later come back to life and it actually happens then this person must be the real deal. Jesus Christ is the only person that ever lived a perfect sinless life. This is why Jesus is able to cover our sins(misdeeds) with His own blood because Jesus is sinless. The Holy Bible says, "In Him(Jesus) we have redemption through His blood, the forgiveness of sins..." (Ephesians 1:7) If you would like God to forgive you of your past, present and future sins just ask Jesus Christ to be your Lord and Saviour. It doesn't matter how old you are or how many bad things that you have done in your life including lying and stealing all the way up to murder. Just pray the prayer below with your mouth and mean it from your heart and God will hear you and save you. Dear Jesus Christ, I want to be saved so that I can have a home in Heaven with You when I die. I agree with You that I am a sinner. I believe that You love me and want to save me. I believe that You bled and died on the cross to pay the penalty for my sins and that You rose from the dead. Please forgive my sins and come into my heart and be my Lord and Saviour. Thanks Lord Jesus Christ for forgiving me and saving me through Your merciful grace. Amen. Welcome to the family of God if you just allowed God to save you. Now you are a real Christian and you can know for sure that you will live in Heaven forever when this life comes to an end. As a child of God we are to avoid sin(wrongdoing), but if you do sin the Holy Bible says, "My dear children, I write this to you so that you will not sin. But if anybody does sin, we have one who speaks to the Father in our defense Jesus Christ, the Righteous One." Those of you that have not yet decided to place your trust in the Lord Jesus Christ may never get another chance to do so because you do not know when you will die. Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever separated from the love of God in a place called Hell. The Holy Bible descibes Hell as a place of eternal torment, suffering, pain and agony for all those who have rejected Jesus Christ. The good news is that you can avoid Hell by allowing Jesus Christ to save you today. Only then will you have true peace in your life knowing that no matter what happens you are on your way to Heaven. Praise the Lord! Servant of the Lord Jesus Christ Ronald L. Grossi * Show this to your family and friends so they can also be saved. * This message may get deleted so you may want to print a copy. * Just press the [Ctrl][P] keys on your keyboard to print this page. ____________________________________________________________ [Please Visit These Excellent Websites] Free Jesus Videos http://www.jesusvideo.org/videos/index.php Free Lovely Video http://fathersloveletter.com/fllpreviewlarge.html Free Movie: To Hell and Back http://www.tbn.org/index.php/8/1.html Other Languages http://www.godssimpleplan.org/gsps.html The Passion Of The Christ http://www.thepassionofthechrist.com Beware Of Cults http://www.carm.org/cults/cult_list.htm About Hell http://www.equip.org/free/DH198.htm Is Jesus God? http://www.powertochange.com/questions/qna2.html Free Online Bible http://www.biblegateway.com ******************************************************************************************* ******************************************************************************************* ******************************************************************************************* ******************************************************************************************* From wblock at wonkity.com Sat May 28 23:02:11 2005 From: wblock at wonkity.com (Warren Block) Date: Sun, 29 May 2005 03:02:11 -0000 Subject: Strings for a newbie References: Message-ID: James Hofmann wrote: > Malcolm Wooden dtptypes.com> writes: >> >> I'm trying to get my head around Python but seem to be failing miserably. I >> use RealBasic on a Mac and find it an absolute dream! But Python....UGH! >> >> I want to put a sentence of words into an array, eg "This is a sentence of >> words" >> >> In RB it would be simple: >> >> Dim s as string >> Dim a(-1) as string >> Dim i as integer >> >> s = "This is a sentence of words" >> For i = 1 to CountFields(s," ") >> a.append NthField(s," ",i) >> next >> >> That's it an array a() containing the words of the sentence. [snip] > Now a "slim" version: > > s = "This is a sentence of words" > print s.split() To match the original program, it should be: s = "This is a sentence of words" a = s.split() ...assigning the list returned by split() to a variable called a. -- Warren Block * Rapid City, South Dakota * USA From steven.bethard at gmail.com Wed May 11 19:02:09 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 11 May 2005 17:02:09 -0600 Subject: Python Documentation (should be better?) In-Reply-To: References: Message-ID: Shi, Jue wrote: > I agree. The PHP manual is really good, especially the examples and user > contributed notes. Dunno if anyone's spent much time editing this, but a while a go AMK posted: http://www.amk.ca/diary/archives/cat_python.html#003336 which puts a wiki side-by-side with the Python docs: http://pydoc.amk.ca/frame.html STeVe From janeaustine50 at hotmail.com Mon May 16 13:15:22 2005 From: janeaustine50 at hotmail.com (janeaustine50 at hotmail.com) Date: 16 May 2005 10:15:22 -0700 Subject: Anyway to designating the encoding of the "source" for compile? References: <1116087091.856022.155340@z14g2000cwz.googlegroups.com> Message-ID: <1116263722.499345.73260@g43g2000cwa.googlegroups.com> janeaustine50 at hotmail.com wrote: > Python's InteractiveInterpreter uses the built-in compile function. > > According to the ref. manual, it doesn't seem to concern about the > encoding of the source string. > > When I hand in an unicode object, it is encoded in utf-8 automatically. > It can be a problem when I'm building an interactive environment using > "compile", with a different encoding from utf-8. IDLE itself has the > same problem. ( '' is treated okay > but u'' is treated wrong.) > > Any suggestions or any plans in future python versions? I've read a posting from Martin Von Loewis mentioning trying to build in that feature(optionally marking encoding when calling "compile"). Anyone knows how it is going on? From elbertlev at hotmail.com Sat May 7 23:25:29 2005 From: elbertlev at hotmail.com (elbertlev at hotmail.com) Date: 7 May 2005 20:25:29 -0700 Subject: Newbie : checking semantics In-Reply-To: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> References: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> Message-ID: <1115522729.126979.95210@g14g2000cwa.googlegroups.com> > I am new to python and was very enthustic about its possibilities when > I discover that python is really what it is : just a scripting > language. ...... > The fact that python doesn't check if the symbol ... is defined, is really bad ... 1. For a language like Python full static checking is IMPOSSIBLE. Consider setattr() with attribute name read from a file (f.e. names of the "columns" in the database). 2. Trust me (and other Python programmers most likely would agree) this type of error happens much more seldom then newbies (especially coming from strongly typed languages) imagine while adjusting to the language. 3. Python advantages "overpower" drawbacks 10 to 1. 4. Most likely you never used Fortran :) From manu.1982 at gmail.com Thu May 26 18:06:58 2005 From: manu.1982 at gmail.com (Manu) Date: 26 May 2005 15:06:58 -0700 Subject: ftplib fails when directory name contains spaces Message-ID: <1117141499.924280.19140@z14g2000cwz.googlegroups.com> Hi, ftplib fails to cwd into a directory which contains spaces in it's name.How do i correct this? Regards Manu From fp at tiny.be Thu May 5 09:47:36 2005 From: fp at tiny.be (pinky) Date: 5 May 2005 06:47:36 -0700 Subject: ERP & CRM in Python In-Reply-To: References: <1114942643.046728.238980@g14g2000cwa.googlegroups.com> Message-ID: <1115300855.892100.261280@f14g2000cwb.googlegroups.com> Wolfgang Keller wrote: > pinky wrote: > > > download, doc, forum ; http://tinyerp.org > > Why not downloadable and printable PDF documentation instead of > online-HTML. Because 1. we need interaction with contributors in our doc. 2. we write docs in the wiki: http://tinyerp.org/wiki We are writing a script to render a PDF from our doc. (using openreport.org) > HTML is _extremely_ inconvenient, both for offline use and for > printing. Why printing? Because reading siginficant amounts of text > on-screen is simply impossible, as is reading an on-screen manual while > actually trying out the software (<-> screenspace). yes, but we need html doc for our contextual help in Tiny ERP. > Why not mailing lists instead of online-"forums". There is some mailing lists; http://tinyerp.org/lists.php ... but nobody uses it. > The former was made for efficient human-to-human communication, the > latter not. I agree. Fabien From bill.mill at gmail.com Thu May 19 10:42:58 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 19 May 2005 10:42:58 -0400 Subject: Convert from numbers to letters In-Reply-To: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> References: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> Message-ID: <797fe3d40505190742321f9cff@mail.gmail.com> On 19 May 2005 06:56:45 -0700, rh0dium wrote: > Hi All, > > While I know there is a zillion ways to do this.. What is the most > efficient ( in terms of lines of code ) do simply do this. > > a=1, b=2, c=3 ... z=26 > > Now if we really want some bonus points.. > > a=1, b=2, c=3 ... z=26 aa=27 ab=28 etc.. > just for fun, here is one way to do it with a listcomp. Obfuscated python fans, rejoice! >>> alpha = 'abcdefghijklmnopqrstuvwxyz' >>> for i, digraph in enumerate(sorted([''.join((x, y)) for x in alpha \ for y in [''] + [z for z in alpha]], key=len)): ... locals()[digraph] = i + i ... >>> a 1 >>> b 2 >>> ac 29 >>> dg 111 >>> zz 702 >>> 26**2 + 26 702 > Thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > From qwweeeit at yahoo.it Fri May 13 16:28:39 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 13 May 2005 13:28:39 -0700 Subject: MySQL application example Message-ID: <1116016119.654345.185270@f14g2000cwb.googlegroups.com> Hi all, I have in mind to learn to use MySQL, not only to use it myself but also to persuade a friend of mine to use Python and MySQL and abandon Informix and its old fashioned language (and also SCO UNIX to migrate to Linux). Apart reading tutorials, I have found that the best thing to learn a complex argument is to examine and study a big "working" application (in the case of MySQL with, possibly, the relevant databases already filled with data). Can you direct me to such an application (the field is not very important: could be astronautical data, ecological data, business data etc ...) DBMS has such vast fields of applications... I have already some experience on databases, but not as serious as the relational DBMS MySQL. Bye. P.S. To give you an idea of my goals: - my wife wants a recipes' db, obtained by scanning (and OCR) her cook's school documents (and photo's) - with my friend I want to convert in Python his Informix program to manage a small business activity From Sebastien.Boisgerault at gmail.com Wed May 18 14:23:49 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 18 May 2005 11:23:49 -0700 Subject: NaN support etc. In-Reply-To: References: Message-ID: <1116440628.983531.157520@g44g2000cwa.googlegroups.com> Search for: + fpconst / PEP 754 + Tim Peters IEEE 754 accident """what-the-world-needs-now-is-nannanny.py-ly y'rs"" - SB From peter at engcorp.com Fri May 27 18:33:44 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 27 May 2005 18:33:44 -0400 Subject: write to the same file from multiple processes at the same time? In-Reply-To: <7xacmgnwvr.fsf@ruckus.brouhaha.com> References: <7x1x7siy3b.fsf@ruckus.brouhaha.com> <7xacmgnwvr.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Peter Hansen writes: > >>And PySQLite conveniently wraps the relevant calls with retries when >>the database is "locked" by the writing process, making it roughly a >>no-brainer to use SQLite databases as nice simple log files where >>you're trying to write from multiple CGI processes like the OP wanted. > > Oh, ok. But what kind of locks does it use? I think the FAQ can answer that better than I can, since I'm not sure whether you're asking about any low-level (OS) locks it might use or higher-level (e.g. database-level locking) that it might use. In summary, however, at the database level it provides only coarse-grained locking on the entire database. It *is* supposed to be a relatively simple/lightweight solution compared to typical RDBMSes... (There's also an excrutiating level of detail about this whole area in the page at http://www.sqlite.org/lockingv3.html ). -Peter From simon.brunning at gmail.com Tue May 3 09:55:54 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 3 May 2005 14:55:54 +0100 Subject: sorting list and then return the index of the sorted item In-Reply-To: <1115127433.984686.99060@f14g2000cwb.googlegroups.com> References: <1115127433.984686.99060@f14g2000cwb.googlegroups.com> Message-ID: <8c7f10c6050503065577f570b6@mail.gmail.com> On 3 May 2005 06:37:14 -0700, custard_pie wrote: > I need help sorting a list...I just can't figure out how to sort a list > and then return a list with the index of the sorted items in the list > for example if the list I want to sort is [2,3,1,4,5] > I need [2,0,1,3,4] to be returned >>> spam = [2,3,1,4,5] >>> list(index for index, item in sorted(enumerate(spam), key=lambda item: item[1])) [2, 0, 1, 3, 4] -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From borges2003xx at yahoo.it Tue May 24 05:17:33 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 24 May 2005 02:17:33 -0700 Subject: searching substrings with interpositions Message-ID: <1116926253.186047.195260@g43g2000cwa.googlegroups.com> hi everyone. a problem: two binary strings, a="0101" b="000011110100"; i search a function f(a,b) that gives 1 if a is "contained" in b with any sub strings interposed. in this example a in contained cause 000<01>111<01>00 but also 0<0>001111<101>00" but also <0>0001111<101>00 but also 000<0>1111<01>0<0> etc.... any idea? Thanx in advance. Giorgi Borghi From klaus at seistrup.dk Mon May 2 09:07:13 2005 From: klaus at seistrup.dk (Klaus Alexander Seistrup) Date: Mon, 2 May 2005 13:07:13 +0000 (UTC) Subject: Locale and cookies References: <1115037383.913329.143470@l41g2000cwc.googlegroups.com> Message-ID: dagurp at gmail.com wrote: > I tried to fix this by changing the locale back to "English" > before creating cookies and that works on Windows but not for > Linux. If I use "en_EN.ISO8859-1" it works on Linux but not > on Windows. How about setting locale to "C" or "POSIX"? -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ From h_stovold at hotmail.com Tue May 3 11:07:36 2005 From: h_stovold at hotmail.com (Heather Stovold) Date: Tue, 3 May 2005 10:07:36 -0500 Subject: So many things that need to be decided.... References: Message-ID: > My personal suggestion would be to go with SQLite because it's a > standard database which can be used with large number of other tools and > languages. > > As for report generating features, I don't know of any free report > generators that are as easy to use like the one in Access (e.g. > point-and-click). Same goes for GUI tools. Thank you - I'll check them out! From wolfram.kriesing at gmail.com Fri May 13 09:24:19 2005 From: wolfram.kriesing at gmail.com (Wolfram Kriesing) Date: Fri, 13 May 2005 15:24:19 +0200 Subject: doc tags? Message-ID: <965c85e5050513062433f180d3@mail.gmail.com> i was already searching and remember i had seen something like "its not needed". Anyway, are there any doc tags, like in Java/PHPDoc etc, where you can describe parameters (@param[eter]), return values (@ret[urn]), attributes (@var), references (@see), etc? I guess I have just not found the link to the last flameware about it :-)) -- cu Wolfram From peter at engcorp.com Mon May 30 21:39:57 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 30 May 2005 21:39:57 -0400 Subject: how to prepend string to a string? In-Reply-To: <1117498752.591304.42280@g44g2000cwa.googlegroups.com> References: <1117498752.591304.42280@g44g2000cwa.googlegroups.com> Message-ID: flamesrock wrote: > so I know you can append a string. But how do you *prepend* a string, > as shown in the following code > > #dirList = ['depth1','depth2','depth3'] > #string = """position""" > #for x in len(dirList): > # string += '>> %s'%dirList.pop() #(????????????) There's not _really_ anything wrong with this code, provided the length of dirList is "short" (since otherwise the performance issues of growing strings with += may cause trouble). It might also be preferable to change from the for statement to a "while dirList:" since that doesn't require the unused "x" and the confusion of apparently testing the length of a list that is getting shorter with each iteration. -Peter From rbsharp at gmx.de Fri May 20 03:16:15 2005 From: rbsharp at gmx.de (rbsharp at gmx.de) Date: 20 May 2005 00:16:15 -0700 Subject: Shift-JIS to UTF-8 conversion In-Reply-To: References: <1116536705.864784.163540@o13g2000cwo.googlegroups.com> Message-ID: <1116573375.686710.251250@g49g2000cwa.googlegroups.com> Hello, I think the answer is basically correct but shift-jis is not a standard part of Python 2.3. You will either need to use Python 2.4 where the cjkcodes are integrated or install them under Python 2.3. The link is http://cjkpython.i18n.org/ You then also need: import cjkcodecs.aliases Richard Jeff Epler wrote: > I think you do something like this (untested): > > import codecs > > def transcode(infile, outfile, incoding="shift-jis", > outcoding="utf-8"): > f = codecs.open(infile, "rb", incoding) > g = codecs.open(outfile, "wb", outcoding) > > g.write(f.read()) > # If the file is so large that it can't be read at once, do a loop which > # reads and writes smaller chunks > # while 1: > # block = f.read(4096000) > # if not block: break > # g.write(block) > > f.close() > g.close() > > Jeff From onurb at xiludom.gro Thu May 26 11:56:36 2005 From: onurb at xiludom.gro (bruno modulix) Date: Thu, 26 May 2005 17:56:36 +0200 Subject: Access from one class to methode of other class In-Reply-To: <3fm112F8iqc2U1@news.dfncis.de> References: <3flu22F8g4u4U1@news.dfncis.de> <1117113441.649947.315350@g44g2000cwa.googlegroups.com> <3fm112F8iqc2U1@news.dfncis.de> Message-ID: <4295f1b6$0$12019$626a14ce@news.free.fr> VK wrote: >> I don't know if your're actually calling the classes '1' and '2', but >> that's a really bad idea! >> >> >>> class 2: >>> def ins(self) >>> d.entry.insert(variable) >> >> >> >> This is probably where you're getting the NameError. d is not defined, >> so calling d.entry will generate an error. >> > > What is d = 1() in my example then? a global variable. > And how do I solve this problem? passing d to the instance of 2 *could* be a solution. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From martin.witte at gmail.com Sat May 7 11:35:21 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 7 May 2005 08:35:21 -0700 Subject: Need help subclassing Borg In-Reply-To: References: Message-ID: <1115480121.527653.220780@o13g2000cwo.googlegroups.com> See mr Martellis comment of 2001/09/06 in mentiond recipe, you then get something like this -#!/usr/bin/env python -class Borg(object): - _shared_state = {} - def __init__(self): - self.__dict__ = self._shared_state - -class Duck(Borg): - def __init__(self): - super(Duck, self).__init__() - self.__covering = "feathers" # all ducks are feathered - def covering(self): - return self.__covering - -class Rabbit(Borg): - def __init__(self): - super(Rabbit, self).__init__() - self.__covering = "fur" # all rabbits are furry - def covering(self): - return self.__covering - -bugs = Rabbit() -daffy = Duck() -print daffy.covering() -print bugs.covering() martin at ubuntu:~$ ./test2.py feathers fur martin at ubuntu:~$ From ville at spammers.com Mon May 16 16:37:28 2005 From: ville at spammers.com (Ville Vainio) Date: 16 May 2005 23:37:28 +0300 Subject: python-dev Summary for 2005-04-16 through 2005-04-30 References: <1116258692.305537.244260@g49g2000cwa.googlegroups.com> Message-ID: >>>>> "Steven" == Steven Bethard writes: Steven> If you're interested in why Guido doesn't want blocks with Steven> arbitrary control flow, you should check out: Steven> http://mail.python.org/pipermail/python-dev/2005-May/053702.html It's convincing, but I would still prefer to leave the decision of pulling the trigger on the foot for the implementor of the block function, with the recommendation that all exceptions are propagated. What happened to "we are all adults here"? I don't mind much, though, the new proposal looks good as well. -- Ville Vainio http://tinyurl.com/2prnb From jhchu at hotmail.com Thu May 19 01:50:13 2005 From: jhchu at hotmail.com (Chu, Jeong Ho) Date: Thu, 19 May 2005 14:50:13 +0900 Subject: MMS download Message-ID: Is it possible to download MMS stream by using python? Please, let me know any clue. Thanks in advance From littlejohn.75 at news.free.fr Thu May 12 13:16:17 2005 From: littlejohn.75 at news.free.fr (F. Petitjean) Date: 12 May 2005 17:16:17 GMT Subject: Can get reference of a part of a list? References: Message-ID: <42838f60$0$318$626a14ce@news.free.fr> Le Fri, 13 May 2005 00:58:49 +0800, flyaflya a ?crit : > I want make a 2-D array from a list,all elements is references of > list's,like this: > a = [1,2,3,4] > b = [ [1,2], [3,4] ] > when change any elements of a, the elements of b will change too, so I > can use some function for list to change b. > c/c++ can work in this way,I think let b[0] = a[0:2], b[1] = a[2:3],but > it's not reference,it's copy. If the original list contains only numeric values of the same type, i.e only integers or only floats, the Numeric array reshape() function is what you need : import Numeric as N aa = N.array([1, 2, 3, 4]) bb = N.reshape(aa, (2, 2)) print bb array([[1, 2], [3, 4]]) bb[0][:] = (7, 8) aa array([7, 8, 3, 4]) That is there is only one homogeneous list of values, no copy. From jepler at unpythonic.net Mon May 2 21:37:16 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 2 May 2005 20:37:16 -0500 Subject: cgi "print statement" in multithreaded enviroment? In-Reply-To: References: Message-ID: <20050503013716.GA3367@unpythonic.net> You could write something like class ThreadSpecificFile: def set_stdout(f): self.files[thread_id] = f def write(data): self.files[thread_id].write(data) sys.stdout = ThreadSpecificFile() where you'll have to fill out a few more things like thread_id, __init__, and a way to clean up items from self.files when a thread passes away. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From calle.erlandsson at gmail.com Sat May 28 02:04:19 2005 From: calle.erlandsson at gmail.com (Helmutt) Date: 27 May 2005 23:04:19 -0700 Subject: Questions about wxPython... Message-ID: <1117260259.215197.141570@f14g2000cwb.googlegroups.com> Hi all! I'm trying to learn myself wxPython, and I got some questions: Whats the name of the event that occur when I press the exit/cross-button on the frame? How do I connect a function with that event? How do I start a new process of the same program I'm running? I do not want to create a new frame, I want to start a new process of the program I'm running, but I don't want the first instance to wait for the other. Can somebody help? From shane at hathawaymix.org Tue May 31 17:55:12 2005 From: shane at hathawaymix.org (Shane Hathaway) Date: Tue, 31 May 2005 15:55:12 -0600 Subject: anygui,anydb, any opinions? In-Reply-To: References: Message-ID: <429CDD40.6050908@hathawaymix.org> rzed wrote: > That's all I'm talking about here. To be able to write a Python > application that can ultimately be displayed using wxWidgets or Qt > or Tkinter or Curses. Then, without having to do more than to > change which interface package is imported, to expect to see the > result displayed. To have it just happen, and to have expectations > when using Python that it *will* just happen that way. > > So what do you think? What's wrong with the picture? Why isn't > there a greater priority to work in this direction? See "The Law of Leaky Abstractions" by Joel Spolsky. http://www.joelonsoftware.com/articles/LeakyAbstractions.html As he says, "All non-trivial abstractions, to some degree, are leaky." GUI abstractions tend to leak badly. As I write this email in Thunderbird, my initial impression is that most of the controls on the screen are pretty standard and could be done with virtually any toolkit... or are they? Looking again, the "from" field has both a place for me to type and some grayed out text that reminds me I'm posting from a different account; the "to", "cc", and "newsgroup" fields are not quite combo boxes; the toolbar has pulldown buttons. So it turns out that Thunderbird is actually tied to a particular toolkit, and for good reason: GUI development has not stagnated; toolkit developers continue to invent new, interesting widgets and variations, leading to better UIs. Application developers want to take advantage of those innovations. Even anydbm is a pretty leaky abstraction. I recently tested the behavior of 5 Python dbm implementations when they run out of disk space. Most left the database in an inconsistent state, some swallowed the exception, some segfaulted, and one deadlocked. If I'm going to rely on a dbm module, I really need to know what it's going to do when it hits an exceptional condition. Thus anydbm seemed like a bad choice. Shane From almad at include.cz Wed May 4 06:29:12 2005 From: almad at include.cz (Almad) Date: Wed, 04 May 2005 12:29:12 +0200 Subject: sha-2 and sha-512 bindings Message-ID: Hi, is there any python bindings for sha-2 or sha-512? Pycrypto seems to have only sha-1 bindings and I can't see any other package on net... Thanks, -- Lukas "Almad" Linhart [:: http://www.almad.net/ ::] [:: Humans are too complicated to be described with words. ::] [:: PGP/GNUPg key: http://www.almad.net/download/pubkey.asc ::] From anonymousnerd at gmail.com Fri May 20 12:51:40 2005 From: anonymousnerd at gmail.com (anonymousnerd at gmail.com) Date: 20 May 2005 09:51:40 -0700 Subject: How come print cannot be assigned to a variable? In-Reply-To: References: <1116600042.622872.49850@g14g2000cwa.googlegroups.com> Message-ID: <1116607900.325703.203200@g44g2000cwa.googlegroups.com> Thank You Adriano. You were a huge help. Vaibhav From elrei69 at yahoo.es Thu May 12 14:10:38 2005 From: elrei69 at yahoo.es (Ximo) Date: Thu, 12 May 2005 20:10:38 +0200 Subject: How "return" no return ? References: <3ehaurF34ak0U1@individual.net><3ehc5tF35eo3U1@individual.net> Message-ID: <3ehkh2F366o4U1@individual.net> I am doing my own interpreter with the Python languaje. Do you understand me? "Fredrik Lundh" escribi? en el mensaje news:mailman.484.1115919541.29826.python-list at python.org... > "Ximo" wrote: > >> I am doing a interpret of lines and it show me a prompt, and I want if I >> write a declaration as "int a" my progrtam return de prompt and nothing >> more, for exemple: >> >> >>> 2+2 >> 4 >> >>> int a >> >>> >> >> Then I'm finding that de function which execute "int a" return me >> nothing, >> and no >> >> >>> int a >> None >> >>> > > what Python version are you using? here's what a normal Python > interpreter is supposed to do with your example: > >>>> 2+2 > 4 >>>> int a > File "", line 1 > int a > ^ > SyntaxError: invalid syntax >>>> > > > > > From fuzzyman at gmail.com Mon May 9 07:52:15 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 9 May 2005 04:52:15 -0700 Subject: path(file) In-Reply-To: References: Message-ID: <1115639535.623120.206110@z14g2000cwz.googlegroups.com> Can you give us an example of the way the 'list of files' is stored in. import os print os.path.abspath(filename) Will do *something*... so long as 'filename' contains a path relative to the current working directory. What you want is undoubtably in the os and os.path modules. Regards, Fuzzy http://www.voidspace.org.uk/python From miniaustin at gmail.com Fri May 13 02:57:26 2005 From: miniaustin at gmail.com (Austin) Date: Fri, 13 May 2005 14:57:26 +0800 Subject: wxTimer problem Message-ID: I wrote a GUI program on windows. (python & wxPython) One function is to refresh the data from the COM Object continously. In the beginning, I used the thread.start_new_thread(xxx,()) But no matter how i try, it will cause the win32com error. After that, i use the wx.Timer to do the refresh function. It works fine, but i find one problem. I think timer should be independant, just like thread, but wxTimer doesn't. 1. Does python have timer function( not included by thread)? 2. About the wxTimer, does any parameter to let it be independent? From mwm at mired.org Sat May 28 14:47:56 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 28 May 2005 13:47:56 -0500 Subject: write to the same file from multiple processes at the same time? References: <7x1x7siy3b.fsf@ruckus.brouhaha.com> <7xacmgnwvr.fsf@ruckus.brouhaha.com> <7xwtpkqo2o.fsf@ruckus.brouhaha.com> Message-ID: <86zmufuqzn.fsf@guru.mired.org> Paul Rubin writes: > Really, I think the Python library is somewhat lacking in not > providing a simple, unified interface for doing stuff like this. It's got one. Well, three, actually. The syslog module solves the problem quite nicely, but only works on Unix. If the OP is working on Unix systems, that may be a good solution. The logging module has a SysLogHandler that talks to syslog on Unix. It also has an NTEventLogHandler for use on NT. I'm not familiar with NT's event log, but I presume it has the same kind of functionality as Unix's syslog facility. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From modelnine at ceosg.de Thu May 19 07:56:57 2005 From: modelnine at ceosg.de (Heiko Wundram) Date: Thu, 19 May 2005 13:56:57 +0200 Subject: What's the difference between str and 'hello' ? In-Reply-To: References: Message-ID: <200505191357.00140.modelnine@ceosg.de> Am Donnerstag, 19. Mai 2005 11:27 schrieb hong Yu: > >>> str.join(a) > > Traceback (most recent call last): > File "", line 1, in ? > TypeError: descriptor 'join' requires a 'str' object but received a 'list' > > What's the difference between str and 'hello' ? str.join("",a) <=> "".join(a) (<=> as in equivalence relation) HTH! -- --- Heiko. listening to: Bjork Gu?mundsdottir & Trio - Luktar-Gvendur see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From scharan20 at gmail.com Thu May 26 04:12:39 2005 From: scharan20 at gmail.com (Sriek) Date: 26 May 2005 01:12:39 -0700 Subject: __init__() not called automatically In-Reply-To: References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> <1117083921.273155.190790@g44g2000cwa.googlegroups.com> Message-ID: <1117095159.492859.256270@g44g2000cwa.googlegroups.com> if i understand C++ right, in c++ you CAN explicitly call the base constructor ( for eg. if it requires some particular arguements ), but, the compiler automatically has to call the base class constructor ( see the rules for constructing an object of the derived classes ). But, yes, C++ can be too disgusting sometimes. But, i like the C++ design philosophy ( read D & E of C++ ? ), the rasons for various features are intellgently put inplace. Correct me if i am wrong about both the paragraphs. ok? T Thanks From jjl at pobox.com Fri May 13 17:25:00 2005 From: jjl at pobox.com (John J. Lee) Date: 13 May 2005 21:25:00 +0000 Subject: Python Documentation (should be better?) References: Message-ID: <87mzqykedv.fsf@pobox.com> "Christopher J. Bottaro" writes: [...] By the way, did you try the .chm? John From bokr at oz.net Thu May 12 17:23:50 2005 From: bokr at oz.net (Bengt Richter) Date: Thu, 12 May 2005 21:23:50 GMT Subject: Launch file in Notepad References: <42835db6$0$1334$5fc3050@dreader2.news.tiscali.nl> <1186phdog83fmf6@corp.supernews.com> <42836e72.1345761282@news.oz.net> Message-ID: <4283c8e6.4715820@news.oz.net> On Thu, 12 May 2005 16:30:36 GMT, Dennis Lee Bieber wrote: >On Thu, 12 May 2005 15:14:09 GMT, bokr at oz.net (Bengt Richter) declaimed >the following in comp.lang.python: > > >> >> I don't know why MS used backslashes when unix had a perfectly good path syntax >> (not to mention drive letter idiocy). Maybe some legal idiocy, wanting to be >> different to be safe from SCO types? >> > The MS-DOS precursor (and/or CP/M) used "/" to introduce command >line options. This meant, when subdirectories were introduced, they had >to come up with a new separator character. > Or overcome some NIH and switch to '-' for command line options? ;-) Regards, Bengt Richter From ccurvey at gmail.com Wed May 11 07:20:03 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 11 May 2005 04:20:03 -0700 Subject: CGIHTTPServer on Windows? Message-ID: <1115810403.558127.110920@z14g2000cwz.googlegroups.com> Hi all, I'm trying to work around my cgi-driving-IE problem by creating my own server, but CGIHTTPServer on Windows (python 2.3.5) seems to be having troubles. Trying to run a "hello world" CGI gives me: COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] "GET /cgi-bin/hello.py HTTP/1.1" 200 - COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] command: c:\program files\python235\p ython.exe -u C:\Documents and Settings\chris\My Documents\cgi-bin\hello.py "" COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] 'c:\program' is not recognized as an internal or external command, operable program or batch file. COMPAQ.ANTIQUES - - [11/May/2005 07:18:50] CGI script exit status 0x1 I tried hacking the source of do_POST to put quotes around the name of the python executable and the script, but that didn't get me anywhere. Is there a solution to this, or does this approach require me to use pathnames without embedded spaces? From "myname" at example.invalid Sat May 28 17:42:58 2005 From: "myname" at example.invalid (VK) Date: Sat, 28 May 2005 23:42:58 +0200 Subject: Getting value of radiobutton trouble In-Reply-To: References: <3fs17rF9b8edU1@news.dfncis.de> <%35me.194$Dq7.159@newssvr11.news.prodigy.com> Message-ID: <3fs6vqF9e961U1@news.dfncis.de> Philippe C. Martin wrote: > Sorry, > > I still had your code in my clipboard :-) here goes: So, your code works, but I need, that first window calls another separate window. In your programm they stick together. Reg, VK > > > > from Tkinter import * > class GetVariant(Frame): > def __init__(self,p): > self.root = p > self.mainframe = Frame(self.root,bg="yellow") > self.mainframe.pack(fill=BOTH,expand=1) > > self.firstframe = Frame(self.mainframe,bg="red") > self.firstframe.pack(side=BOTTOM,expand=1) > > > self.v = StringVar() > self.radiobutton = Radiobutton(self.firstframe,text="Variant 1", > variable=self.v, value="Variant 1") > self.radiobutton.pack(side=TOP,anchor=W) > self.radiobutton.select() > self.radiobutton = Radiobutton(self.firstframe,text="Variant 2", > variable=self.v, value="Variant 2") > self.radiobutton.pack(side=TOP,anchor=W) > self.radiobutton = Radiobutton(self.firstframe,text="Variant 3", > variable=self.v, value="Variant 3") > self.radiobutton.pack(side=TOP,anchor=W) > > > > self.secondframe = Frame(self.mainframe,bg="blue") > self.secondframe.pack() > self.var = Button(self.secondframe,text="What > Variant",command=self.call) > self.var.pack(expand=1,side=BOTTOM) > > > > def call(self): > print dir(self.v) > self.variant = self.v.get() > print 'Input => "%s"' % self.variant > > class OneButton(Frame): > def __init__(self): > self.root = Tk() > Button(self.root,text="click me",command=self.getvar).pack() > def getvar(self): > print 'HRE' > a=GetVariant(self.root) > > d = OneButton() > d.root.mainloop() > > > > > > > Philippe C. Martin wrote: > > >>Hi, >> >>I think your second call to Tk() does it: this works although the look is >>different: >> >> >>from Tkinter import * >>class GetVariant: >> def __init__(self): >> self.root = Tk() >> self.mainframe = Frame(self.root,bg="yellow") >> self.mainframe.pack(fill=BOTH,expand=1) >> >> self.firstframe = Frame(self.mainframe,bg="red") >> self.firstframe.pack(side=BOTTOM,expand=1) >> >> global v >> v = StringVar() >> self.radiobutton = Radiobutton(self.firstframe,text= "Variant >>1", variable=v, value="Variant 1") >> self.radiobutton.pack(side=TOP,anchor=W) >> self.radiobutton.select() >> self.radiobutton = Radiobutton(self.firstframe,text= "Variant >>2", variable=v, value="Variant 2") >> self.radiobutton.pack(side=TOP,anchor=W) >> self.radiobutton = Radiobutton(self.firstframe,text= "Variant >>3", variable=v, value="Variant 3") >> self.radiobutton.pack(side=TOP,anchor=W) >> >> >> >> self.secondframe = Frame(self.mainframe,bg="blue") >> self.secondframe.pack() >> self.var = Button(self.secondframe,text="What >>Variant",command=self.call) >> self.var.pack(expand=1,side=BOTTOM) >> >> >> >> def call(self): >> self.variant = v.get() >> print 'Input => "%s"' % self.variant >> >>class OneButton: >> def __init__(self): >> self.root = Tk() >> Button(self.root,text="click me",command=self.getvar).pack() >> def getvar(self): >> a=GetVariant() >> >>d = OneButton() >>d.root.mainloop() >> >> >> >> >>VK wrote: >> >> >>>Hi! >>>What I'm missing in following code? Cannot get the values of >>>radiobuttons. Starting only one class (GetVariant), it works. When I put >>>two classes together, it doesn't. >>>Regards, VK >>> >>>from Tkinter import * >>>class GetVariant: >>> def __init__(self): >>> self.root = Tk() >>> self.mainframe = Frame(self.root,bg="yellow") >>> self.mainframe.pack(fill=BOTH,expand=1) >>> >>> self.firstframe = Frame(self.mainframe,bg="red") >>> self.firstframe.pack(side=BOTTOM,expand=1) >>> >>> global v >>> v = StringVar() >>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant >>>1", variable=v, value="Variant 1") >>> self.radiobutton.pack(side=TOP,anchor=W) >>> self.radiobutton.select() >>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant >>>2", variable=v, value="Variant 2") >>> self.radiobutton.pack(side=TOP,anchor=W) >>> self.radiobutton = Radiobutton(self.firstframe,text= "Variant >>>3", variable=v, value="Variant 3") >>> self.radiobutton.pack(side=TOP,anchor=W) >>> >>> >>> >>> self.secondframe = Frame(self.mainframe,bg="blue") >>> self.secondframe.pack() >>> self.var = Button(self.secondframe,text="What >>>Variant",command=self.call) >>> self.var.pack(expand=1,side=BOTTOM) >>> >>> >>> >>> def call(self): >>> self.variant = v.get() >>> print 'Input => "%s"' % self.variant >>> >>>class OneButton: >>> def __init__(self): >>> self.root = Tk() >>> Button(self.root,text="click me",command=self.getvar).pack() >>> def getvar(self): >>> a=GetVariant() >>> >>>d = OneButton() >>>d.root.mainloop() > > From onurb at xiludom.gro Mon May 16 11:36:35 2005 From: onurb at xiludom.gro (bruno modulix) Date: Mon, 16 May 2005 17:36:35 +0200 Subject: Importing and namespace visibility In-Reply-To: <1116198993.514542.96350@g44g2000cwa.googlegroups.com> References: <1116198993.514542.96350@g44g2000cwa.googlegroups.com> Message-ID: <4288be05$0$22928$636a15ce@news.free.fr> jean-marc wrote: > As an application programmer, I'm not well versed in the material > aspects of computing (memory, cpu, bus and all). My understanding of > imports in Python is such: the __main__ program is the center piece > which holds the programs reference: globals, functions, classes, > modules etc. the '__main__' program is in fact just another Python module. What makes it the 'main program' is the fact that you pass it to the Python interpreter as a 'main program'. > The objects of this file (functions and classes) are > directly accessible; from within this particular module only. > 'import suchModule' s objects are attainable > through the *qualified name* (module.function); the 'from suchModule > import *' the objects are directly attainable. > Take care, this has other implications too. (snip) > > BUT, of all this I thought that if you import module1, then module2 > (into __main__), objects from module1 would be available to objects of > module2 which came (into memory space) after module1 was loaded. This > does not seem to be the case, This is not. > and module2 requires an 'import module1' Right. And that's a Good Thing(tm). > statement in its own file to see this last module's objects. This is > not the recursive situation that was a pitfall Fredrik was evoking. > What am I missing here??? The term 'global' in Python is somewhat misleading. What it really means is "global to the current module". Each module (and remember the 'main program' is a module too) has it's own namespace. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From simon.brunning at gmail.com Tue May 3 08:19:57 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 3 May 2005 13:19:57 +0100 Subject: Py2Exe security In-Reply-To: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> Message-ID: <8c7f10c60505030519454b6ba8@mail.gmail.com> On 3 May 2005 05:03:00 -0700, Terje Johan Abrahamsen wrote: > We have created some programs in Python that are to be distributed > around. The programs will be made into .exe files by py2exe. However, > in the source there are certain webadresses, logins and passwords that > the programs use, that we would like to keep away from the end users. > They will use them thru the program, but we would like them not to be > extracted and used separately for other purposes. If your program can access these details, then a suficiently determined attacker can access them too, regardless of what you do. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From prabapython at yahoo.co.in Wed May 11 06:38:35 2005 From: prabapython at yahoo.co.in (praba kar) Date: Wed, 11 May 2005 11:38:35 +0100 (BST) Subject: Regarding Mail sending smtplib Module Message-ID: <20050511103835.82049.qmail@web8406.mail.in.yahoo.com> Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils import mimetypes import os,string fromAddr="prabahar at enmail.com" toAddr= ["prabakar1978 at rediffmail.com","praba at enmail.com"] mainMsg=email.Message.Message() mainMsg["Date"]=email.Utils.formatdate(localtime=1) mainMsg["Subject"]="en new contents" mainMsg["From"]=fromAddr mainMsg["To"]= string.join(toAddr,",") ## I am sending below message ## here mainMsg.set_payload("Good to win win\n") server = smtplib.SMTP('localhost') server.set_debuglevel(1) server.sendmail(fromAddr, toAddr, mainMsg.as_string()) server.quit() ###################### This is the output of above send mail program. Here I want to avoid this line "Received: from unknown (HELO prabahar.enmail.com) (59.92.13.47) by mailserver with SMTP; 11 May 2005 10:09:11 -0000 " How can I do this? . Why python give this line? . Mail sending Module in php will not give this type line. Here I have another doubt Php mail sending module give MessageId automatically but python doesn't set that. why? output ******* Return-Path: Delivered-To: prabakar1978 at rediffmail.com Received: (qmail 6865 invoked from network); 11 May 2005 10:09:11 -0000 Received: from unknown (HELO prabahar.enmail.com) (59.92.13.47) by mailserver with SMTP; 11 May 2005 10:09:11 -0000 Received: (dqd 1118 invoked from network); 12 Apr 2005 06:38:59 -0000 Received: from unknown (HELO prabahar.enmail.com) (127.0.0.1) by prabahar.enmail.com with SMTP; 12 Apr 2005 06:38:59 -0000 Date: Tue, 12 Apr 2005 03:38:59 -0300 Subject: en new contents From: prabahar at enmail.com To: prabakar1978 at rediffmail.com,praba at enmail.com Good to win win with regards Prabahar ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From gandalf at geochemsource.com Mon May 23 04:57:36 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Mon, 23 May 2005 10:57:36 +0200 Subject: Manipulating mailboxes Message-ID: <42919B00.8070703@geochemsource.com> Hi All, I need to create a daemon that sits on a server and forwards some e-mails. (Well not only that, it needs to change header information before forwarding and also insert messages into a database). The mailbox module is fine but I do not see a way to delete/add messages - it is ready only. The other possiblity is IMAP4 but it is bad because my program should not store passwords for all users. I can only see one solution right now: 1. Make a copy of the mailbox 2. Truncate the mailbox 3. Process the messages in the copy and forward the e-mails by sending out real e-mails. But this looks so clumsy. Is there a way to delete/add messages to mailboxes of different users, directly? Thanks, Laci 2.0 From tnaran at no-more-virii-please.direct.ca Wed May 25 01:24:22 2005 From: tnaran at no-more-virii-please.direct.ca (Travers Naran) Date: Wed, 25 May 2005 05:24:22 GMT Subject: Counting occurences of words in a list of strings In-Reply-To: <4293fe18@news.eftel.com> References: <4293fe18@news.eftel.com> Message-ID: John Machin wrote: > Are you comparing BMH implemented in Python with str.count() implemented > in C? Tee-hee. Yes. I figured out that was the problem pretty quickly and just went back to count(). > 1. A pure Python suggestion: > > Presuming there is a character SEP that cannot appear in the keys in > your query dictionary, try this: > > SEP = '\n' # for example > big_string_count = SEP.join(tc.strings).count > for query_key in self.dict.keys(): > self.dict[query_key]['count'] += big_string_count(query_key) > > Why do we have += in the above line? Is there anything else being added > in by not-shown code? If not, the following would be much more > comprehensible, and faster: There is. Because the program can loop over mutliple input files, it needs to count it across the files. But that's a minor thing. > Checking your requirements for "non-overlapping": if you have 'foobar' > and 'barzot' in the dictionary, and a string contains 'foobarzot', your > code will count 1 for 'foobar' and 1 for 'barzot'. Is that OK? Exactly. Let me be more precise: non-overlapping with itself. I.e., if I has "aa", then "aaaa" should count 2. But foorbar and barzot both coming back 1 in your example is exactly the behavoir I want. > 2. Next, if you don't mind using a C-extension, look at Danny Yoo's > ahocorasick module, which will search in parallel for your 3000+ keys. > > http://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/ > > Under one definition of non-overlapping, you will be able to use one of > the findall methods; under the other definition, you will need to use > one of the search methods and restart at (matched_position + 1). Nifty! Thanks muchly. > 3. If you want to roll your own, start with Gonzalo Navarro's > publications: http://www.dcc.uchile.cl/~gnavarro/subj-multiple.html I don't suffer from NMH syndrome. If ahocorasick does the job, or even count, I'm OK with that. From rrr at ronadam.com Tue May 17 22:12:11 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 18 May 2005 02:12:11 GMT Subject: Representing ambiguity in datetime? In-Reply-To: <5hvk81prupnpinq4ucspsikdqns5rmcaf0@4ax.com> References: <5hvk81prupnpinq4ucspsikdqns5rmcaf0@4ax.com> Message-ID: <%vxie.25534$VH2.13093@tornado.tampabay.rr.com> John Machin wrote: > On Tue, 17 May 2005 17:38:30 -0500, Terry Hancock > wrote: > > >>What do you do when a date or time is >>incompletely specified? ISTM, that as it is, there is no >>formal way to store this --- you have to guess, and there's >>no way to indicate that the guess is different from solid >>information. As a result, I have sometimes had to abandon >>datetime, even though it seemed like the logical choice for >>representing data. >> >>E.g. I might have information like "this paper was published >>in May 1997". There's no way to write that with datetime, >>is there? Even if I just use the "date" object instead of >>datetime, I still have to actually specify something like >>May 1, 1997 --- fabricating data, which is frequently >>undesireable (later on, I might find information saying that >>it was actually published May 23, 1997 and I might want >>to update the earlier one, or simply evaluate them as >>"equal" since they are, to within the precision given --- >>for example, I might be trying to decide that two database >>entries are really duplicate references to the same paper). >> >>I know that this is somewhat theoretically stated, but I >>have run into to concrete problems along the lines of >>the above. >> >>I'd say this is analogous to how you might use "None" >>rather than "0" to represent an integer if you don't know >>it's value (rather than knowing that it is zero). ISTM, you >>ought to be able to specify a date as, e.g.: >> >>d = datetime.date(2005, 5, None) >> >>I realize there might be some complexity with deciding >>how to handle datestamp math, but as this situation >>occurs frequently in real life, it seems like it shouldn't >>be avoided. >> >>How do other people deal with this kind of problem? > > > Mostly, badly :-( > > Real-life example: due to war-time disruption etc, in some countries > it is common enough to find that the date of birth of someone born in > the 1940s is not known precisely. E.g. on the Hong Kong identity card, > it is possible to find only the year and month of birth, and sometimes > even only the year. Depending on the purpose, legislation and > convention will take the first day of the vague period or the last day > when a calculation is required. Badly == entering into a database the > "exact" date that was used for the purpose du jour, with no indication > that the source was vague. Consequently a person can have DOB recorded > as 1945-01-01 on one database and 1945-12-31 on another. > > Suggested approach in Python (sketch): Don't try to get the datetime > module to solve the problem. Define a fuzzydate class. Internal > representation: I'd suggest earliest possible date and latest possible > date. That way you have valid date instances for doing date > arithmetic. May have different constructors depending on how the > incoming vagueness is specified. > > HTH, > John This is a very common problem in genealogy research as well as other sciences that deal with history, such as geology, geography, and archeology. I agree that some standard way of dealing with fuzzy dates would be a good thing. I think looking at how others do it would be the way to start... A google search found the following reference buried in a long reference page on mysql. http://www.dreamlink.net/mysql/manual_Functions.html > The reason the ranges for the month and day specifiers begin with zero is that MySQL allows incomplete dates such as '2004-00-00' to be stored as of MySQL 3.23. So it seems using 0's for the missing day or month may be how to do it. Cheers, _Ron From mcassiano at manord.com Thu May 12 08:28:42 2005 From: mcassiano at manord.com (Cassiano, Marco) Date: Thu, 12 May 2005 14:28:42 +0200 Subject: Sleepycat Bsdbd 4.3.27 and Python 2.4.1 Message-ID: <52DC70C1C1575C418CB033523A29CF1403AD5395@exchange2000.manord.com> Hi all, I've just compiled Python 2.4.1 on a linux box (RHEL 3AS) after having installed Berkeley DB 4.3.27 from sleepycat Software. During the configure/build process python correctly found the BSBDB library. I then installed the rest of my environment which is correctly working with Python 2.3 When I try to run one of my procedures I get the following error trying to opening a common shelve file : Mod_python error: "PythonHandler mod_python.publisher" Traceback (most recent call last): File "/usr/local/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch result = object(req) File "/usr/local/lib/python2.4/site-packages/mod_python/publisher.py", line 136, in handler result = util.apply_fs_data(object, req.form, req=req) File "/usr/local/lib/python2.4/site-packages/mod_python/util.py", line 361, in apply_fs_data return object(**args) File "/discoe/script/cgi/cgi-mpy/cgi-mpy_login.py", line 116, in controlla_login dbase = shelve.open(file_AUTENTICAZIONE) #apre shelve File "/usr/local/lib/python2.4/shelve.py", line 231, in open return DbfilenameShelf(filename, flag, protocol, writeback, binary) File "/usr/local/lib/python2.4/shelve.py", line 212, in __init__ Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback, binary) File "/usr/local/lib/python2.4/anydbm.py", line 83, in open return mod.open(file, flag, mode) File "/usr/local/lib/python2.4/dbhash.py", line 16, in open return bsddb.hashopen(file, flag, mode) File "/usr/local/lib/python2.4/bsddb/__init__.py", line 285, in hashopen e = _openDBEnv() File "/usr/local/lib/python2.4/bsddb/__init__.py", line 339, in _openDBEnv e.open('.', db.DB_PRIVATE | db.DB_CREATE | db.DB_THREAD | db.DB_INIT_LOCK | db.DB_INIT_MPOOL) DBError: (156471272, 'Unknown error 156471272') Any hint or suggestion is welcom Thnx Marco Cassiano -------------- next part -------------- An HTML attachment was scrubbed... URL: From Bernd.Nawothnig at t-online.de Sat May 14 13:23:56 2005 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sat, 14 May 2005 19:23:56 +0200 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> Message-ID: On 2005-05-14, Philippe C. Martin wrote: > You're thinking you're passing the arguments as reference That is the way Fortran handles them: [...] >> Right now I'm taking a simple program I wrote in Fortran Bernd -- Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. [T. Jefferson] From peter at engcorp.com Wed May 11 19:23:52 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 11 May 2005 19:23:52 -0400 Subject: windows directories for curr user In-Reply-To: <1115842685.555385.65010@g47g2000cwa.googlegroups.com> References: <1115842685.555385.65010@g47g2000cwa.googlegroups.com> Message-ID: flamesrock wrote: > Thanks for the code Tom. > > Unforunately, I get the following error message when trying to import > win32com in idle: Have you installed the pywin32 package? If not, see Google... From jepler at unpythonic.net Fri May 13 09:01:18 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Fri, 13 May 2005 08:01:18 -0500 Subject: How "return" no return ? In-Reply-To: <3ehc5tF35eo3U1@individual.net> References: <3ehaurF34ak0U1@individual.net> <3ehc5tF35eo3U1@individual.net> Message-ID: <20050513130115.GC12225@unpythonic.net> At the interactive prompt, a result is printed when both these things are true: * The entered code is an expression, not any other kind of statement * The result of the expression is not 'None' If an expression occurs, information about it will be printed instead. So the interpreter won't print a result for >>> a = 3 # because it's an assignment statement >>> def f(): return # because it's a 'def' statement >>> None # because the result of the expression is 'None' >>> f() # because the result of the expression is 'None' Your example >>> int a is not Python, but if it was it would probably be a non-expression statement, and thus never print a result in the interpreter. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From wazaah at hotmail.com Sun May 1 07:16:59 2005 From: wazaah at hotmail.com (Nathan) Date: Sun, 1 May 2005 21:16:59 +1000 Subject: tkMessageBox dialog help Message-ID: <1179elj56ralk70@news.supernews.com> Hi, I've been testing the standard dialog boxes in tkMessageBox under IDLE. If I type for example, tkMessageBox.askyesno('test', 'test'), the dialog box comes up fine but another window also appears. I'm guessing this is the parent window of the message box. If I click on either of the yes/no buttons, i get a True/False on the std out and the dialog box closes but the parent window remains and seems to hang. This is on WinXP by the way. Is this normal behaviour? How do I get the dialog box appearing without the parent window or is this not possible? Thanks, Nathan. From rschroev_nospam_ml at fastmail.fm Thu May 12 03:39:41 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Thu, 12 May 2005 07:39:41 GMT Subject: reg mail sending without smtp module In-Reply-To: References: Message-ID: <1LDge.88601$zf.5398554@phobos.telenet-ops.be> praba kar wrote: > --- Tim Williams wrote: >>Why don't you want to use smtplib ? > > In Php we can build a Mail Message by > Mail_mime class and send this message by > Mail::Factory's class send Method. Here Php > doesn't use any smtp modules. Like that > In Python I used email.Message class to > build Mail Message and Now I am searching > modules to send this message as mail. You can still use smtplib: msg = email.Message() ... smtp = smtplib.SMTP(...) smtp.sendmail(from, to, msg.as_string()) -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From fredrik at pythonware.com Fri May 6 19:06:31 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 7 May 2005 01:06:31 +0200 Subject: Reference to self not passed to member function References: <200505061533.02116.jstroud@mbi.ucla.edu> Message-ID: James Stroud wrote: > I did this: > > py> class bob(object): > ... def __init__(self,**kwargs): > ... for fname,func in kwargs.items(): > ... setattr(self, fname, lambda *args : func(*args)) > ... > py> def doit(): > ... print "wuzzup?" > ... > py> abob = bob(doit=doit) > py> > py> abob.doit() > wuzzup? > > Much to my surprise, this works fine. why is that surprising? "doit" is a callable, you wrap it in another callable, and then you store it in an attribute. that's no different from storing a integer as an attribute, and it sure doesn't turn your callable into an instance method. > 1. What exactly is going on? see above. > 2. How can I get ref to self passed to doit() if I want it to? try using this bob instead: import new class bob(object): def __init__(self, **kwargs): for fname, func in kwargs.items(): setattr(self, fname, new.instancemethod(func, self, bob)) From discipulus at gmail.com Mon May 23 13:51:47 2005 From: discipulus at gmail.com (Discipulus) Date: 23 May 2005 10:51:47 -0700 Subject: MUD Client and Python Plugin Framework Message-ID: <1116870707.802985.58190@g14g2000cwa.googlegroups.com> Hey, I'm contemplating starting a MUD client in Python, and I would like to make it so that people can write their own plugins, but I need ideas on the framework. Any suggestions? From simon at arrowtheory.com Sun May 1 22:57:54 2005 From: simon at arrowtheory.com (simon at arrowtheory.com) Date: 1 May 2005 19:57:54 -0700 Subject: epydoc and latex math Message-ID: <1115002674.401016.251510@o13g2000cwo.googlegroups.com> Hi, We have a requirement for latex math (eg. $\sum_i x_i$) in our documentation, and i'm looking at patching epydoc to handle this. We have been using the python doc system (also used by numarray), with a script to rip docstrings into the required latex. However, this method is getting out of hand, and epydoc looks like a great replacement tool. I see nltk and twisted use epydoc, but the project itself seems to be quiet at the moment. Also, I have been subscribed to doc-sig for a while now, but I am utterly confused as to what they are up to. bye, Simon. -- Simon Burton, B.Sc. Licensed PO Box 8066 ANU Canberra 2601 Australia Ph. 61 02 6249 6940 http://arrowtheory.com From vincent at visualtrans.de Thu May 26 02:45:56 2005 From: vincent at visualtrans.de (vincent wehren) Date: Thu, 26 May 2005 08:45:56 +0200 Subject: Problem redirecting stdin on Windows References: Message-ID: "aurora" schrieb im Newsbeitrag news:op.src1o0py6yt6e7 at news.cisco.com... | On Windows (XP) with win32 extension installed, a Python script can be | launched from the command line directly since the .py extension is | associated with python. However it fails if the stdin is piped or | redirected. | | Assume there is an echo.py that read from stdin and echo the input. | | | | Launching from command line directly, this echos input from keyboard: | | echo.py | | | | But it causes an error if the stdin is redirected | | echo.py <42949ca2$0$6501$636a15ce@news.free.fr> <1117041254.820429.306500@g49g2000cwa.googlegroups.com> Message-ID: wrote in message news:1117041254.820429.306500 at g49g2000cwa.googlegroups.com... > Thanks for the help. I now understand it better. As Bruno points out, I > really don't need a property in this case, as my attribute is public, > and I will remove it. As much to the point is that your name attribute is static in the sense of being a fixed object between settings. Should you later want to make it dynamic (or perhaps lazy) in the sense of being computed on demand, then you can do so with property() *without* changing the external interface to the class. A third reason for property() is when you want to do something in addition to the access, such as reporting the access to something else. Terry J. Reedy From python-url at phaseit.net Tue May 24 11:19:29 2005 From: python-url at phaseit.net (Simon Brunning) Date: Tue, 24 May 2005 15:19:29 +0000 Subject: Dr. Dobb's Python-URL! - weekly Python news and links (May 24) Message-ID: QOTW: "If you're sick of answering newbie questions, and don't think you can do so politely, for the sake of the community, DON'T! You're not that necessary." - Joal Heagney "Who controls the runtime also controls the language." - Kay Schluehr Jake tells us about the \r control character, which allows one to refresh a terminal line. Many people help him to use it from Python, and Fredrik warns him that it might well not work from an IDE: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/50cffbb6eb03cc4 John Reese asks whether he needs to explicitly close file objects, or whether reference counting will take care of it for him. Martin v. L?wis shows a scenario that demonstrates that ref counting won't always close files when you think it will: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/7eba2d6efd271707 Simon Percivall and Jp Calderone show Michael Chermside how to process subprocess module output a line at a time: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/df6854ec10c6d508 WSGI Explorations with Python - Mike Orr investigates WSGI and Paste: http://rex.kicks-ass.net/python/wsgi-explorations.html Len, an "old time Cobol programmer", asks for some advice on storing data: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/c20623a77b22c456 Dustin is refactoring some unpythonic code that uses a very nasty import mechanism, but now he's having trouble with circular imports: http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/8eae5075b9973a2b A Matter Of Questions - Ben Last tells us how he's using Python for data cleansing, amongst other things, while building a Playstation Music Quiz: http://www.livejournal.com/users/benlast/24719.html William Park wants to test how similar two strings are. This is more complicated than it sounds... http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/4aa08f075d05eb48 Create an ODBC data source in the fly with Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/414879 Paul Rubin investigates how the super() function works with multiple inheritance. A number of people clear things up for him. http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/57cdcc73f8747091 Notable releases: pysqlite 2.0.2 http://pysqlite.org/ PyPy 0.6 (!) http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/8e4a74dfb90c8bf4 ======================================================================== Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ The Python Business Forum "further[s] the interests of companies that base their business on ... Python." http://www.python-in-business.org Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%20patch Cetus collects Python hyperlinks. http://www.cetus-links.org/oo_python.html Python FAQTS http://python.faqts.com/ The Cookbook is a collaborative effort to capture useful and interesting recipes. http://aspn.activestate.com/ASPN/Cookbook/Python Among several Python-oriented RSS/RDF feeds available are http://www.python.org/channews.rdf http://bootleg-rss.g-blog.net/pythonware_com_daily.pcgi http://python.de/backend.php For more, see http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all The old Python "To-Do List" now lives principally in a SourceForge reincarnation. http://sourceforge.net/tracker/?atid=355470&group_id=5470&func=browse http://python.sourceforge.net/peps/pep-0042.html The online Python Journal is posted at pythonjournal.cognizor.com. editor at pythonjournal.com and editor at pythonjournal.cognizor.com welcome submission of material that helps people's understanding of Python use, and offer Web presentation of your work. del.icio.us presents an intriguing approach to reference commentary. It already aggregates quite a bit of Python intelligence. http://del.icio.us/tag/python *Py: the Journal of the Python Language* http://www.pyzine.com Archive probing tricks of the trade: http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python&num=100 http://groups.google.com/groups?meta=site%3Dgroups%26group%3Dcomp.lang.python.* Previous - (U)se the (R)esource, (L)uke! - messages are listed here: http://www.ddj.com/topics/pythonurl/ (requires subscription) http://groups-beta.google.com/groups?q=python-url+group:comp.lang.python*&start=0&scoring=d& http://purl.org/thecliff/python/url.html (dormant) or http://groups.google.com/groups?oi=djq&as_q=+Python-URL!&as_ugroup=comp.lang.python Suggestions/corrections for next week's posting are always welcome. E-mail to should get through. To receive a new issue of this posting in e-mail each Monday morning (approximately), ask to subscribe. Mention "Python-URL!". -- The Python-URL! Team-- Dr. Dobb's Journal (http://www.ddj.com) is pleased to participate in and sponsor the "Python-URL!" project. From jstroud at mbi.ucla.edu Thu May 5 13:37:23 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 5 May 2005 10:37:23 -0700 Subject: dictionary comparison In-Reply-To: <1115313648.259509.80170@z14g2000cwz.googlegroups.com> References: <1115306371.818120.150340@f14g2000cwb.googlegroups.com> <1115312393.514506.77600@z14g2000cwz.googlegroups.com> <1115313648.259509.80170@z14g2000cwz.googlegroups.com> Message-ID: <200505051037.23715.jstroud@mbi.ucla.edu> On Thursday 05 May 2005 10:20 am, so sayeth rickle: > Bill and Jordan, thank you both kindly. I'm not too well versed in > functions in python and that's exactly what I needed. I could see I > was doing something wrong in my original attempt, but I didn't know how > to correct it. > > It's working like a charm now, thank you both very much. > -Rick I thought I'd throw this in to show some things in python that make such comparisons very easy to write and also to recommend to use the patch as key and version as value in the dict.: Note that the meat of the code is really about 4 lines because of (module) sets and list comprehension. Everything else is window dressing. James =================================== # /usr/bin/env python from sets import Set # pretending these stripped from file recc_ary = ["117000-05", "116272-03", "116276-01", "116278-01", "116378-02", "116455-01", "116602-01", "116606-01"] serv_ary = ["117000-01", "116272-02", "116272-01", "116602-02"] # use patch as value and version as key recc_dct = dict([x.split("-") for x in recc_ary]) serv_dct = dict([x.split("-") for x in serv_ary]) # use Set to see if patches overlap overlap = Set(recc_dct.keys()).intersection(serv_dct.keys()) # find differences (change comparison operator to <,>,<=,>=, etc.) diffs = [patch for patch in overlap if recc_dct[patch] != serv_dct[patch]] # print a pretty report for patch in diffs: print "reccomended patch for %s (%s) is not server patch (%s)" % \ (patch, recc_dct[patch], serv_dct[patch]) -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From steve at REMOVETHIScyber.com.au Sun May 29 08:23:42 2005 From: steve at REMOVETHIScyber.com.au (Steven D'Aprano) Date: Sun, 29 May 2005 22:23:42 +1000 Subject: Software licenses and releasing Python programs for review References: <1117245014.218831.317750@g14g2000cwa.googlegroups.com> <1117324124.350474.136600@g14g2000cwa.googlegroups.com> Message-ID: On Sat, 28 May 2005 16:48:44 -0700, poisondart wrote: > The reason why I need people to review my code and also the ideas > behind the code is mostly for academic interest...but not necessarily > reserved to an academic audience...which is why I don't want people to > make profit from it. It uses ideas from a language--which would be > ridiculous (to me) for anybody to make profit from selling the > mechanics of a natural language. Let me toss some scenarios out there for you to think about. You write your code, and distribute it for free. Very generous of you. I publish for profit a computer magazine which includes a CD containing software. I would like to include your code. Can I? My colleague Betty compiles collections of software, tests them, weeds out the buggy and useless programs, documents the ones that remain, and sells the collection for profit. She would like to include your code on her CD. Can she? My competitor Barney tries to start a business selling your code for profit. How long do you think he will stay in business trying to sell what you are making available for free on your website? My neighbour Bobby creates a game which he sells for profit. This game includes a natural language engine allowing the game characters to (almost) understand real language. He would like to use your code to do this. Can he? My business partner Billy wants to sell servers for profit. On this server, he wants to include a collection of software for added value. He would like to include your software. Can he? Regards, -- Steven From qhfgva at gmail.com Fri May 20 10:38:18 2005 From: qhfgva at gmail.com (qhfgva at gmail.com) Date: 20 May 2005 07:38:18 -0700 Subject: circular imports Message-ID: <1116599898.308012.71220@g47g2000cwa.googlegroups.com> I'm working with a large code base that I'm slowly trying to fix "unpythonic" features of. One feature I'm trying to fix is the use of: # how things are now sys.path.append('/general/path/aaa/bbb') # lots of lines like this to specific dirs import foo Insead I'd rather have PYTHONPATH already include '/general/path/' and then just use: # how I'd like them to be from aaa.bbb import foo So I thought I'd just add the necessary __init__.py files and then things would just work. Unfortunately trying this exposed a large number of circular imports which now cause the files to fail to load. Any ideas why the sys.path.append method has no problem with circular imports whereas doing thing the "right way" chokes. thanks, dustin From xah at xahlee.org Sat May 14 06:41:28 2005 From: xah at xahlee.org (Xah Lee) Date: 14 May 2005 03:41:28 -0700 Subject: function with variable arguments In-Reply-To: References: <1115977954.266898.141150@g49g2000cwa.googlegroups.com> Message-ID: <1116067288.070061.286480@g43g2000cwa.googlegroups.com> Thanks to all for the reply. (i should've known better) on a related topic, I think it would be a improvement for the built-in range() so that step needs not be an integer. Further, it'd be better to support decreasing range. e.g. Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8] Range( 5, -4, -2); # returns [5,3,1,-1,-3] Xah xah at xahlee.org ? http://xahlee.org/ From mogmios at mlug.missouri.edu Tue May 10 23:11:47 2005 From: mogmios at mlug.missouri.edu (Michael) Date: Tue, 10 May 2005 20:11:47 -0700 Subject: Jabber/XML-RPC lib in Python? Message-ID: <428177F3.6050201@mlug.missouri.edu> I was wanting to write a program that lets two machines communicate (without user intervention) using XML-RPC over a Jabber network. Does anyone know of an existing library suited to that task? I'd like it if I didn't need to worry about writing any Jabber or XML-RPC code if I could and just worry about the logic of my own program. Any ideas? -- Michael http://kavlon.org From bellman at lysator.liu.se Wed May 11 04:02:06 2005 From: bellman at lysator.liu.se (Thomas Bellman) Date: Wed, 11 May 2005 08:02:06 +0000 (UTC) Subject: Trouble saving unicode text to file References: <1115500976.571232.76100@z14g2000cwz.googlegroups.com> <42819c66$0$29930$9b622d9e@news.freenet.de> Message-ID: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= wrote: >Thomas Bellman wrote: >> Fixed-with characters *do* have advantages, even in the external >> representation. With fixed-with characters you don't have to >> parse the entire file or stream in order to read the Nth character; >> instead you can skip or seek to an octet position that can be >> calculated directly from N. > OTOH, encodings that are free of null bytes and ASCII compatible > also have advantages. Indeed, indeed. But that's no reason to choose UTF-16 over UTF-32, since you don't get those advantages then. >> And not the least, UTF-32 is *beautiful* compared to UTF-16. > But ugly compared to UTF-8. Not only does it have the null byte > and the ASCII incompatibility problem, but it also has the > endianness problem. So for exchanging Unicode between systems, > I can see no reason to use anything but UTF-8 (unless, of course, > one end, or the protocol, already dictates a different encoding). UTF-8 beats UTF-32 in the practicality department, due to its compatibility with legacy software, but in my opinion UTF-32 wins over UTF-8 for shear beauty, even with the endianness problem. I do wish they had standardized on one single endianness for UTF-32 (and UTF-16), instead of allowing both to exist. In the mid 1990's I had to work with files in the TIFF format, which allows both endianesses. The specification *requires* you to read both, but it was a rare sight to find MS Windows software that didn't barf on big endian TIFF files. :-( Unix software tended to be better at reading both endians, but generally wrote in the native format, meaning big endian on Sun Sparc. Luckily I could convert files using tiffcp on our Unix machines, but it was irritating to have to introduce that extra step. I fully expect the same problem to happen with UTF-16 and UTF-32 too. Anyway, back to UTF, my complaint is that UTF-16 doesn't give you the advantages of *either* UTF-8, nor UTF-32, so if you have the choice, UTF-16 is always the worst alternative of those three. I see no reason to recommend UTF-16 at all. -- Thomas Bellman, Lysator Computer Club, Link?ping University, Sweden "God is real, but Jesus is an integer." ! bellman @ lysator.liu.se ! Make Love -- Nicht Wahr! From mf1987 at arcor.de Fri May 27 11:03:36 2005 From: mf1987 at arcor.de (mmf) Date: 27 May 2005 08:03:36 -0700 Subject: cpu usage limit Message-ID: <1117206216.695085.282510@g44g2000cwa.googlegroups.com> Hi. My problem: How can I make sure that a Python process does not use more that 30% of the CPU at any time. I only want that the process never uses more, but I don't want the process being killed when it reaches the limit (like it can be done with resource module). Can you help me? Thanks in advance. Best regards, Markus From bh at intevation.de Thu May 12 12:59:43 2005 From: bh at intevation.de (Bernhard Herzog) Date: Thu, 12 May 2005 18:59:43 +0200 Subject: Finding startup files References: <1115829176.541687.22090@z14g2000cwz.googlegroups.com> <1184dj36mp5sdc6@corp.supernews.com> <1186p8e5nkrj095@corp.supernews.com> Message-ID: Grant Edwards writes: > On 2005-05-11, jeff elkins wrote: > >> I'm totally new to Python (obvious,yes?) so how might argv[0] fail? > > argv[0] contains whatever is put there by the program that > exec'ed you, and can therefore contain just about anything (or > nothing). It may not contain a full path, and your program's > install directory may not be in your $PATH (it be executed by a > shortcut or symlink). That's true for the C-level, i.e. main's argv. If you're only concerned about CPython and the program is a script living in a file, then sys.argv[0] is the filename the python interpreter itself used to read the script. Hence it's a valid filename that refers to the script. It may be a relative filename, of course, in which case it won't be correct anymore if the program changes its working directory. Bernhard -- Intevation GmbH http://intevation.de/ Skencil http://skencil.org/ Thuban http://thuban.intevation.org/ From jjge at xs4all.nl Sat May 21 13:59:15 2005 From: jjge at xs4all.nl (jg) Date: Sat, 21 May 2005 19:59:15 +0200 Subject: Fw: evidence john bokma al jazeera connection ? References: <1T87IN1838493.4652546296@anonymous.poster> Message-ID: <428f76f3$0$64528$e4fe514c@news.xs4all.nl> William Baker wrote: > > > > please add forward to alt.security.terrorism if information > > p.p.s. "john bokma" shows long list in message boards, just in last > month. lots of information to netherlands where muslem militants > are. could some be coded cryption to aljazeera, so messages are in > secret for the terror network? Do not forget his alter egos: Waldo Centini, Jerry Harper, Els... ;-) -- g From sxanth at ceid.upatras.gr Wed May 25 20:12:54 2005 From: sxanth at ceid.upatras.gr (Stelios Xanthakis) Date: Thu, 26 May 2005 03:12:54 +0300 Subject: pyvm -- faster python In-Reply-To: References: Message-ID: <42951486.2090103@ceid.upatras.gr> Hi Michael [...] > > Releasing open source means that people *may* fix their own bugs, or > abandon the code. [...] I agree with all the points made. Moreover let me add that "code is one expression of a set of good ideas", and ideas want to be free! ;) I've decided to release the source code of pyvm as soon as it's ready. Right now *it doesn't* make much sense to give the source because it is still at an early development stage. Even if I did and people sent patches they wouldn't apply because I still make big changes to the architecture of it. I'd like to keep it in this status where I can modify the structure of the program until it becomes really developer-friendly. And IMO it doesn't make sense to release incomplete open source projects: either give something that's good and people can happily hack, or don't do it at all. Giving out the source of an unstable project will most likely harm it (see CherryOS incidents). The bottomline is that I estimate that pyvm will be ready within the summer. Thanks, Stelios From Serge.Orlov at gmail.com Tue May 17 12:52:23 2005 From: Serge.Orlov at gmail.com (Serge Orlov) Date: 17 May 2005 09:52:23 -0700 Subject: Type question References: <1116345629.908618.165300@o13g2000cwo.googlegroups.com> Message-ID: <1116348743.742074.152780@g44g2000cwa.googlegroups.com> nitrogen... at web.de wrote: > Hello, > > is this call assumed to be True in any case? > > result = type(SomeClass) is SomeClass > > I've written a proxy class which shadows a real object. If you call > type(proxyobj) it returns the type of the proxyobject and not the type > of the shadowed object. Example: > > p = proxy(shadowobj()) > result1 = type(p) is shadowobj # will return False > result2 = isinstance(p, shadowobj) # will return True > > So the first call compares the id()s of both types, while the second > calll seems to work different. > I've tried to use a proxy metaclass that creates new objects with the > name 'shadowobj'. So > > print type(p) > print type(shadowobj()) > > will look exactly the same. isinstance is not a law. It's just a convention. You don't actually need to implement it. Consider PEP 246, I believe, it is the right way to do what you want to do. isinstance and metaclasses are not. Instead of writing if not isinstance(obj, class): report error ask your users to write obj = adapt(obj, Interface) instead of dispatch code like if isinstance(obj, thisclass): do this elif isinstance(obj, thatclass): do that else: report error ask the users to write: if kind(obj) is ThisKind: do this elif kind(obj) is ThatKind: do that else: report error where kind can be defined as def kind(obj): return getattr(obj, 'kind', None) Serge. From Serge.Orlov at gmail.com Tue May 17 02:51:51 2005 From: Serge.Orlov at gmail.com (Serge.Orlov at gmail.com) Date: 16 May 2005 23:51:51 -0700 Subject: Anyway to designating the encoding of the "source" for compile? In-Reply-To: <1116287070.202497.16340@g44g2000cwa.googlegroups.com> References: <1116087091.856022.155340@z14g2000cwz.googlegroups.com> <1116263722.499345.73260@g43g2000cwa.googlegroups.com> <1116286039.267037.91500@o13g2000cwo.googlegroups.com> <1116287070.202497.16340@g44g2000cwa.googlegroups.com> Message-ID: <1116312711.880415.255930@g44g2000cwa.googlegroups.com> janeaustin... at hotmail.com wrote: > > Okay, I'll use one of the CJK codecs as the example. EUC-KR is the > > default encoding. > > > > >>> import sys;sys.getdefaultencoding() > > 'euc-kr' > > >>> '??' > > '\xc7\xd1\xb1\xdb' That is the problem. Non-ascii characters in byte strings are deprecated. Here is what I get when I run a deprecated hello world program in Russian: ------- hello.py --------- print "??????????, ???!" -------------------------- C:\py>c:\Python24\python.exe hello.py sys:1: DeprecationWarning: Non-ASCII character '\xc7' in file text.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details ??????????, ???! -------------------------- Oops, not only there is a warning, but it doesn't even work on Windows in Russian locale. To correct the program I need to switch to unicode strings: ------- hello.py --------- # -*- coding: windows-1251 -*- print u"??????????, ???!" -------------------------- C:\py>c:\Python24\python.exe hello.py ??????????, ???! -------------------------- Since non-ascii characters are deprecated in byte strings, any non-ascii encoding for sys.getdefaultencoding() is deprecated as well. Don't set it to 'euc-kr'. > Any suggestions or any plans in future python versions? In python 3.0 byte strings will be gone. So you won't be able to put non-ascii characters into them. Serge. From jo at durchholz.org Tue May 17 03:01:02 2005 From: jo at durchholz.org (Joachim Durchholz) Date: Tue, 17 May 2005 09:01:02 +0200 Subject: tree functions daily exercise In-Reply-To: <1116236529.172707.174570@g47g2000cwa.googlegroups.com> References: <1115969822.361451.100620@g47g2000cwa.googlegroups.com> <87r7gbr1rg.fsf@sefirot.ii.uib.no> <1116236529.172707.174570@g47g2000cwa.googlegroups.com> Message-ID: xah at xahlee.org wrote: > K! > http://en.wikipedia.org/wiki/K_programming_language > > Interesting. > Looking at your program, they are so short. I don't know if they are > full implementation or what... That's no surprise: list and tree processing are often built right into more expressive languages, and K seems to be one of these. Regards, Jo From fredrik at pythonware.com Fri May 6 13:18:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 6 May 2005 19:18:07 +0200 Subject: annonymous functions -- how to References: <1115239458.776800.240080@g14g2000cwa.googlegroups.com><42795acb.685370470@news.oz.net><1115264804.625020.203800@f14g2000cwb.googlegroups.com> <2fNee.10965$fI.8507@fed1read05> Message-ID: Dave Benjamin wrote: > > so name them all "func" or "next" or something, so you don't have > > to think. once the object is bound, the name is irrlevant. > > Sure, you could do this, but then you'd have multiple functions at > different nesting levels with the same name, which would be confusing. "I don't wanna try that", you mean. because if you had done so, you would have noticed that "multiple functions with the same name" doesn't have to be any more confusing than "multiple print statements" or "multiple if statements" (as long as you're not using bad names on purpose, of course). > > there's also: > > > > def add_thingy(self): > > What object is "self"? Are we defining a method at this point? if you have a problem with methods, you shouldn't use Python. > > > yield get_new_thingy_id; thingy_id = self.result > > What is "get_new_thingy_id"? A function? To whom are we yielding here? I could have sworn that you mentioned event-driven programming in your original post. if that's still what you're doing, the answers are "a token" and "the event source". From philippe at philippecmartin.com Wed May 18 08:35:13 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Wed, 18 May 2005 12:35:13 GMT Subject: How to learn OO of python? References: Message-ID: <5EGie.1718$5Z1.1396@newssvr30.news.prodigy.com> You might want to look at this first: http://pigseye.kennesaw.edu/~dbraun/csis4650/A&D/UML_tutorial/ http://uml.tutorials.trireme.com/ could ildg wrote: > I have learned python for over a month. > I heard that it was very easy to learn, but when I tried to know OO of > python, I found it really weird, some expressions seem very hard to > understand, and I can't find enough doc to know any more about it. > So, I wonder how did you master python? And where to find some cool docs? > > Thanks. From rbt at athop1.ath.vt.edu Tue May 3 08:59:14 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Tue, 03 May 2005 08:59:14 -0400 Subject: [Errno 9] Bad File Descriptor on Windows 2003 Server & Py 2.4.1 Message-ID: The below script produces a '[Errno 9] Bad File Descriptor' when executed. If I remove the try: except: statements, the script stops when the error occurs. The purpose of the script is to monitor the size of the three main logs on a Windows 2003 server and send and email should any of the logs get shorter. It works fine... just don't know *why* it produces the '[Errno 9] Bad File Descriptor' error. I'm running Python 2.4.1 on Windows 2003 SP1 Server with no funky win32 extensions ;) logs = ['AppEvent.Evt', 'SecEvent.Evt', 'SysEvent.Evt'] app_size = 0 sec_size = 0 sys_size = 0 def send_email(LogName, old_size, new_size): f = "Somebody" t = "Somebody_Else at vt.edu" msg = MIMEText("""old_size = %d, new_size = %d""" %(old_size, new_size)) msg["Subject"] = "%s Log Just Got Shorter" %LogName msg["Message-id"] = email.Utils.make_msgid() msg["From"] = f msg["To"] = t h = "smtp.vt.edu" s = smtplib.SMTP(h) s.sendmail(f, t, msg.as_string()) s.quit() while 1: for log in logs: try: a = os.stat('C:\WINDOWS\System32\config\%s' %log) cur_size = a[6] print log print "cur_size", cur_size if log == 'AppEvent.Evt': print "old_size", app_size, "\n" if cur_size >= app_size: app_size = cur_size time.sleep(6) continue else: send_email(log, app_size, cur_size) time.sleep(6) continue elif log == 'SecEvent.Evt': print "old_size", sec_size, "\n" if cur_size >= sec_size: sec_size = cur_size time.sleep(6) continue else: send_email(log, sec_size, cur_size) time.sleep(6) continue else: print "old_size", sys_size, "\n" if cur_size >= sys_size: sys_size = cur_size time.sleep(6) continue else: send_email(log, sys_size, cur_size) time.sleep(6) continue except Exception, e: fp7 = file('log_mon_exception.txt', 'a') print >> fp7, e fp7.close() From jdc at uwo.ca Tue May 3 15:30:21 2005 From: jdc at uwo.ca (Dan Christensen) Date: Tue, 03 May 2005 15:30:21 -0400 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: <3dg5isF6qe1nhU1@news.dfncis.de> <1f7befae05043000165448b8d@mail.gmail.com> Message-ID: <87hdhkaz02.fsf@uwo.ca> Roel Schroeven writes: > Chris McAloney wrote: > >> Hi all, >> >> Okay, so I've been working on level seven for a LONG time now. I've >> decoded the first message to get the hint for the next level. Using the >> same tactics, then I decode the hint as well, but there are non-printable >> characters. I've tried stripping out those characters, quoting them to >> include in the URL and various anagrams of the printable characters, but >> nothing works. Does anybody have any suggestions? > > I just took a guess for the first of those non-printable characters, and > proceeded from there. I thought it was going to be too simplistic, but > it worked. And fortunately my first guess was the right one. Hmm, I didn't get any non-printable characters, just a regular English word to be used to get to level 8. I think you guys must be doing something wrong... Dan From flamesrock at gmail.com Wed May 11 02:27:01 2005 From: flamesrock at gmail.com (flamesrock) Date: 10 May 2005 23:27:01 -0700 Subject: windows directories for curr user In-Reply-To: <1115791696.278982.56430@g43g2000cwa.googlegroups.com> References: <1115769947.020454.170340@f14g2000cwb.googlegroups.com> <1115791696.278982.56430@g43g2000cwa.googlegroups.com> Message-ID: <1115792821.399365.319620@z14g2000cwz.googlegroups.com> thanks!! From censored at dontemailme.com Sat May 28 05:11:46 2005 From: censored at dontemailme.com (censored) Date: Sat, 28 May 2005 18:11:46 +0900 Subject: How to load plugins as objects? Message-ID: Hi. I'm hoping for a bit of programming guidance here .... I have an application I wrote (it's an irc bot fyi), with which I want to use plugins. Basically, I want there to be directory called plugins/ . In plugins, there should be a bunch of *.py files. Each file should contain a single class. When the application launches, I want the interpreter to scan the plugins/ dir for *.py files, and load each class in each every *.py file as an object an object in memory. I want it to so that every time I want the app to perform a new function, I just write a plugin and stick it in the plugins/ directory. What's the easiest way to go about this? From philippe at philippecmartin.com Tue May 17 18:41:13 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Tue, 17 May 2005 22:41:13 GMT Subject: Sorting x lists based on one list ... maybe an example would make sense: References: <428A68DF.4070705@syscononline.com> Message-ID: I had no clue this was feasible! Python folks should get the Nobel price ! Larry Bates wrote: > Why not merge the lists together using zip() and then > sort. > > info=zip(l1, l2, l3) > info.sort() > info.reverse > > Larry Bates > > Philippe C. Martin wrote: >> l1 = ['a','b','c'] >> l2 = ['toto','titi','tata'] # 'toto' refers to 'a', 'titi' to b' .... >> l3 = ['foo','bar','doe'] # 'foo' refers to 'a' ........ >> >> I want to reverse sort l1 and have l2 and l3 follow accordingly. >> >> Regards, >> >> Philippe >> >> >> >> >> >> >> Philippe C. Martin wrote: >> >> >>>Hi, >>> >>>I'm looking for an easy algorithm - maybe Python can help: >>> >>>I start with X lists which intial sort is based on list #1. >>> >>>I want to reverse sort list #1 and have all other lists sorted >>>accordingly. >>> >>>Any idea is welcome. >>> >>>Regards, >>> >>>Philippe >> >> From mefjr75 at hotmail.com Sun May 1 18:01:21 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 1 May 2005 15:01:21 -0700 Subject: Webbrowser On Windows In-Reply-To: References: Message-ID: <1114984881.087927.11700@o13g2000cwo.googlegroups.com> Hello Andrea, I have played around for a few seconds and have a few suggestions. The code is a little baffling it appears that there is no way to do that on windows. I have looked into Internet Explorer and have found that there is an option in Internet Explorer that controls this. In Internet Explorer ( some things may have changed or be slightly diffrent in your version ): open I.E. -> goto top toolbar and click: Tools->Internet Options->Browsing->Reuse windows for launching shortcuts. Uncheck that option and you should be able to just os.startfile or webrowser and have it open a new window. Have not looked into it but you can probably do this easily with win32api . Search MSDN and then translate that into win32api for Python. hth, M.E.Farmer From Robert at AbilitySys.com Mon May 2 14:32:19 2005 From: Robert at AbilitySys.com (Robert D. Young) Date: Mon, 2 May 2005 11:32:19 -0700 Subject: How to tell if invoked through IDLE or command line? Message-ID: <117cshk6l796o75@corp.supernews.com> I've probably asked this before, but how can I tell within the program I'm running if the .py files was involved by "run module" in IDLE or by using the .py assoication with the python.exe program? I'd like to prevent running under certain circumstances, or pop-up warnings, or change character displays (some look different when run under IDLE). - Robert From terjeja at gmail.com Mon May 2 16:21:20 2005 From: terjeja at gmail.com (terjeja at gmail.com) Date: 2 May 2005 13:21:20 -0700 Subject: Mouseclick In-Reply-To: References: <1e140f34.0505021030.9f615dc@posting.google.com> Message-ID: <1115065280.936189.67050@o13g2000cwo.googlegroups.com> Benji York wrote: > Terje Johan Abrahamsen wrote: > > I have been trying desperately for a while to make Python push the > > left mousebutton. > > Here's some code I've used to simulate a *right* click, but it should > be obvious how to make it do what you want: > > void sendRightClick(void) > { > PostMessage(GetForegroundWindow(), WM_RBUTTONDOWN, MK_RBUTTON, 0); > PostMessage(GetForegroundWindow(), WM_RBUTTONUP, 0, 0); > } Thanks for the input. I have 'Pythonized' the code a little: >>> def click(): ... windll.user32.SetCursorPos(100, 100) ... win32gui.PostMessage(win32gui.GetActiveWindow(), win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, 0) ... win32gui.PostMessage(win32gui.GetActiveWindow(), win32con.WM_LBUTTONUP, 0, 0) and when I try it like this: n = click() Sure, the cursor moves, but it does not click. What am I doing wrong? Thanks in advance From just at xs4all.nl Wed May 4 08:51:59 2005 From: just at xs4all.nl (Just) Date: Wed, 04 May 2005 14:51:59 +0200 Subject: py2exe and library.zip References: <5uadnUTTqv6Iw-rfRVn-qw@powergate.ca> Message-ID: In article , Peter Hansen wrote: > [ ... ] (Note to self: check if zip files that can > be in sys.path can be compressed, Yes. > and if py2exe compresses them.) Don't know, but I assume yes. Just From reallarryboy at yahoo.com Wed May 25 21:43:44 2005 From: reallarryboy at yahoo.com (mwdsmith) Date: 25 May 2005 18:43:44 -0700 Subject: Checking for a full house Message-ID: <1117071824.882035.250710@g49g2000cwa.googlegroups.com> Hi, I'm new to python, and I'm not sure if this is the place to post this kind of question; so feel free to tell me if I should take this elsewhere. So, to start me off on python, I decided to put together a little script to test the probabilities of rolling certain combinations of dice. Below is my code for checking for a full house (when rolling with 5 dice). A roll is a list, eg [1, 3, 5, 1, 4] (this example is not a full house) def removeAll(element, num2Rem, list): l = list[:] for num in range(0, num2Rem): l.remove(element) return l def isfullHouse(roll): for die in range(1,7): if roll.count(die)==3: l = removeAll(die, 3, roll) if l[0]==l[1]: return 1 return 0 My questions is this: is there a better way to do this? A way that's more natural to python, or just more efficient perhaps? ps. A roll of [1, 2, 1, 1, 2] is a full house (three of one kind and two of another) From skip at pobox.com Wed May 18 09:40:15 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 18 May 2005 08:40:15 -0500 Subject: Python forum In-Reply-To: <428B1803.80509@softhome.net> References: <428B1803.80509@softhome.net> Message-ID: <17035.17855.129397.462296@montanaro.dyndns.org> >> If you speak German, there is a forum at www.python-forum.de . There >> is also an english one at http://python-forum.org/py/index.php, but >> as you can see, there's not much traffic :-/ Jonas> There are few messages because they are not known. I believe that Jonas> they would be due to add in the resources of python.org I think the general thought is that python.org should link to proven resources as opposed to endorse unproven ones. "Endorse" is probably too strong a word, but the resources to maintain the website are limited, so we have to be judicious about what we add. Even in the Python world, not every scrap of information is useful. In any case, I've updated the /community/lists.html page on the python.org website with this information. I also located a French language forum mentioned in the docs and added the German language forum to the German section of the doc/NonEnglish.html page. (Is "forums" okay as a plural of "forum" or should I have used "fora"?) Skip From bogus@does.not.exist.com Thu May 19 09:35:02 2005 From: bogus@does.not.exist.com () Date: Thu, 19 May 2005 13:35:02 -0000 Subject: No subject Message-ID: #! rnews 1636 Newsgroups: comp.lang.python Path: news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!newsfeeder.wxs.nl!textfeed1.on.meganewsservers.com!meganewsservers.com!feeder2.on.meganewsservers.com!216.196.98.140.MISMATCH!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp From: Harry George Subject: Re: NaN support etc. X-Nntp-Posting-Host: cola2.ca.boeing.com Content-Type: text/plain; charset=iso-8859-1 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Lines: 38 Sender: hgg9140 at cola2.ca.boeing.com Content-Transfer-Encoding: 8bit Organization: The Boeing Company References: <428ba190$0$7687$9b622d9e at news.freenet.de> <1116449707.021063.132500 at g44g2000cwa.googlegroups.com> Mime-Version: 1.0 Date: Thu, 19 May 2005 13:14:32 GMT Xref: news.xs4all.nl comp.lang.python:378109 "S?bastien Boisg?rault" writes: > Martin v. L?wis a ?crit : > > Andreas Beyer wrote: > > > How do I find out if NaN, infinity and alike is supported on the > current > > > python platform? [snip] > > But, practically, I have never found a platform where > the following fpconst-like code did not work: > > import struct > cast = struct.pack > > big_endian = cast('i',1)[0] != '\x01' > if big_endian: > nan = cast('d', '\x7F\xF8\x00\x00\x00\x00\x00\x00')[0] > else: > nan = cast('d', '\x00\x00\x00\x00\x00\x00\xf8\xff')[0] > > Can anybody provide an example of a (not too old or > exotic) platform where this code does not behave as > expected ? > > Cheers, > > SB > I use fpconst too. I've been concerned that its source home seems to wander. Any chance of it being added to the base distro? -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 294-4718 From gvanrossum at gmail.com Mon May 2 11:04:40 2005 From: gvanrossum at gmail.com (guido@python.org) Date: 2 May 2005 08:04:40 -0700 Subject: How to kill a SocketServer? In-Reply-To: <7xekcq75av.fsf@ruckus.brouhaha.com> References: <7xwtqj1lh1.fsf@ruckus.brouhaha.com> <7xpswa4wfu.fsf@ruckus.brouhaha.com> <17013.25972.965219.254879@montanaro.dyndns.org> <7xekcq75av.fsf@ruckus.brouhaha.com> Message-ID: <1115046280.413931.16970@g14g2000cwa.googlegroups.com> [Skip Montanaro] > > def serve_forever(self): > > while self.serving: > > r,w,e = select.select([self.socket], [], [], self.pause) > > if r: > > self.handle_request() > > > > and set self.pause to something short-ish. The select call times out and > > the server exits. [Paul Rubin] > Ah, good point. Something like this should probably be added to > SocketServer.py (optional timeout parameter to serve_forever), or at > least the trick should be mentioned in the docs. I like this idea, and perhaps you all could come up with some more useful APIs in this area; I know that I often struggle a bit with getting these servers to stop. (I also like the idea of having the worker thread mixin part of the standard library -- it seems generally useful.) --Guido van Rossum (home page: http://www.python.org/~guido/) From bob at greschke.com Wed May 18 22:36:09 2005 From: bob at greschke.com (Bob Greschke) Date: Wed, 18 May 2005 20:36:09 -0600 Subject: Tkinter Return/Enter key handling References: Message-ID: Sorry. Yeah, Linux. Eww. Ick. Don't want to mess with .Xdefaults. It works, so I guess I'll just keep the .bind. Thanks, Phil! "phil" wrote in message news:mailman.180.1116466047.8733.python-list at python.org... > If you are talking Linux there's .Xdefaults > Which I had to resort to for tn5250. > For Tkinter apps its a LOT easier to just use bind. > > Win32? dunno. From http Thu May 19 19:59:25 2005 From: http (Paul Rubin) Date: 19 May 2005 16:59:25 -0700 Subject: Tkinter special math chars References: Message-ID: <7xll6a6a3m.fsf@ruckus.brouhaha.com> phil writes: > Using Tkinter to teach high school geometry. Sorta committed to > Tkinter at least for now. Would like to use some special chars like > limits, infinity, square root, cube root and a buch more. If you want to get really fancy, you could do what Wikimedia does: take TeX input, run it through TeX and a dvi converter and make it into a graphic that you simply display as a .gif. From reidarok at gmail.com Thu May 26 09:17:21 2005 From: reidarok at gmail.com (reidarok at gmail.com) Date: 26 May 2005 06:17:21 -0700 Subject: Access from one class to methode of other class In-Reply-To: <3flu22F8g4u4U1@news.dfncis.de> References: <3flu22F8g4u4U1@news.dfncis.de> Message-ID: <1117113441.649947.315350@g44g2000cwa.googlegroups.com> I don't know if your're actually calling the classes '1' and '2', but that's a really bad idea! > class 2: > def ins(self) > d.entry.insert(variable) This is probably where you're getting the NameError. d is not defined, so calling d.entry will generate an error. Reidar From Scott.Daniels at Acm.Org Tue May 3 10:21:31 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 May 2005 07:21:31 -0700 Subject: problem in the compiler ? In-Reply-To: References: <338366A6D2E2CA4C9DAEAE652E12A1DE025204C3@au3010avexu1.global.avaya.com> Message-ID: <427782e9$1@nntp0.pdx.net> Glauco Silva wrote: > python : 2.3.5 > os: win 2K This part is good enough (though sometimes it helps to mention the service pack number on windows systems). > My code is like this: > > MyClass() > > class MyClass: > def __init__(self): > btn = RadioButton(command=self.Function) > def Function(self): > print "Enter in the function" This is not good enough. Show us a small actual example that exhibits the problem behavior on your machine. Often in the course of doing this distillation, the original problem will become clear to you. The code above fails with: Traceback (most recent call last): File "", line 1, in -toplevel- MyClass() NameError: name 'MyClass' is not defined on the initial call to MyClass(). I suspect this is not what you care about. Don't make people trying to help you do any work you cannot do yourself. Imagine yourself browsing the newsgroup and trying to decide whether to spend some time trying to help someone with a problem. Would _you_ want to spend time trying to guess what the code was with the problem as well as what the problem was, or would you decide to help someone else out? --Scott David Daniels Scott.Daniels at Acm.Org From a at b.c Mon May 9 02:52:36 2005 From: a at b.c (D H) Date: Mon, 09 May 2005 01:52:36 -0500 Subject: Fredrik Lundh In-Reply-To: References: Message-ID: Sakesun Roykiattisak wrote: > IMHO, Pythonware.com does not have to be about python. It can be > anything the maintainer want it to be. > > Get the point ? You successfully repeated my own argument, so yes, I get the point. From kraus at hagen-partner.de Fri May 13 09:38:37 2005 From: kraus at hagen-partner.de (Wolfram Kraus) Date: Fri, 13 May 2005 15:38:37 +0200 Subject: doc tags? In-Reply-To: References: Message-ID: Wolfram Kriesing wrote: > i was already searching and remember i had seen something like "its not needed". > > Anyway, are there any doc tags, like in Java/PHPDoc etc, where you can > describe parameters (@param[eter]), return values (@ret[urn]), > attributes (@var), references (@see), etc? > > I guess I have just not found the link to the last flameware about it :-)) > I'm not sure if there is something like that builtin, but you can use epydoc: http://epydoc.sourceforge.net/ HTH, Wolfram :-) From mwm at mired.org Thu May 12 01:24:55 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 12 May 2005 00:24:55 -0500 Subject: Finding startup files References: <1115829176.541687.22090@z14g2000cwz.googlegroups.com> <1184dj36mp5sdc6@corp.supernews.com> Message-ID: <86d5rxkod4.fsf@guru.mired.org> jeff elkins writes: > On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote: >> On 2005-05-11, hemagician at gmail.com wrote: >> > The following script demonstrates a method that should work for you. I >> > believe it is entirely cross-platform. >> > >> > #! /usr/bin/python >> > >> > import sys >> > import os >> > >> > print os.path.abspath(os.path.dirname(sys.argv[0])) >> >> That will probably work most of the time, but... >> >> 1) you're not gauranteed that argv[0] contains the application >> path/filename. >> >> 2) the directory containing the executable is not where >> configuration files are supposed to be stored under >> Unix/Linux. > > Thanks Grant, > > I live and develop in Linux, but unfortunately, 99.99% of the users of this > particular application (analysis of medical laboratory data) will be working > with Windows. Yes, but Windows these days supports multiple users. Are you sure that you want to restrict your users to one configuration file per installed version of the program? I'm not sure Windows has a good solution to this problem. My experiences with trying to share applications between users on Windows haven't been very pleasant. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From ville at spammers.com Mon May 23 02:34:35 2005 From: ville at spammers.com (Ville Vainio) Date: 23 May 2005 09:34:35 +0300 Subject: first release of PyPy References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116644536.741250.249860@g44g2000cwa.googlegroups.com> <1116653460.808204.74460@g43g2000cwa.googlegroups.com> <87mzqpytep.fsf@wilson.rwth-aachen.de> <7xfywhxerd.fsf@ruckus.brouhaha.com> <87is1dyru8.fsf@wilson.rwth-aachen.de> Message-ID: >>>>> "Christian" == Christian Tismer writes: >> PyPy is written in python, if it can be compiled then the programs >> can >> be as well. Christian> Well, this is not really true. PyPy is written in Christian> RPython, a sub-language of Python that is implicitly Christian> defined by "simple and static enough to be compilable". Could it be possible to tag some modules in application code as RPython-compatible, making it possible to implement the speed critical parts in RPython? -- Ville Vainio http://tinyurl.com/2prnb From jerf at jerf.org Sun May 1 18:16:12 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Sun, 01 May 2005 18:16:12 -0400 Subject: Python interpreter in Basic or a Python-2-Basic translator. References: <1114953507.031865.244920@g14g2000cwa.googlegroups.com> Message-ID: On Sun, 01 May 2005 06:18:27 -0700, Engineer wrote: > The security 'droids have decided that since the MS Office Suite is a > "standard" application then software written in MS Office VBA must be > "safe." "Melissa". (Google hint: "Virus".) Given the brazen stupidity demonstrated by these decision makers in the face of *internationally newsworthy* plain facts to the contrary, this may be a "brush up the resume" situation. Life's short. Good luck. More constructively, see if you can convince your VBA installation to run on Javascript(/Jscript) instead of Visual Basic. While it has some annoyances next to Python, by and large it should be a much more tolerable choice. It's not Python, but it's surprisingly close in a lot of ways. From aa at hanmail.net Fri May 27 19:30:25 2005 From: aa at hanmail.net (Çϳª·Î) Date: Sat, 28 May 2005 08:30:25 +0900 Subject: just a test .sorry Message-ID: sorry From t.bettio at transnorm.ch Tue May 3 16:16:53 2005 From: t.bettio at transnorm.ch (Tiziano Bettio) Date: Tue, 03 May 2005 22:16:53 +0200 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: Message-ID: <4277DC35.6020607@transnorm.ch> PLEASE HELP... What the hell do i have to pronounce in puzzle 5???? Some useful hints would be awesome thx From tgm2tothe10thpower at replacetextwithnumber.hotmail.com Wed May 25 09:45:38 2005 From: tgm2tothe10thpower at replacetextwithnumber.hotmail.com (Thomas G. Marshall) Date: Wed, 25 May 2005 13:45:38 GMT Subject: What are OOP's Jargons and Complexities? References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> <1779523.9sBn8HKUcY@yahoo.com> <1116988493.510520.199020@g47g2000cwa.googlegroups.com> Message-ID: <6k%ke.55$Tm3.11@trndny09> beliavsky at aol.com coughed up: > Thomas G. Marshall wrote: > *Missattributed* --Thomas G. Marshall (I) did /not/ write the following: >>> I am not familiar with modern Fortran. Surely it at least has >>> argument prototyping by now? > > Since the 1990 standard, if Fortran subroutines and functions are > placed in MODULEs, or if INTERFACEs are provided, the compiler checks > that procedures are called with the right types (int or float, scalar > or array, etc.) of arguments. > >> There are some fortran advocates that pop into here now and again. >> Frankly, I'm spooked by how far fortran seems to have come. There >> is even OO support now. OI. > > Some Fortranners think the language has gotten too big and > complicated, sounding a bit like C programmers complaining about C++ > (I don't mean that pejoratively). There are old-poops in every discipline. :) -- Unix users who vehemently argue that the "ln" command has its arguments reversed do not understand much about the design of the utilities. "ln arg1 arg2" sets the arguments in the same order as "mv arg1 arg2". Existing file argument to non-existing argument. And in fact, mv itself is implemented as a link followed by an unlink. From fredrik at pythonware.com Tue May 10 13:21:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 10 May 2005 19:21:27 +0200 Subject: object oriented inheritance problem References: Message-ID: Matthew Thorley wrote: > So is elementtree a module of modules? I didn't know you could do that. "elementtree" is a package. see: http://docs.python.org/tut/node8.html#SECTION008400000000000000000 for a bit more information. From richardjones at optushome.com.au Mon May 23 01:04:27 2005 From: richardjones at optushome.com.au (richard) Date: Mon, 23 May 2005 15:04:27 +1000 Subject: problem uploading ZIP file tp PyPI References: Message-ID: <42916459$0$5175$afc38c87@news.optusnet.com.au> John Machin wrote: > FYI, there are a few unreconstructed diehards out here who neither run > on a *x platform nor run bleeding-edge Python straight out of last > night's CVS. I think you need to pull your head in, mate. The bug you discovered in PyPI is plain and simple a bug in its attempts to discover whether an uploaded ZIP file was generated by distutils. It's a bug. It will get fixed. Get over your damn platform paranoia. Richard From dagurp at gmail.com Mon May 2 08:36:23 2005 From: dagurp at gmail.com (dagurp at gmail.com) Date: 2 May 2005 05:36:23 -0700 Subject: Locale and cookies Message-ID: <1115037383.913329.143470@l41g2000cwc.googlegroups.com> I'm doing a small mod_python project and I'm using a locale for my own language. This is not a problem until I start using cookies because the cookie module in mod_python uses time.strftime() to write the expiration times and therefore makes invalid cookies. I tried to fix this by changing the locale back to "English" before creating cookies and that works on Windows but not for Linux. If I use "en_EN.ISO8859-1" it works on Linux but not on Windows. I'm sure there's an easy way to fix this. From dalke at dalkescientific.com Thu May 12 22:48:17 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 13 May 2005 02:48:17 GMT Subject: Escape spaces in strings References: Message-ID: Florian Lindner wrote: > is there a function to escape spaces and other characters in string for > using them as a argument to unix command? In this case rsync > (http://samba.anu.edu.au/rsync/FAQ.html#10) It's best that you use the subprocess module and completely skip dealing with shell escapes. The module is standard with 2.4 but you can get the module and use it for 2.2 or 2.3. http://docs.python.org/lib/module-subprocess.html http://cvs.sourceforge.net/viewcvs.py/*checkout*/python/python/dist/src/Lib/subprocess.py Andrew dalke at dalkescientific.com From maxm at mxm.dk Tue May 3 14:57:47 2005 From: maxm at mxm.dk (Max M) Date: Tue, 03 May 2005 20:57:47 +0200 Subject: Read / Write image file In-Reply-To: <1115143942.944188.158270@g14g2000cwa.googlegroups.com> References: <1115143942.944188.158270@g14g2000cwa.googlegroups.com> Message-ID: <4277c8d6$0$256$edfadb0f@dread12.news.tele.dk> codecraig wrote: > I have a image file on my pc, say a .jpg. Basically I want to setup a > client/server socket, and I want the client to read in the jpg and send > it to the server, where the server can write that data into a new file > on the server. > > I tried just doing something like.. > > x = open("abc.jpg") > y = x.read() > tmp = open("newFile.jpg", "w") > tmp.write(y) > tmp.close() > x.close() > > ...but that doesn't give me a copy of abc.jpg > > any ideas? Thanks > x = open("abc.jpg", 'rb') -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From oliver.andrich at gmail.com Sat May 28 02:54:20 2005 From: oliver.andrich at gmail.com (Oliver Andrich) Date: Sat, 28 May 2005 08:54:20 +0200 Subject: search/replace in Python In-Reply-To: References: Message-ID: <6f7b52d050527235421bf8a9b@mail.gmail.com> Hi, 2005/5/28, Vamsee Krishna Gomatam : > Hello, > I'm having some problems understanding Regexps in Python. I want > to replace "PHRASE" with > "PHRASE" in a block of > text. How can I achieve this in Python? Sorry for the naive question but > the documentation is really bad :-( it is pretty easy and straightforward. After you imported the re module, you can do the job with re.sub or if you have to do it often, then you can compile the regex first with re.compile and afterwards use the sub method of the compiled regex. The interesting part is re.sub(r"(.*)",r"\1", text) cause here the job is done. The first raw string is the regex pattern. The second one is the target where \1 is replaced by everything enclosed in () in the first regex. Here is the output of my ipython session. In [15]: text="This is a Python. And some random nonsense test....." In [16]: re.sub(r"(.*)",r"\1", text) Out[16]: 'This is a Python. And some random nonsense test.....' Best regards, Oliver From tjreedy at udel.edu Fri May 27 22:50:48 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 27 May 2005 22:50:48 -0400 Subject: Software licenses and releasing Python programs for review References: <1117245014.218831.317750@g14g2000cwa.googlegroups.com> Message-ID: "poisondart" wrote in message news:1117245014.218831.317750 at g14g2000cwa.googlegroups.com... > testing on other platforms, but also I would like to explore the > different software licenses that are available (there seems to be There is an Open Software Foundation (or something close) with a site listing and linking to numerous OSF-approved licenses. TJR From rkern at ucsd.edu Wed May 18 09:48:13 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 18 May 2005 06:48:13 -0700 Subject: Python forum In-Reply-To: <17035.17855.129397.462296@montanaro.dyndns.org> References: <428B1803.80509@softhome.net> <17035.17855.129397.462296@montanaro.dyndns.org> Message-ID: Skip Montanaro wrote: > (Is "forums" okay as a plural of "forum" or should I have used "fora"?) dict.org says _forums_. I used _fora_, but I'm silly. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From mrstephengross at hotmail.com Thu May 5 13:57:43 2005 From: mrstephengross at hotmail.com (mrstephengross) Date: 5 May 2005 10:57:43 -0700 Subject: How to detect a double's significant digits In-Reply-To: References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: <1115315863.050413.275390@g14g2000cwa.googlegroups.com> So how can I get the kind of information I want then? For example: 0.103 --> 3 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.0000103 --> 7 Any ideas? --Steve From dieter at handshake.de Fri May 27 10:30:57 2005 From: dieter at handshake.de (Dieter Maurer) Date: 27 May 2005 16:30:57 +0200 Subject: python24.zip References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> <428faddd$0$26322$9b622d9e@news.freenet.de> <4290dc79$0$9989$9b622d9e@news.freenet.de> <42948097$1@nntp0.pdx.net> Message-ID: Scott David Daniels writes on Wed, 25 May 2005 07:10:00 -0700: > ... > I'll bet this means that the 'zope.zip', 'python24.zip' would drop > you to "about 12500 - 10000 = 2500" failing opens. That should be > an easy test: sys.path.insert(0, 'zope.zip') or whatever. > If that works and you want to drop even more, make a copy of zope.zip, > update it with python24.zip, and call the result python24.zip. We can not significantly reduce the amount of opens further: Each module import from a zip archive opens the archive. As we have about 2.500 modules, we will get this order of opens (as long as we use Python's "zipimporter"). The "zipimporter" uses a sequence of "stat"s to determine whether it can handle a path item: it drops the last component until it gets an existing file object and then checks that it is indeed a zip archive. Adding a cache for this check could save an additional few hundreds of opens. Dieter From gh at ghaering.de Fri May 20 03:22:43 2005 From: gh at ghaering.de (Gerhard Haering) Date: Fri, 20 May 2005 09:22:43 +0200 Subject: [pysqlite] How do I use pysqlite in a multi-threading env.? In-Reply-To: References: Message-ID: <20050520072243.GA27043@mylene.ghaering.de> On Fri, May 20, 2005 at 08:42:54AM +0200, F. GEIGER wrote: > In my wxPython-app a part of it gathers data, when a button is pressed, and > stores it into a db. > > The GUI part should display the stuff being stored in the db. > > When both parts work on the same connection, I get "SQL statements in > progress errors". Seems ok to me, you can't do that. You get that error message with which pysqlite call? > So, next step: Both parts get a separate connection. Now I get "Database > locked" errors. Hmm, yes, it's GUI stuff after all, being all in the same > thread. One connection did not commit() or rollback() within the default timeout (5 seconds). SQLite is not a good solution if you need long transactions, because other SQLite connections are blocked, then. > So, next step: I put the data gathering part into a real thread, that's > started, wehn the "Scan" button is pressed. This way the "Database locked"- > errors should got away. But now I get "SQLite objects created in a thread > can only be used in that same thread.The object was created in thread id > 3576 and this is thread id 1040". Hmm, true, I want to display db content, > that was stored by an other thread. But that's what multi-threading > capabilities are for! Yes, but pysqlite's threadsafety level is 1, that means you cannot share a connection object among multiple threads. In order to ensure that and to avoid that you get random and unexplainable crashes, I implemented this warning. > I must be missing something here. Anyway, I'm a bit lost now, really. So, > how are you doing such stuff with pysqlite? Use multiple connections and commit/rollback early. HTH, -- Gerhard -- Gerhard H?ring - gh at ghaering.de - Python, web & database development -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 196 bytes Desc: Digital signature URL: From flupke at nonexistingdomain.com Thu May 12 09:12:59 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 12 May 2005 13:12:59 GMT Subject: Destructor Woes, was Advice needed on __del__ In-Reply-To: References: <427FBAD4.3070004@anvilcom.com> <42800279.3B26FFF3@pauahtun.org> Message-ID: Fredrik Lundh wrote: > "flupke" wrote: > > >>>Then i got a tip that you can register a function that needs to be >>>called when the object is going to be deleted. >>>For instance to register a function __exit, you do this: > > >>>class line: >>> def __init__(s,glob,argl,color=''): >>> atexit.register(s.__exit) > > >>I don't know what's wrong in your example. Here it works (doesn't help >>you of course). I would first try with an easy example an try to test >>the atexit functionality like that. It seems that the problem you are >>having isn't related to the atexit part. > > > do you (or whoever gave you the tip) have the slightest idea what atexit does? > > As i said, it works for me. I use it to log the closure of my main program. Maybe my first message wasn't clear on the use of atexit. Benedict From scrimp212 at yahoo.com Wed May 4 12:46:25 2005 From: scrimp212 at yahoo.com (scrimp) Date: 4 May 2005 09:46:25 -0700 Subject: FTP/TLS connection using python Message-ID: <1115225185.951540.128460@z14g2000cwz.googlegroups.com> Hello, I was wondering if there is any other way to securly connect to an FTP site using SSL or TLS? I dont have the option of purchasing M2Crypto from the site. Any help/suggestions would help. Thanks! --Barry From rbt at athop1.ath.vt.edu Wed May 25 23:12:44 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 25 May 2005 23:12:44 -0400 Subject: urllib2 and SSL Message-ID: urllib2 handles https request flawlessly on my Linux machines, but errors out on Windows like this: PythonWin 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. working_0... working_2... Is SSL not supported on win32? From bronger at physik.rwth-aachen.de Wed May 11 00:55:48 2005 From: bronger at physik.rwth-aachen.de (Torsten Bronger) Date: Wed, 11 May 2005 06:55:48 +0200 Subject: Python Graphing Utilities. References: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> <797fe3d405051010392c00011f@mail.gmail.com> Message-ID: <87psvycqej.fsf@wilson.rwth-aachen.de> Hall?chen! Fernando Perez writes: > [...] > > And I'd also second the matplotlib suggestion, to which I've by > now fully switched after years of faithful gnuplot usage. > Matplotlib is very good, has an active development community, and > it is designed from the ground up not only as a library for > rendering plots to screen/disk, but also for embedding into guis > (with support for Tk, WX, GTK, QT and FLTK). Why not for Gnuplot, by the way? On sceen, matplotlib looks extremely good, however, I still need Gnuplot for the hardcopy version[*]. It *seems* to me that the programming interfaces are quite different, so a Gnuplot backend for matplotlib would be helpful for me. Tsch?, Torsten. [*] because of the "pslatex" backend, which means that the plot is typeset by the same LaTeX run as your document --> consistent fonts, TeX-quality formulae -- Torsten Bronger, aquisgrana, europa vetus From osv at javad.ru Fri May 27 08:15:23 2005 From: osv at javad.ru (Sergei Organov) Date: 27 May 2005 16:15:23 +0400 Subject: Strings for a newbie References: Message-ID: "Malcolm Wooden" writes: > I'm trying to get my head around Python but seem to be failing miserably. I > use RealBasic on a Mac and find it an absolute dream! But Python....UGH! > > I want to put a sentence of words into an array, eg "This is a sentence of > words" > > In RB it would be simple: Simple?! 7 lines of code for such a trivial task is simple?! > Dim s as string > Dim a(-1) as string > Dim i as integer > > s = "This is a sentence of words" > For i = 1 to CountFields(s," ") > a.append NthField(s," ",i) > next > > That's it an array a() containing the words of the sentence. > > Now can I see how this is done in Python? - nope! from string import split s = "This is a sentence of words" a = split(s) or, s = "This is a sentence of words" a = s.split() or even a = "This is a sentence of words".split() -- Sergei. From http Tue May 17 02:37:31 2005 From: http (Paul Rubin) Date: 16 May 2005 23:37:31 -0700 Subject: Windows distribution suggestions? Message-ID: <7x3bsmfjdg.fsf_-_@ruckus.brouhaha.com> As what must be penance for something or other, I'm needing to release a Python app for use under Windows XP. Please be gentle with me since I'm a Un*x weenie and the only thing I've had much practice with under Windows is rebooting it. My app contains three different programs (say alice.py, bob.py, and carol.py) that need to be independently launchable, and a dozen or so other .py files that get imported into those first three. What I'd really really like is to make a single installer called (say) "app.exe". Launching app.exe should completely install Python, unpack all the necessary modules, and make three icons (alice, bob, carol) on the desktop. I know there's various ways of building Windows distros like that, but am not sure what's currently preferred. Gordon McMillan's site www.mcmillan-inc.com has had its domain expire (he really should renew it before some squatter grabs it!) and the mirror that I've found indicates that it was last updated for Python 2.3. I wrote my app under 2.4 and while I don't think I depend heavily on any 2.4 features, I'd rather not have to downgrade just to make this exe installer. There's also py2exe--is that as good? Also, what's the preferred way of releasing updates? That is, let's say I want to update my .py files and release a new version fairly frequently--should I just make a new .exe every time? Would launching the new one cleanly overwrite or uninstall the old one? Total coolness would be a way to ship an "update.py" along with the app, that syncs the app up to a Subversion repository, but that may be asking a bit much. I do have Visual C++ installed on the development machine, if that helps. From utabintarbo at gmail.com Sat May 7 10:45:04 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 7 May 2005 07:45:04 -0700 Subject: Ask for a tools to protect my .pyc file :) In-Reply-To: References: Message-ID: <1115477104.218282.154990@g14g2000cwa.googlegroups.com> pyobfuscate http://www.lysator.liu.se/~astrand/projects/pyobfuscate/ From k04jg02 at kzoo.edu Tue May 10 13:32:46 2005 From: k04jg02 at kzoo.edu (Joseph Garvin) Date: Tue, 10 May 2005 17:32:46 +0000 Subject: Solipsis: Python-powered Metaverse In-Reply-To: References: Message-ID: <4280F03E.2070903@kzoo.edu> Terry Reedy wrote: >Today I followed a link to an interesting Python application I have not >seen mentioned here before: http://solipsis.netofpeers.net/wiki/HomePage/. > >"A peer-to-peer system for a massively multi-participant virtual world " > >It is a France Telecom R&D project, LGPL licenced, still in alpha, built on >Python, Twisted, WxPthon, PIL, and probably other components actual or >considered. The new Node software, rewritten with Twisted, was released >yesterday. > >Terry J. Reedy > > > I was looking at this earlier today because I was curious how they were going to handle performance concerns (both due to Python and bandwidth). I'm having trouble understanding all of the details -- what is the significance of the use of a torus for the world space? Does this somehow help in the computation of the convex hull? From frankie.y.liu at gmail.com Mon May 9 12:58:19 2005 From: frankie.y.liu at gmail.com (ohms377) Date: 9 May 2005 09:58:19 -0700 Subject: Listing of declared variables and functions Message-ID: <1115657899.543887.284720@f14g2000cwb.googlegroups.com> Dear python users, In interactive mode, I was wondering if there is a way to list all declared variables and functions (and from global workspace). Thanks, -frankie From mwm at idiom.com Mon May 23 22:04:54 2005 From: mwm at idiom.com (Mike Meyer) Date: 23 May 2005 19:04:54 -0700 Subject: Running a python program during idle time only References: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> <1116869538.611233.264960@g14g2000cwa.googlegroups.com> Message-ID: <5j64x9gz09.fsf@idiom.com> "los" writes: > Thanks for all the replies. > > I did try using nice under windows. I created a java program that > would just loop and print numbers on the screen. Even when I ran that > simple program with nice, (lets call it program A) as soon as I started > the program the cpu went all the way to 100% usage. Then when I ran > another program that did the same thing (lets call it program B), > program A halted to let B finish, then it started again. Nevertheless > it still hogged all the cpu while I was using the computer. Actually, CPU usage going to 100% when you run a cpu-intensive program under nice is what you expect - even want. The idea is that the nice'd prog soaks up all the "unused" cpu on the system. You don't say whether program B was niced or not, but from the description, it wasn't. And you got the behavior I thought you wanted: the nice'd program quit using any CPU at all while the normal program was running. At least, that's the behavior I want from my backgrounded tasks. > For my indexing program I just wrote a simple python program and called > on the python os.walk() method to iterate through the drive and then it > connects to a database to store some information. Then I wrote a > simple interface to connect to the database to search for files using > visual basic. Once everything is indexed it works fine, but it would > be nice to have the program looping through and indexing the files all > the time to account to file updates, deletes, and relocation, but > without hurting the performance when I'm using the computer. As has been pointed out, your daemon is doing disk i/o, which nice won't mediate properly. > So really what I am looking for is some way to have the program only > start indexing and crawling through the hd after 5 minutes of no user > interaction with the computer. Why 5 minutes? What if you've gone to get a cup of coffee while something that takes more than five minutes is completing? I'm sure there are tools for doing this kind of thing on windows. That's pretty much how screen savers work. I haven't written a screen saver for windows, though - so I have no idea what you're looking for. Note that the screen savers I have written still lowered their priority to avoid interfering with any long-running tasks you may be waiting on. At least for CPU usage. > I'm going to take a look at this CPU load possibility. But I'm afraid > that this will work similarly to "nice" in which case it will let the > program kick in when the CPU isn't being used heavily, but I might > still be using the computer. I think you're right. On a completely different topic, this looks like the wrong way to solve the problem. You want to update a search engine based on changes to the underlying file system. The right way to do this isn't to just keep rescanning the file system, it's to arrange things so that your scanner gets notified of any changes made to the file system. I did something like this for my web site search engine, but that's hooked into the SCM that's used for propogating changes to the web site. I know someone is working on patches to the FreeBSD kernel to make this kind of thing work. It would seem that some of the "backup" facilities that worked by keeping a mirror of the disk on separate media would have to have used such hooks, but maybe not. I'm not sure this is possible. If it is, it's almost certainly deep magic. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From finite.automaton at gmail.com Wed May 4 18:01:08 2005 From: finite.automaton at gmail.com (Lonnie Princehouse) Date: 4 May 2005 15:01:08 -0700 Subject: how can I sort a bunch of lists over multiple fields? In-Reply-To: References: <1114623282.855415.132040@l41g2000cwc.googlegroups.com> <1114634355.348110.141690@o13g2000cwo.googlegroups.com> <1114710873.292998.128090@f14g2000cwb.googlegroups.com> <1114714105.582253.12150@f14g2000cwb.googlegroups.com> <1114724023.743271.275710@g14g2000cwa.googlegroups.com> <1114796569.028242.45700@o13g2000cwo.googlegroups.com> Message-ID: <1115244068.789209.225120@f14g2000cwb.googlegroups.com> > If you want to compare partial keys, often the simplest approach is to > use tuples as keys, with the elements of the tuple being the "parts" of > the key. Python's standard tuple comparison mechanism takes care of the > rest. Right, but suppose it's expensive to generate each part of the key - e.g. a database query or some kind of hash, so it doesn't make sense to compute the whole key in advance if the first part is sufficient to establish an ordering most of the time. This is what I had in mind (I should have been more clear about that) Sure, you could put together a lazy evaluation object to use for elements of the tuple, but this again becomes equivalent to writing a __cmp__ function... From david.tolpin at gmail.com Sun May 29 17:03:33 2005 From: david.tolpin at gmail.com (david.tolpin at gmail.com) Date: 29 May 2005 14:03:33 -0700 Subject: cgi.py? Message-ID: <1117400613.000360.223440@f14g2000cwb.googlegroups.com> Hi, I've looked into cgi.py from 2.4's distribution, and its contents puzzle me. In parse_header, the first line splits on ';': plist = map(lambda x: x.strip(), line.split(';')) but header parameters may contain semicolon in quoted strings: Content-Type: image/jpeg; filename="home:lib;images;face.jpg" and headers like this one will be parsed incorrectly. A few subsequent lines unquote a quoted value, but the only place where quoted-string production is defined is RFC 3875, and there is no quote escaping in the production (nor in any other draft or related RFC). So, even if the former is fixed, the latter will still prevent headers like Content-Type: text/plain; filename="c:\files\"; title="My Files" from being parsed correctly. What am I missing? David From mathnoir at gmail.com Sun May 29 23:50:21 2005 From: mathnoir at gmail.com (spinach) Date: 29 May 2005 20:50:21 -0700 Subject: use of AttributesNSImpl in writing ? Message-ID: <1117425021.642639.308070@g47g2000cwa.googlegroups.com> I just can't find a good example for the use of AttributesNSImpl in the context of writing XML through XMLGenerator. I need to generate XML that uses several namespaces. The documentation is brief ("understands attribute names as two-tuples of namespaceURI and localname"), it appears you have to send it lots of dictionaries full of tuples. Any clarification on this would be most appreciated. From mikulik at physics.muni.cz Thu May 12 13:06:08 2005 From: mikulik at physics.muni.cz (Petr Mikulik) Date: Thu, 12 May 2005 19:06:08 +0200 (CEST) Subject: Python Graphing Utilities. In-Reply-To: References: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> <797fe3d405051010392c00011f@mail.gmail.com> <87psvycqej.fsf@wilson.rwth-aachen.de> <87mzr2f01r.fsf@wilson.rwth-aachen.de> <797fe3d4050511061258bb8302@mail.gmail.com> Message-ID: > A pslatex backend certainly would be interesting. A Gnuplot backend > would probably not be feasible. Does it expose its raw drawing operations? There is a patch [ 1027032 ] Connect gnuplot_x11 to exterior application window http://sourceforge.net/tracker/index.php?func=detail&aid=1027032&group_id=2055&atid=302055 which allows to "Connect gnuplot_x11 to exterior application window...". If you test it, please write a note there and the patch can go to cvs. --- PM From duncan.booth at invalid.invalid Fri May 27 04:24:17 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2005 08:24:17 GMT Subject: Case Sensitive, Multiline Comments References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> <8664x5y92g.fsf@guru.mired.org> <429654DA.9050903@lexicon.net> <1117154013.092736.298310@g14g2000cwa.googlegroups.com> Message-ID: Dennis Lee Bieber wrote: > On 26 May 2005 17:33:33 -0700, "Elliot Temple" > declaimed the following in comp.lang.python: > >> Thanks for the link on case sensitivity. I'm curious about the person >> who found case sensitivity useful though: what is it useful for? >> > Making a language run faster on slow machines since the syntax > parsing doesn't have to do the equivalent of upper or lower casing > anything that is not a string literal before checking for keywords or > identifiers. > > Consider the time spent by languages like Ada and Fortran when > they have to do case normalization every time you compile. > That isn't a good argument for case sensitivity. You really aren't going to be able to measure a slowdown in compilation speed just because the compiler has to lowercase all the identifiers before using them. What I consider good arguments for case sensitivity are: Consistency. I've used non-case sensitive languages where the same variable was spelled sometimes with capitals and sometimes without. Forcing you to choose one case and stick to it is, IMHO a good thing. Worse, I've used Visual Basic where the editor will gratuitously change the case of a variable you just typed in because there is another occurrence of the same name somewhere else in a different case. Conventions such as capitalising class names, or camelCasing can be useful. Again this only applies if they are used consistently. Interoperability. Like it or not, there are other case sensitive systems out there. I once had the misfortune to use a Microsoft Access database (where lookups on indexed fields are case insensitive) to store records indexed by a case sensitive medical coding system. Codes in that system do exist which differ from other completely unrelated conditions only by the case of the code. The only way to handle this in a case insensitive system is to somehow escape each case sensitive code. That particular example wouldn't necessarily apply to a case insensitive programming language, but plenty of others would: e.g. using a remote procedure call system to call a (case sensitive) function on another system. In all such cases, the case insensitive system is the 'poor relation', it is the one where you have to introduce workrounds in order to communicate with the case sensitive system. Going in the other direction (calling a case insensitive function from a case sensitive system) you simply have to invent a convention (e.g. lowercase everything) and stick by it. There are arguments that, especially for beginners, case sensitivity introduces an extra level of complexity, but the cost of losing this complexity would be to make Python a poor relation amongst programming languages. From pyguy2 at gmail.com Fri May 20 18:26:16 2005 From: pyguy2 at gmail.com (pyguy2 at gmail.com) Date: 20 May 2005 15:26:16 -0700 Subject: SSL (HTTPS) with 2.4 In-Reply-To: References: <1116392416.139727.84630@g49g2000cwa.googlegroups.com> <428AD4D1.8030405@v.loewis.de> <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> <1116524774.606167.98240@f14g2000cwb.googlegroups.com> <1116550788.207740.171780@o13g2000cwo.googlegroups.com> Message-ID: <1116627976.845517.268370@z14g2000cwz.googlegroups.com> The code I have wriitten that does auth ssl through a proxy with python _works_ with a proxy I tested with earlier. I finally got a squid proxy server running in which it does not work. As I get time, during the next few days, I am going to try to debug the difference and let you know what's up. And I agree, getting a fix included in the dist would be a good idea. john From max at alcyone.com Thu May 5 16:43:37 2005 From: max at alcyone.com (Erik Max Francis) Date: Thu, 05 May 2005 13:43:37 -0700 Subject: How to detect a double's significant digits In-Reply-To: References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: Jeremy Bowers wrote: > Step one for mrstephengross is to *rigorously* define what he means by > "significant digits", then go from there. Since I think he mentioned > something about predicting how much space it will take to print out, my > suggestion is to run through whatever printing routines there are and get > a string out, the measure the string, as anything else will likely be > wrong. If that's not possible with the formatting library, you've already > lost; you'll have to completely correctly re-implement the formatting > library, and not only is that a major PITA, you almost never get it > bug-for-bug right... Especially since all of his examples have the same number of significant digits (3), as the term is usually meant. Zeroes to the right are significant, not zeroes to the left. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis What is it that shapes a species? -- Louis Wu From teamuhlig at gmail.com Wed May 18 12:20:18 2005 From: teamuhlig at gmail.com (john67) Date: 18 May 2005 09:20:18 -0700 Subject: Is Python suitable for a huge, enterprise size app? In-Reply-To: <1116432325.497438.64580@g49g2000cwa.googlegroups.com> References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> Message-ID: <1116433218.495131.71260@g49g2000cwa.googlegroups.com> Would the allocation/deallocation memory usage issue be different than it would be with Java? Both Python and Java have automatic garbage collection, correct? Is Python's not as effective as Java's? I think the memory issues for the two languages would be similar in this area, but maybe I am wrong. John From flupke at nonexistingdomain.com Thu May 26 08:54:17 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 26 May 2005 12:54:17 GMT Subject: using timeit for a function in a class Message-ID: Hi, i tried to use timeit on a function in a class but it doesn't do what i think it should do ie. time :) In stead it starts printing line after line of hello time test! What am i doing wrong in order to time the f function? class TimeTest(object): def f(self): print "hello time test!" if __name__ == '__main__': from timeit import Timer s = """ test = TimeTest() test.f() """ t = Timer(s,"from __main__ import TimeTest") print t.timeit() Regards, Benedict Verheyen From steve at holdenweb.com Sun May 22 12:31:16 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 22 May 2005 12:31:16 -0400 Subject: SQL Query via python In-Reply-To: <200505202357.01579.jeffelkins@earthlink.net> References: <200505202357.01579.jeffelkins@earthlink.net> Message-ID: Jeff Elkins wrote: > I'm attempting to pass an SQL query via the console: > > $ ./getbd month 05 > > The arguments get seem to passed correctly (via print statements) and then: > > cursor.execute (""" > SELECT name, month, day ,category, city FROM bday > WHERE %s = %s > """,(arg1,arg2)) > > No results. However, if I hardcode the WHERE argument with a field name: > > cursor.execute (""" > SELECT name, month, day ,category, city FROM bday > WHERE month = %s > """,(arg2)) > > It works. > Because here you aren't trying to parameterize the name of a database object. > How can I code the left side of the WHERE clause so I can pass an arbitrary > field name to search on? > > You might have to construct the SQL statement to include the names of tables and columns. It's still better to use parameterization for data substitutions, though, because then you don't have to perform any quoting. -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From foundsabin at gmail.com Tue May 31 06:10:05 2005 From: foundsabin at gmail.com (A.K.Sabin) Date: 31 May 2005 03:10:05 -0700 Subject: :: winreg :: Message-ID: <1117534205.676233.143670@g47g2000cwa.googlegroups.com> Hi Evrbdy, I do struggle with Registry Keys. ( _winreg ) I am able to Create Keys inside HKEY_LOCAL_MACHINE, =_winreg.HKEY_LOCAL_MACHINE/ IE EXTENSION is MY AIM SOFTWARE/Microsoft/Internet Explorer/Extensions I cant assign the values to CLSID, HOT ICON, EXEC, Default Visible. Please Help me out. Sabin From sarapythonlist at yahoo.com Sat May 7 11:55:35 2005 From: sarapythonlist at yahoo.com (Sara Khalatbari) Date: Sat, 7 May 2005 08:55:35 -0700 (PDT) Subject: Shell Commands in Python Code Message-ID: <20050507155535.34927.qmail@web61110.mail.yahoo.com> There are a lot of commands that I need to use in my code & I don't know how to do it Is there a way to use shell commands in Python code? __________________________________ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail From http Wed May 18 16:13:36 2005 From: http (Paul Rubin) Date: 18 May 2005 13:13:36 -0700 Subject: SSL (HTTPS) with 2.4 References: <1116392416.139727.84630@g49g2000cwa.googlegroups.com> <428AD4D1.8030405@v.loewis.de> <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> Message-ID: <7x8y2c70nj.fsf@ruckus.brouhaha.com> Trent Mick writes: > Unfortunately ActivePython cannot include the SSL library by default > because of crypto export regulations. That hasn't been true for several years. In principle you're supposed to notify the commerce department but in fact they seem to just ignore the notices: http://www.bxa.doc.gov/Encryption Mozilla, MSIE, Windows, etc. all come with crypto by default. If you want SSL in pure Python, try . It's a really nice piece of code, though (so far) not what I'd call full featured. From erinhouston at gmail.com Thu May 26 10:18:09 2005 From: erinhouston at gmail.com (erinhouston at gmail.com) Date: 26 May 2005 07:18:09 -0700 Subject: Automatically populate and submit HTML Forms In-Reply-To: <1117071785.193503.41620@g49g2000cwa.googlegroups.com> References: <1117071785.193503.41620@g49g2000cwa.googlegroups.com> Message-ID: <1117117089.498759.196990@o13g2000cwo.googlegroups.com> These two blog entries might be of help to you. http://www.ishpeck.net/index.php?P=b1115239318ishpeck second half is at http://www.ishpeck.net/index.php?P=b1115225809ishpeck alex23 wrote: > Hey rbt, > > You should take a look at mechanize: > http://wwwsearch.sourceforge.net/mechanize/ > > One of its listed features is 'Easy HTML form filling, using ClientForm > interface'. > > A more recent option which came up on this group a few days ago is > twill: http://www.idyll.org/~t/www-tools/twill.html > > twill combines pyparsing & mechanize to provide a way of scripting > tests for web applications. While it might not offer the functionality > you're after (I haven't had call to use either of these), it looks very > accessible, and could provide some good examples for using mechanize > with your own scripts. > > -alex23 From grante at visi.com Tue May 10 19:57:31 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 10 May 2005 23:57:31 -0000 Subject: Python Graphing Utilities. References: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> <11823g4ph2kkp8b@corp.supernews.com> Message-ID: <1182ijbequ9bu0e@corp.supernews.com> On 2005-05-10, Kenneth Miller wrote: > Ahh Thanks for the quick replies. I'm having a look through > them now. What would you consider the best for real time > applications? That depends on how fast "real time" is. I use gnuplot-py for 1 Hz update rates with no issues. 2Hz worked OK but much faster than that probably isn't the best application for gnuplot. > The idea here is to stream in the results from an A/D > converter onto a 2d chart. -- Grant Edwards grante Yow! Why is everything at made of Lycra Spandex? visi.com From grante at visi.com Thu May 5 22:46:12 2005 From: grante at visi.com (Grant Edwards) Date: Fri, 06 May 2005 02:46:12 -0000 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> <1115316826.659271.247350@o13g2000cwo.googlegroups.com> <1115320481.000911.111220@z14g2000cwz.googlegroups.com> Message-ID: <117lmjkthk1qa24@corp.supernews.com> On 2005-05-05, mrstephengross wrote: >>This doesn't look like Python to me. Are you sure you're on the right > newsgroup? > > Er, ok, I'm an idiot. This was all supposed to be on > comp.lang.c++, but obviously I posted on the wrong one. Sorry > for all the hassle. In python, this stuff is a heck of a lot > easier. No, it isn't. The question is equally meaningless in any language. -- Grant Edwards grante Yow! WHO sees a BEACH at BUNNY sobbing on a SHAG visi.com RUG?! From list.repository at gmail.com Wed May 25 17:21:04 2005 From: list.repository at gmail.com (list.repository at gmail.com) Date: 25 May 2005 14:21:04 -0700 Subject: py2exe problems with win32com [ EnsureDispatch('ADODB.Connection') ] Message-ID: <1117056064.693253.74330@z14g2000cwz.googlegroups.com> Problem: Works fine when running python test.py but fails when executing test.exe. test.py: conn = win32com.client.gencache.EnsureDispatch('ADODB.Connection') conn.Open("Provider='SQLOLEDB';Data Source='.';Initial Catalog='mydatabase';User ID='user';Password='pwd';") . . . setup.py:(same KeyError) from distutils.core import setup import py2exe setup(console=['test.pyw'], options = { "py2exe": { "typelibs": [('{00000550-0000-0010-8000-00AA006D2EA4}', 0, 2, 8)] } } ) (Doesn't work since its not registered or need to get the setup.py: (same KeyError) from distutils.core import setup import py2exe setup(console=['test.pyw']) Generated error when running test.exe: Traceback (most recent call last): File "test.py", line 66, in ? File "test.py", line 57, in main File "test.py", line 16, in test_status File "win32com\client\gencache.pyc", line 540, in EnsureDispatch File "win32com\client\CLSIDToClass.pyc", line 50, in GetClass KeyError: '{00000550-0000-0010-8000-00AA006D2EA4}' Solution: Use a registered typelib that has ADODB.Connection functionality :) Any suggestions... From slick_mick_00 at hotmail.com Fri May 27 07:31:07 2005 From: slick_mick_00 at hotmail.com (Michael) Date: Fri, 27 May 2005 11:31:07 +0000 (UTC) Subject: Incrementing letters Message-ID: Hi, I've got a string s, and i want to shift all the letters up by one, eg a->b, b->c ........ z->a In c++ i can do this quite simply with if(C == 'z') C='a'; else C++; but i can't work out how to do this this in python?? Regards Michael From thesamet.nospam at pythonchallenge.com Sat May 21 07:58:08 2005 From: thesamet.nospam at pythonchallenge.com (thesamet) Date: Sat, 21 May 2005 14:58:08 +0300 Subject: Problem: embedding Python In-Reply-To: <1116675051.879539.116840@g43g2000cwa.googlegroups.com> References: <1116675051.879539.116840@g43g2000cwa.googlegroups.com> Message-ID: mmf wrote: > Hallo! > > I tried to use Python from C like it is described in the Python > Docmentation. So I wrote the following C source file: > > #include > int > main(int argc, char *argv[]) > { > Py_Initialize(); > PyRun_SimpleString("print 'Hallo World!'\n"); > Py_Finalize(); > return 0; > } > > I saved it as run.c and tried to compile it using the following > command: > gcc run.c > > But that always results in a list of errors: > > /tmp/cc1tmrPU.o(.text+0x1d): In function `main': > : undefined reference to `Py_Initialize' > /tmp/cc1tmrPU.o(.text+0x2a): In function `main': > : undefined reference to `PyRun_SimpleString' > /tmp/cc1tmrPU.o(.text+0x32): In function `main': > : undefined reference to `Py_Finalize' > > What am I doing wrong? Can you help me? > > Tanks. > > Best regards, > Markus > You should link with Python's shared object (replace with your version of Python): gcc -o run run.c -I/usr/include/python2.4 -lpython2.4 -- Are you a riddle lover? Try http://www.pythonchallenge.com From miradan at sbcglobal.net Tue May 10 15:33:25 2005 From: miradan at sbcglobal.net (Miradan) Date: 10 May 2005 12:33:25 -0700 Subject: Python on Pocket PC (Strong Arm) In-Reply-To: References: Message-ID: <1115753604.974000.21350@f14g2000cwb.googlegroups.com> rbt wrote: > I'm about to test this out on a new Dell hand held. Anyone had luck with it? > > http://www.murkworks.com/Research/Python/PocketPCPython/Overview Works just fine for me. Running the Axim 600Mhz processor. From fredrik at pythonware.com Mon May 9 08:00:57 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 9 May 2005 14:00:57 +0200 Subject: New Python regex Doc References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com><1113856843.023012.165500@l41g2000cwc.googlegroups.com><1113908069.264676.207090@g14g2000cwa.googlegroups.com><1115328523.852744.110390@f14g2000cwb.googlegroups.com><1115423751.016177.250650@o13g2000cwo.googlegroups.com><1115444726.627426.172260@g14g2000cwa.googlegroups.com><1115508491.462229.294020@o13g2000cwo.googlegroups.com> <86hdhes988.fsf@guru.mired.org> Message-ID: Mike Meyer wrote: > After doing a google for "regular expression greedy", the second match > starts with the text: > > By default, pattern matching is greedy, which means that the matcher > returns the longest match possible. > > Now, it can be argued that the term ought not to be used, except that > it's a standard term with a well-known meaning, and exactly describes > the behavior in question. fwiw, judging from frequently asked questions and bug reports, people have no problems understanding the phrase "greedy", but they sometimes have problems understanding why "return the longest match possible" doesn't always mean "return the overall longest match possible" (using the greedy modifier only applies to the given RE operator; it doesn't modify the behaviour of other operators, or the method used; e.g. | will still pick the *first* possible match even if one of the alternatives use a greedy operator, search/find still scans the target string from left to right, etc). From philippe at philippecmartin.com Sat May 28 14:57:19 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 28 May 2005 18:57:19 GMT Subject: Trying to understand pickle.loads withou class declaration References: <3L2me.3465$3D6.2238@newssvr12.news.prodigy.com> Message-ID: I confirm that all I have to do in order to successfully load a pickled object of class A is to declare class A: def __init__(self): pass Although the object has tons of fields Quid ? Regards, Philippe Philippe C. Martin wrote: > Hi, > > Shuffling files around in my project, I notice I broke everything when I > stopped declaring classes in a program that "pickled.loaded" existing > pickled object of type "classes". > > The error message being that the class(es) was unknown. > > However, I _think_, I did manage to do the following in the past: > > 1) pickle.dump class "test" with field "A" intialized in declaration > 2) pickle.load class "test" and add field "B" then pickle.dumps it > 3) pickl.load class "test" with no problem although field "B" was not > initialized in that declaration. > > > I have two questions: > > 1) Why cannot the interpreter accept to load an object which class is not > defined ? > 2) assuming the above (.... I _think_ ....) is true, why then is there not > problem in loading an object which changes dynamically. > > Hope I'm making sense. > > Any clue ? > > Thanks, > > Philippe From sateeshkavuri at yahoo.com Mon May 23 07:14:25 2005 From: sateeshkavuri at yahoo.com (Sateesh) Date: Mon, 23 May 2005 11:14:25 GMT Subject: Access lotus notes using Python Message-ID: Hi, Is it possible to access Lotus notes using Python? Can anyone provide me some pointers? Thanks Sateesh From spamtome at ewetel.net Tue May 17 06:01:57 2005 From: spamtome at ewetel.net (Jacob van Iwaarden) Date: Tue, 17 May 2005 12:01:57 +0200 Subject: Help wanted Message-ID: Hello NG, I'm a 59 year old Networker who was pushed to go to school for 2 years. I think I did it fine 'till now. But now I have to make a small project in Python with Y-Pages and Snakeletts. My Problem is that Python is like Arabian to me, and I have Time till Sunday. My Question: is here anyone who is willing to help me by PM on this projekt? The teacher told us it will be approx. 50 Lines of Code. I have to make a Webapplication wich will take Number and Title and number of minutes of CD's. It should be done with strings, no saving into an SQL-Database or so. I have to add , edit, search and show and delete Items. Thanks in advance Jacob From Serge.Orlov at gmail.com Tue May 17 03:25:01 2005 From: Serge.Orlov at gmail.com (Serge.Orlov at gmail.com) Date: 17 May 2005 00:25:01 -0700 Subject: python 2.3.4, cx_Oracle 4.1 and utf-8 - trouble In-Reply-To: References: Message-ID: <1116314701.643291.103240@f14g2000cwb.googlegroups.com> Maxim Kuleshov wrote: > Hello! > > Trying to fetch long varchar2 column and get the following error: > > cx_Oracle.DatabaseError: column at array pos 0 fetched with error: 1406 > > i.e. string buffer is not much enough to fetch the string. > > # fragment of code... > myCon = cx_Oracle.connect(user, psw, dsn) > myCur = myCon.cursor() > myCur.execute(""" > select COLUMN from TABLE where ID=1 > """) > for record in myCur.fetchall(): > # ... > > Error is reproduced only if actual string value longer than half of > declared column size. For short strings all is ok. > > If I print myCur.description, I get: > > [('COLUMN', , 250, 250, 0, 0, 1)] > > 250 - declared column max size, but I guess cx_Oracle allocates only 250 > bytes(!), so if my string longer than 125 chars (utf-8 national char > occupies > 1 byte) - I get the error. > > Is it bug or what? Any suggestions? Googling for "varchar2 utf-8" suggests that it's an Oracle's feature (or issue). varchar2 is allocated in bytes. Finding out the largest number of bytes per character is left as an exercise :) Sergey. From fredrik at pythonware.com Fri May 6 18:36:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 7 May 2005 00:36:14 +0200 Subject: hard memory limits References: <86vf5w5tkz.fsf@guru.mired.org><200505061052.28325.jstroud@mbi.ucla.edu> <86hdhg5cc1.fsf@guru.mired.org> Message-ID: Mike Meyer wrote: > > So why would Apple insist on setting unusably low process limits, when > > the others don't? > > You're making an unwarranted assumption here - that the OP wasn't > creating a large process of some kind. You need a special license to create large processes on a Mac? I clicked on the google link that Bill posted, and noted that it wasn't exactly something that only affected a single Python user. If some- thing causes problems for many different applications that run fine on other Unix systems, it's pretty obvious that the default OS X con- figuration isn't quite as Unixy as one would expect. > FWIW, OS X has a Mach kernel. The failing vm_malloc call listed in the > OP is a Mach call, not a Unix call. So has tru64. I've done some serious Python stuff on that platform (stuff that included some really large processes ;-), and I never had any allocation problems. But of course, that system was designed by DEC people... From kraus at hagen-partner.de Fri May 27 10:10:32 2005 From: kraus at hagen-partner.de (Wolfram Kraus) Date: Fri, 27 May 2005 16:10:32 +0200 Subject: Incrementing letters In-Reply-To: References: Message-ID: Duncan Booth wrote: > Michael wrote: > > >>Hi, >>I've got a string s, and i want to shift all the letters up by one, eg >>a->b, b->c ........ z->a >>In c++ i can do this quite simply with >> >>if(C == 'z') C='a'; >>else C++; >> >>but i can't work out how to do this this in python?? > > >>>>import string >>>>upone = string.maketrans( > > 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', > 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA') > >>>>string.translate("I've got a string s....", upone) > > "J'wf hpu b tusjoh t...." > > > Note the difference though: the Python code does what you said you wanted, > whereas your sample code corrupts punctuation. Wow, that's quite nice. You really learn something new every day :-) A minor improvement: Use string.ascii_letters as the first parameter for string.maketrans Wolfram From dh47302 at yahoo.com Tue May 10 18:17:00 2005 From: dh47302 at yahoo.com (Klaus Alexander Seistrup) Date: Tue, 10 May 2005 22:17:00 +0000 (UTC) Subject: A Faster Way... References: Message-ID: andrea.gavana at agip.it wrote: > If I simplify the problem, suppose I have 2 lists like: > > a = range(10) > b = range(20,30) > > What I would like to have, is a "union" of the 2 list in a > single tuple. In other words (Python words...): > > c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, ..... If the order is unimportant you could use: #v+ >>> tuple(set(range(10)) | set(range(20,30))) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29) >>> #v- Cheers, -- Klaus Alexander Seistrup Magnetic Ink, Copenhagen, Denmark http://magnetic-ink.dk/ From jstroud at mbi.ucla.edu Tue May 31 17:16:02 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Tue, 31 May 2005 14:16:02 -0700 Subject: running tkinter In-Reply-To: References: Message-ID: <200505311416.02051.jstroud@mbi.ucla.edu> On Tuesday 31 May 2005 01:44 pm, Jim Anderson wrote: > Are tcl/tk still supposed to be an intergrated part of the > python release? > > Do I have to download, configure, make, install tcl and tk > packages to get tkinter running? I had to do this. Don't forget blt. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From peter at engcorp.com Sun May 15 09:20:44 2005 From: peter at engcorp.com (Peter Hansen) Date: Sun, 15 May 2005 09:20:44 -0400 Subject: Range function In-Reply-To: <1116150732.766217.258960@g47g2000cwa.googlegroups.com> References: <1115951576.138445.51080@z14g2000cwz.googlegroups.com> <1116150732.766217.258960@g47g2000cwa.googlegroups.com> Message-ID: Xah Lee wrote: > Here's the Python solution. > # implementation note: When iStep is a decimal, rounding error > # accumulates. For example, the last item returned from > # Range(0,18,0.3) is 17.7 not 18. A remedy is to turn iStep into a > # fraction and do exact arithmetics, and possibly convert the result > # back to decimal. A lesser workaround is to split the interval as to > # do multiple smaller range and join them together. Good lord no! The correct way is to use an integer count and simply multiply it each time by the step, and add that to the range. No accumulation of errors then. Where did you learn to program? (Rhetorical question of course, as you haven't, yet.) > def Range(iMin, iMax=None, iStep=None): > if (iMax==None and iStep==None): > return Range(1,iMin) > if iStep==None: > return Range(iMin,iMax,1) > if iMin <= iMax and iStep > 0: > if (isinstance(iStep,int) or isinstance(iStep,long)): > return range( iMix, iMax, iStep) > else: > result=[];temp=iStep > while iMin <= iMax: > result.append(iMin) > iMin += iStep > return result That's some of the worst Python code I've seen recently. Please, no one take this as representative of how decent Python programmers write code. -Peter From gh at ghaering.de Tue May 17 17:05:16 2005 From: gh at ghaering.de (=?ISO-8859-1?Q?Gerhard_H=E4ring?=) Date: Tue, 17 May 2005 23:05:16 +0200 Subject: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied. In-Reply-To: References: Message-ID: <428A5C8C.3020404@ghaering.de> F. GEIGER wrote: > Arrgh, sorry for that post! > > self._dbc.execute(q, data) > > where data is None, works with MySQL. For SQLite I have to write > > if data is not None: > self._dbc.execute(q, data) > else: > self._dbc.execute(q) No, you have to write: self._dbc.execute(q, (data,)) in both drivers. i. e. the second parameter to execute *must* be a sequence. Some drivers (maybe MySQLdb, too) automatically correct the wrong call and transform a: execute(sql, single_param) into a execute(sql, (single_param,)) for you if they notice that "!PySequence_Check(single_param)". pysqlite 2 does not do this. HTH, -- Gerhard From jstroud at mbi.ucla.edu Sun May 8 19:29:03 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 8 May 2005 16:29:03 -0700 Subject: __brace__ (PEP?) Message-ID: <200505081629.03520.jstroud@mbi.ucla.edu> Hello All, If "__call__" allows anobject() and "__getitem__" allows anobject[arange], why not have "__brace__" (or some other, better name) for anobject{something}. Such braces might be useful for cross-sectioning nested data structures: anary = [[1,2,3],[4,5,6]] anary{2} ==> [3,6] or for a list of dictionaries: alod = [{"bob":1,"ted":2,"carol":3},{"bob":4,"ted":5,"carol":6}] alod{"ted"} ==> [2,5] or, heck, a dictionary of lists: adol = {"bob":[1,2,3],"carol":[4,5,6],"alice":[7,8,9]} adol{1} ==> {"bob":2, "carol":5, "alice":8} Though I positively can not see what is wrong with this suggestion, I am sure this will raise more than a few objections. Please bash my naivete publicly on the list. Some preemptive observations 1. on syntactic ambiguity (i.e. "braces already used") [] ==> used for both list and getitem (both for dict AND list) () ==> used for tuple, callable, grouping 2. on functional ambiguity (i.e. "function not implicit"): Q. What exactly does it mean to call an instance of class MyClass? A. Whatever the author of MyClass wanted it to mean. etc. Also, if this exists already, I apologize because I have not seen it in any Python code before and I wouldn't know what to call it for googling. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From bbcofchina at yahoo.com.cn Sun May 22 23:15:06 2005 From: bbcofchina at yahoo.com.cn (=?gb2312?q?<=CE=AB=B7=BB=B7=E7=F3=DD>?=) Date: Mon, 23 May 2005 11:15:06 +0800 (CST) Subject: Number 1 can't use! In-Reply-To: Message-ID: <20050523031506.1766.qmail@web15004.mail.cnb.yahoo.com> After I installed python 2.4.1 , I found my keyborad Number 1 can't work,but ! is still working --------------------------------- Do You Yahoo!? 150??MP3???????????? ??????????????????? 1G??1000??????????? -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Thu May 26 17:24:39 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 26 May 2005 16:24:39 -0500 Subject: Case Sensitive, Multiline Comments References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> Message-ID: <8664x5y92g.fsf@guru.mired.org> "Elliot Temple" writes: > Hi I have two questions. Could someone explain to me why Python is > case sensitive? I find that annoying. Because it comes from a language background of case sensitive languages (C, shell, etc.). But read what the BDFL has to say about it: Personally, I think anyone who has two variables whose names differ only in case should be shot. No, let me extend that - anyone who has two variables whose names would be pronounced the same should be shot. I've had to debug such code, and it ain't fun. Variables whose name differs from the class they are instance of only in case is the only allowable exception. And should be used with care. On the same note, anyone who spells a variable name with different cases because the languge is case-insensitive should be shot. I want to be able to use various source analysis tools without having to worry about dealing with two different ascii strings being names for a single variable. Add those two together, and you'll see that *I don't care*. I consider taking advantage of a language being case-sensitive or case-insensitive to be a bad idea, so it doesn't matter what the language does. > Also, why aren't there > multiline comments? Would adding them cause a problem of some sort? Because no one every really asked for them. After all, there are two formats for multi-line strings, which the interpreter will build and then discard. There are tools that recognize multi-line strings after function/method definitions and treat them as function documentation. Adding multiline comments probably wouldn't be a problem - you'd just have to come up with an introductory character sequence that can't occur in the language (not that that stopped C). But you'd have to get someone to write the code, then someone with commit privs to decide it was useful enough to commit. That seems to be a lot of work for very little gain. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From fredrik at pythonware.com Thu May 12 13:35:02 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 May 2005 19:35:02 +0200 Subject: How "return" no return ? References: <3ehaurF34ak0U1@individual.net> <3ehc5tF35eo3U1@individual.net> Message-ID: "Ximo" wrote: > I am doing a interpret of lines and it show me a prompt, and I want if I > write a declaration as "int a" my progrtam return de prompt and nothing > more, for exemple: > > >>> 2+2 > 4 > >>> int a > >>> > > Then I'm finding that de function which execute "int a" return me nothing, > and no > > >>> int a > None > >>> what Python version are you using? here's what a normal Python interpreter is supposed to do with your example: >>> 2+2 4 >>> int a File "", line 1 int a ^ SyntaxError: invalid syntax >>> From donn at drizzle.com Sat May 21 01:23:03 2005 From: donn at drizzle.com (Donn Cave) Date: Sat, 21 May 2005 05:23:03 -0000 Subject: Running a python program during idle time only References: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> <86y8a9xj8x.fsf@guru.mired.org> Message-ID: <1116652981.803852@yasure> Quoth Mike Meyer : | "los" writes: | > I'm trying to create a program similar to that of Google's desktop that | > will crawl through the hard drive and index files. I have written the | > program and as of now I just put the thread to sleep for 1 second after | > indexing a couple of files. | > | > I'm wondering if anyone knows of a way that I could make so that the | > program will run at full speed only runs after the computer has been | > idle for a while. I've looked at the "nice" command but that's not | > exactly what I want. | | On Unix, nice is exactly the answer. It's a lot more fine-grained than | what you're talking about, though. But it's the way things like | setiathome manage to run continuously without interfering with normal | usage. Well, he could certainly try it if he hasn't already, but I wouldn't be too surprised if it really isn't exactly what he wants. Maybe it depends on the scheduler, and maybe things have gotten a lot better in that department, but from my experience a process can be niced pretty hard and still tie up a lot of resources. A disk crawler sounds like a good example. I don't have any brilliant ideas, though. Your suggestion to use os.getloadavg sounds good to me. It might be kind of neat if there were some kind of APM ioctl that would register the calling process for notification of pending disk spin down, low power mode etc. Donn From steven.bethard at gmail.com Wed May 11 16:54:41 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 11 May 2005 14:54:41 -0600 Subject: Python Documentation (should be better?) In-Reply-To: References: <1115839271.271071.32710@z14g2000cwz.googlegroups.com> <1115841659.470657.33320@o13g2000cwo.googlegroups.com> Message-ID: Christopher J. Bottaro wrote: > Contrast that with Python. First off there is no "search" mechanism built > into the documentation page (yes I know you can google it, but that just > doesn't feel right). Um, are you looking at the current documentation page? http://docs.python.org/ In the upper right hand corner, I see a box entitled "Search:" and a button that says "submit". STeVe From rbt at athop1.ath.vt.edu Mon May 16 10:04:23 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Mon, 16 May 2005 10:04:23 -0400 Subject: Newbie : checking semantics In-Reply-To: References: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> <87d5rrsh7h.fsf@snobis.de> Message-ID: Andrew Dalke wrote: > Stefan Nobis wrote: > >>The other point is a missing (optional) statement to end blocks >>(so you optional don't have to mark block via whitespace). IMHO >>this comes very handy in some cases (like mixing Python and HTML >>like in PSP). From my experience i also would say beginners have >>quite some problems with only whitespace marking blocks (but it >>also has some benefits). > > > When you say "beginners" is that people with no previous > programming experience or those who have done C/Java/etc. language > which uses {}s? > > > Andrew > dalke at dalkescientific.com > True beginners (no programming experience whatsoever) don't have to deal with unlearning stuff such as the bracket plague. So, I'd say that he's talking about beginners who have used other languages and who have grown accustomed to the bracket plague. From superprad at gmail.com Tue May 31 20:58:55 2005 From: superprad at gmail.com (superprad at gmail.com) Date: 31 May 2005 17:58:55 -0700 Subject: Swig compile errors In-Reply-To: <429d0347$1@news.eftel.com> References: <1117583720.968040.230380@g47g2000cwa.googlegroups.com> <429d0347$1@news.eftel.com> Message-ID: <1117587535.783292.325540@g47g2000cwa.googlegroups.com> Nop No luck. That dint work. From pdemb at gazeta.pl Wed May 18 07:42:13 2005 From: pdemb at gazeta.pl (Peter Dembinski) Date: Wed, 18 May 2005 13:42:13 +0200 Subject: speeding up Python script References: <3evgolF56gtkU3@individual.net> Message-ID: <87acms69re.fsf@hector.domek> "Luis P. Mendes" writes: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi, > > I have a 1000 line python script that takes many hours to finish. > It is running with six inside 'for' loops. > > I've searched the net for ways to speed up the proccess. > > Psyco improves performance around 3% in this case which is not good > enough. > > How can I dramatically improve speed? You are looking for better algorithm, not for Python optimisations. -- http://www.peter.dembinski.prv.pl From steven.bethard at gmail.com Wed May 25 16:11:42 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Wed, 25 May 2005 14:11:42 -0600 Subject: regexp for sequence of quoted strings In-Reply-To: <1117050058.836444.189460@o13g2000cwo.googlegroups.com> References: <1117050058.836444.189460@o13g2000cwo.googlegroups.com> Message-ID: gry at ll.mit.edu wrote: > I have a string like: > {'the','dog\'s','bite'} > or maybe: > {'the'} > or sometimes: > {} > [snip] > > I want to end up with a python array of strings like: > > ['the', "dog's", 'bite'] > > Any simple clear way of parsing this in python would be > great; I just assume that "re" is the appropriate technique. > Performance is not an issue. py> s = "{'the','dog\'s','bite'}" py> s "{'the','dog's','bite'}" py> s[1:-1] "'the','dog's','bite'" py> s[1:-1].split(',') ["'the'", "'dog's'", "'bite'"] py> [item[1:-1] for item in s[1:-1].split(',')] ['the', "dog's", 'bite'] py> s = "{'the'}" py> [item[1:-1] for item in s[1:-1].split(',')] ['the'] py> s = "{}" py> [item[1:-1] for item in s[1:-1].split(',')] [''] Not sure what you want in the last case, but if you want an empty list, you can probably add a simple if-statement to check if s[1:-1] is non-empty. HTH, STeVe From li.qj at 126.com Mon May 30 03:37:37 2005 From: li.qj at 126.com (jerky) Date: Mon, 30 May 2005 15:37:37 +0800 Subject: where can i find pylibpcap module for win32? Message-ID: thanks for your any imformation. From kent37 at tds.net Mon May 30 10:43:18 2005 From: kent37 at tds.net (Kent Johnson) Date: Mon, 30 May 2005 10:43:18 -0400 Subject: Is pyunit still usable? In-Reply-To: References: Message-ID: <429b2663$1_1@newspeer2.tds.net> could ildg wrote: > I want to know something about unittest these days, > and since I'm learning python, I want to touch it through > python. But when I found the newest pyunit is even so > old, I wonder if it is still usable for current python version > 2.4. Will you please tell me? Thank you. unittest is a standard Python module since Python 2.1. It is a version of PyUnit. > What are the advantages and disadvantages of unittest? > Can somebody give me a detailed listing? Of unittest the module or unit testing the practice? If you mean the module, you might be interested in these articles comparing unittest, py.test and doctest: http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-1-unittest.html http://agiletesting.blogspot.com/2005/01/python-unit-testing-part-2-doctest.html http://agiletesting.blogspot.com/2005_01_01_agiletesting_archive.html If you mean the practice, Google is your friend. Countless books and articles have been written about unit testing. Kent From steve at holdenweb.com Fri May 27 13:21:45 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 May 2005 13:21:45 -0400 Subject: python24.zip In-Reply-To: References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> <428F8901.5000300@jessikat.fsnet.co.uk> Message-ID: Dieter Maurer wrote: > Steve Holden writes on Sun, 22 May 2005 16:19:10 -0400: > >>... >>Indeed I have written PEP 302-based code to import from a relational >>database, but I still don't believe there's any satisfactory way to >>have [such a hooked import mechanism] be a first-class component of an >>architecture that specifically requires an os.py to exist in the file >>store during initialization. >> >> >>I wasn't asking for an import hook mechanism (since I already knew >>these to exist), but for a way to allow such mechanisms to be the sole >>import support for certain implementations. > > > We do not have "os.py" (directly) on the file system. > It lives (like everything else) in a zip archive. > > This works because the "zipimporter" is put on > "sys.path_hook" before the interpreter starts executing Python code. > > Thus, all you have to do: use a different Python startup > and ensure that you special importer (able to import e.g. "os") > is already set up, before you start executing Python code. > It might help others like me if you were to document this setup, as I was unable to persuade the interpreter to start without producing the dire-sounding warning messages I mentioned in the bug report. regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From steve at holdenweb.com Tue May 3 00:56:00 2005 From: steve at holdenweb.com (Steve Holden) Date: Tue, 03 May 2005 00:56:00 -0400 Subject: lists in cx_Oracle In-Reply-To: References: <1115047620.602263.180780@o13g2000cwo.googlegroups.com> <1115056746.166202.97140@f14g2000cwb.googlegroups.com> Message-ID: <42770460.80008@holdenweb.com> Andrew Dalke wrote: > infidel wrote: > >>I think perhaps you are asking for something that the OCI doesn't >>provide. > > > But it doesn't need to be supported by the OCI. > > >>And really, it all boils down to the list comprehension: >> >>in_clause = ', '.join([':id%d' % x for x in xrange(len(ids))]) > > > And why can't the equivalent to that be supported in the > DB-API interface, so I can pass in a list/tuple and have > it just work? > > >>... elegance is certainly subjective, and the above statement isn't the >>cleanest ever, but it solves your main problem while avoiding the other >>problem you mentiong (sql injection). Seems "elegant enough" to me. > > > The problem I mentioned is supporting inexperienced developers > (scientists writing software without local programming support) > who, in my experience, don't know about this pitfall and are > more likely to use a close but wrong solution than this correct > one. repr(ids) is after all much easier to write. > Andrew: I cannot help but agree that a more sympathetic treatment of the various sequence types would help tyros and pros alike. Do you think this is a DB-API 3-ish kind of a thing, or would it layer over DB-API 2 in a relatively platform-independent manner? I suspect that some of the code has to be inside the driver (and hence possibly at least partly written in C) to hook into platform-dependent features like quoting string literals. but-you-may-know-better-ly y'rs - steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From franz2 at llnl.gov Thu May 12 20:10:02 2005 From: franz2 at llnl.gov (Al Franz) Date: Thu, 12 May 2005 17:10:02 -0700 Subject: suspected cPickle memory leak Message-ID: <6.1.2.0.2.20050512170807.02550a60@mail.llnl.gov> I believe there is a memory leak in cPickle. I am using python2.2. I have a parallel code which uses array() and indices() from Numeric to massage data buffers before being sent and received by Pypar. Pypar subsequently uses cPickle to pickle the data. After many hours of execution, my code crashes with one of the following error messages (depending upon the run): a = zeros(shape, typecode, savespace) MemoryError: can't allocate memory for array or: s = dumps(x, 1) MemoryError: out of memory I have since modified my code to use a different data format so cPickle is no longer used from PyPar and now the code runs fine. -- Al Franz Computer Scientist Lawrence Livermore National Laboratory From cs_girl14 at hotmail.com Sat May 7 10:27:55 2005 From: cs_girl14 at hotmail.com (Lily Kakm) Date: Sat, 07 May 2005 14:27:55 +0000 Subject: Ask for a tools to protect my .pyc file :) Message-ID: I am sorry, may be I have not explain my mind clearly. But I just want a tool like this : It can change the variable name into meaningless ones. I know it will not be safe enough, but I need one. So I ask for help. Thank you !! Robert Kern wrote: >Lily Kakm wrote: >>when I distribute my software, I will give the users .pyc file (maybe I >>can use py2exe, but I think there's no essential different), because I >>don't like them to know my source code. >> >>But actually, through .pyc file is not so directly as .py file, but the >>user can also easily guest the detail of the program. Because in the .pyc >>file, the name of the variables are exist. >> >>I ask you for a tool. Maybe it can hide the name of the variables. That's not going to provide you any security. Any competent attacker won't care what you name the variables. If you want real security, don't distribute your code. Expose the critical parts as a web service (or similar) instead. If you want pretend security, .pycs or py2exe executables are enough. >For example: > >good_node = 100 >bad_node = 500 - good_node > >Using this tool, it can be like this : > >xxxxxxxxxx = 100 >xxxxxxxxxy = 500 - xxxxxxxxxx > >It has the same function, but it can not easily be seen by the users. Reads just fine to me. >Do you know where to download a tool like this. You ask an open source software community for a free tool to keep your source proprietary? High expectations. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ From claudio.grondi at freenet.de Tue May 24 14:19:29 2005 From: claudio.grondi at freenet.de (Claudio Grondi) Date: Tue, 24 May 2005 18:19:29 -0000 Subject: searching substrings with interpositions References: <1116926253.186047.195260@g43g2000cwa.googlegroups.com> <3fgekjF7lq3qU1@individual.net> <1116939594.958040.14110@z14g2000cwz.googlegroups.com> Message-ID: <3fh2leF7mbtfU1@individual.net> schrieb im Newsbeitrag news:1116939594.958040.14110 at z14g2000cwz.googlegroups.com... > thanx everyone, is what i need. > As Claudio argues, it's a standard problem of dna sequences > comparation. > the next step of my job is to make limits of lenght of interposed > sequences (if someone can help me in this way i'll apreciate a lot) > thanx everyone. > giorgio > Note: code below is intended to help to clarify things only, so that a bunch of examples can be tested. If you need bugfree production quality code, maybe someone else can provide it. I have introduced two additional parameter to the function. If intMaxLenOfGap == 0 the gap size doesn't matter. lstStartEndOfRangeOfBwithOccurenceOfA returns in its 0,1 elements the begin and end of the range strA was found in strB. Hope this does what you mean with "make limits of lenght of interposed sequences", does it? Claudio P.S. Here the code: def blnFindCharSequenceAevenIfSpreadOverEntireStringB(strA, strB, intMaxLenOfGap = 0, lstStartEndOfRangeOfBwithOccurenceOfA = []): lstStartEndOfRangeOfBwithOccurenceOfA = [] intNoOfCharsFound = 0 intPtrToFirstCharFound = 0 intPtrToBeginOfSubsectionOfB = 0 intLenA = len(strA) intLenB = len(strB) blnStrAinB = False indxToA = 0 while(indxToA < intLenA): # print chrA if(indxToA == 0): blnFoundChrA = False for indxToB in range(intPtrToBeginOfSubsectionOfB, intLenB): if(strA[indxToA] == strB[indxToB]): intNoOfCharsFound += 1 # print " ",chrA, strB[indxToB], indxToB intPtrToFirstCharFound = indxToB intPtrToBeginOfSubsectionOfB = indxToB + 1 blnFoundChrA = True break #:if #:for if(intNoOfCharsFound == intLenA): blnStrAinB = True print "sequence '%s' found in '%s'"%(strA, strB) break #:if if(blnFoundChrA == False): break #:if indxToA += 1 else: intGapLen = 0 blnFoundChrA = False for indxToB in range(intPtrToBeginOfSubsectionOfB, intLenB): if(strA[indxToA] == strB[indxToB]): intNoOfCharsFound += 1 # print " ",chrA, strB[indxToB], indxToB intPtrToBeginOfSubsectionOfB = indxToB + 1 blnFoundChrA = True break #:if intGapLen += 1 if(intMaxLenOfGap > 0 and intGapLen > intMaxLenOfGap): indxToA = 0 blnFoundChrA = False intPtrToBeginOfSubsectionOfB = intPtrToFirstCharFound + 1 intNoOfCharsFound = 0 break #:if #:for if(intNoOfCharsFound == intLenA): blnStrAinB = True print "sequence '%s' found in '%s' at range(%i, %i)"%(strA, strB, intPtrToFirstCharFound, indxToB+1) lstStartEndOfRangeOfB.append(intPtrToFirstCharFound) lstStartEndOfRangeOfB.append(indxToB+1) break #:if if(blnFoundChrA == False): break #:if indxToA += 1 #:if/else #:while if blnStrAinB == False: if(intMaxLenOfGap > 0 and intGapLen > intMaxLenOfGap): print "sequence '%s' not in '%s' (maybe allowed gap of %i chars was too small?)"%(strA, strB, intMaxLenOfGap) else: print "sequence '%s' not in '%s'"%(strA, strB) #:if #:def print lstStartEndOfRangeOfB = [] strA = "0101" strB = "000011110100" blnFindCharSequenceAevenIfSpreadOverEntireStringB(strA, strB) lstStartEndOfRangeOfB = [] strA = "0101" strB = "000011110100" blnFindCharSequenceAevenIfSpreadOverEntireStringB(strA, strB, 2) strA = "010101" strB = "000011110100" blnFindCharSequenceAevenIfSpreadOverEntireStringB(strA, strB, 6, lstStartEndOfRangeOfB) strA = "010101" strB = "00001111010000001" blnFindCharSequenceAevenIfSpreadOverEntireStringB(strA, strB, 4, lstStartEndOfRangeOfB) strA = "010101" strB = "00001111010000001" blnFindCharSequenceAevenIfSpreadOverEntireStringB(strA, strB, 5, lstStartEndOfRangeOfB) print print "usage of lstStartEndOfRangeOfB parameter passed to function for use as return value:" print "sequence '%s' was found in '%s' at range(%i, %i)"%(strA, strB, lstStartEndOfRangeOfB[0], lstStartEndOfRangeOfB[1]) From martin at v.loewis.de Sun May 22 15:24:41 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sun, 22 May 2005 21:24:41 +0200 Subject: python24.zip In-Reply-To: References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> <428faddd$0$26322$9b622d9e@news.freenet.de> Message-ID: <4290dc79$0$9989$9b622d9e@news.freenet.de> Dieter Maurer wrote: > Really? > > Is the interpreter unable to call "C" functions ("stat" for example) > to determine whether an object exists before it puts it on "path". What do you mean, "unable to"? It just doesn't. Could it? Perhaps, if somebody wrote a patch. Would the patch be accepted? Perhaps, if it didn't break something else. In the past, there was a silent guarantee that you could add items to sys.path, and only later create the directories behind these items. I don't know whether people rely on this guarantee. > The application was Zope importing about 2.500 modules > from 2 zip files "zope.zip" and "python24.zip". > This resulted in about 12.500 opens -- about 4 times more > than would be expected -- about 10.000 of them failing opens. I see. Out of curiosity: how much startup time was saved when sys.path was explicitly stripped to only contain these two zip files? I would expect that importing 2500 modules takes *way* more time than doing 10.000 failed opens. Regards, Martin From dalke at dalkescientific.com Thu May 12 12:21:38 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Thu, 12 May 2005 16:21:38 GMT Subject: urllib download insanity References: Message-ID: Timothy Smith wrote: > ok what i am seeing is impossible. > i DELETED the file from my webserver, uploaded the new one. when my app > logs in it checks the file, if it's changed it downloads it. the > impossible part, is that on my pc is downloading the OLD file i've > deleted! if i download it via IE, i get the new file. SO, my only > conculsion is that urllib is caching it some where. BUT i'm already > calling urlcleanup(), so what else can i do? Here are some ideas to use in your hunt. - If you are getting a cached local file then the returned object will have a "name" attribute. result = urllib.retrieve(".....") print result.fp.name As far as I can tell, this will only occur if you use a tempcache or a file URL. - You can force some debugging of the open calls, to see if your program is dealing with a local file. >>> old_open = open >>> def my_open(*args): ... print "opening", args ... return old_open(*args) ... >>> open("/etc/passwd") >>> import __builtin__ >>> __builtin__.open = my_open >>> open("/etc/passwd") opening ('/etc/passwd',) >>> You'll may also need to change os.fdopen because that's used by retrieve if it needs a tempfile. If you want to see where the open is being called from, use one of the functions in the traceback module to print the stack trace. - for surety's sake, also do import webbrowser webbrowser.open(url) just before you do urllib.retrieve(url, filename) This will double check that your program is using the URL you expect it to use. - beyond that, check that you've got network activity, You could check the router lights, or use a web sniffer like ethereal, or set up a debugging proxy - check the headers. If your ISP is using a cache then it might insert a header into what it returns. But if it was caching then your IE view should have seen the cached version as well. Andrew dalke at dalkescientific.com From ionel.mc at gmail.com Sun May 22 13:18:45 2005 From: ionel.mc at gmail.com (ionel) Date: Sun, 22 May 2005 19:18:45 +0200 Subject: first release of PyPy In-Reply-To: <7x64xc10pl.fsf@ruckus.brouhaha.com> References: <7x64xc10pl.fsf@ruckus.brouhaha.com> Message-ID: this is interesting anyway i'm to lazy to read so i'll just ask: can PyPy at the current state of develepment help me improve my python programs? (speed) -- ionel. -------------- next part -------------- An HTML attachment was scrubbed... URL: From http Fri May 27 08:49:49 2005 From: http (Paul Rubin) Date: 27 May 2005 05:49:49 -0700 Subject: write to the same file from multiple processes at the same time? References: Message-ID: <7xwtpkrfyq.fsf@ruckus.brouhaha.com> gabor writes: > so, how does one synchronizes several processes in python? > > first idea was that the cgi will create a new temp file every time, > and at the end of the stress-test, i'll collect the content of all > those files. but that seems as a stupid way to do it :( There was a thread about this recently ("low-end persistence strategies") and for Unix the simplest answer seems to be the fcntl.flock function. For Windows I don't know the answer. Maybe os.open with O_EXCL works. From curi42 at gmail.com Thu May 26 02:14:19 2005 From: curi42 at gmail.com (curi42 at gmail.com) Date: 25 May 2005 23:14:19 -0700 Subject: Strange Execution Times Message-ID: <1117088059.588457.200270@z14g2000cwz.googlegroups.com> I am running two functions in a row that do the same thing. One runs in .14 seconds, the other 56. I'm confused. I wrote another version of the program and couldn't get the slow behavior again, only the fast. I'm not sure what is causing it. Can anyone figure it out? Here is my code (sorry it's a bit of a mess, but my cleaned up version isn't slow!). Just skim to the bottom where the timing is. The first time printed out is .14, the seond is 56.56. f = open("/Users/curi/data.xml") o = open("/Users/curi/out2.xml", "w") import md5 import array p1 = "" p2 = "" cnt = 0 m = md5.new jo = "".join adjust = len(p1) - 1 i = 1 s = f.read() a = array.array('c', s).tolist() spot = 0 k = 0 find = s.find starts = [] ends = [] while k != -1: #print len(s) k = find(p2, spot) if k != -1: starts.append(find(p1, spot) + adjust) ends.append(k) spot = k + 1 #s = "".join([s[:j+1], md5.new(s[j+1:k-1]).hexdigest(), s[k:]]) #if k != -1: a[j+1:k-1] = m(jo(a[j+1:k-1])).hexdigest() r = range(len(starts)) #r = range(20) r.reverse() import time data = a[:] md5 = m join = jo t1 = time.clock() for j in r: #print jo(s[starts[j]+1:ends[j]]) digest = m(jo(s[starts[j]+1:ends[j]])).hexdigest() a[starts[j]+1:ends[j]] = digest #cnt += 1 #if cnt % 100 == 0: print cnt t2 = time.clock() print "time is", round(t2-t1, 5) t1 = time.clock() for i in r: data[starts[i]:ends[i]] = md5(join(s[starts[i]:ends[i]])).hexdigest() t2 = time.clock() print "second time is", round(t2-t1, 5) o.write(jo(a)) From Tommy.Ryding at gmail.com Tue May 24 05:00:57 2005 From: Tommy.Ryding at gmail.com (Tommy.Ryding) Date: 24 May 2005 02:00:57 -0700 Subject: Static binding Message-ID: <1116925257.450758.206130@g47g2000cwa.googlegroups.com> Is it possible to use SWIG generated wrapper files when I want to statically bind my extentions? //Tommy From fredrik at pythonware.com Sun May 15 02:00:47 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 15 May 2005 08:00:47 +0200 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com><1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> Message-ID: M.E.Farmer wrote: > I said exactly what I meant, the parentheses around the values creates > a tuple that you have no reference to! repeating it doesn't make you right; no extra tuple is created, and the parens are part of the syntax: If the target is a target list enclosed in parentheses or in square brackets: The object must be a sequence with the same number of items as there are targets in the target list, and its items are assigned, from left to right, to the corresponding targets. http://docs.python.org/ref/assignment.html (originally, you had to use [] to unpack lists, and () or no parens only worked for tuples. the ability to use an arbitrary sequence was added in 1.5) on the other hand, the function you're calling in this example *does* create a tuple that you have no reference to after the assignment. that doesn't matter, of course, since the tuple is removed by the garbage collector immediately after it has been unpacked. From newsgroups at jhrothjr.com Sat May 21 08:46:37 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 21 May 2005 06:46:37 -0600 Subject: first release of PyPy References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com><1116644536.741250.249860@g44g2000cwa.googlegroups.com><1116653460.808204.74460@g43g2000cwa.googlegroups.com><87mzqpytep.fsf@wilson.rwth-aachen.de><7xfywhxerd.fsf@ruckus.brouhaha.com> <87is1dyru8.fsf@wilson.rwth-aachen.de> Message-ID: <118ubdg3lt2cjd0@news.supernews.com> "Torsten Bronger" wrote in message news:87is1dyru8.fsf at wilson.rwth-aachen.de... > Hall?chen! > > Paul Rubin writes: > >> Torsten Bronger writes: >> >>> Please could somebody explain to us non-CS people why PyPy could >>> have speed features CPython can't have? >> >> Does the one-word answer "compiler" explain enough? > > No, just more questions. ;-) > > What's supposed to be compiled? Only PyPy itself or also the > programs it's "interpreting"? To be more specific, the (possible) speed increase will come from JIT (Just In Time) compilation technology. JIT technology is quite capable of handling dynamic languages. That has to come after they get a compilable interpreter working, but I believe it was in the original project vision statement. A JIT compiler within the interpreter will put PyPy pretty much on a par with Java as far as speed goes. > : "In the next step > of the project, we will generate C code or machine code from the > source of Pypy, thereby reducing the speed penalty." > > I've been told by so many books and on-line material that Python > cannot be compiled (unless you cheat). So how is this possible? JIT compilers cheat. Specifically, they compile for the observed object environment of a statement, and then insert a test to make sure that the actual environment matches the expected environment. If it doesn't, it goes back to interpretation for that code segment. John Roth > > Tsch?, > Torsten. > > -- > Torsten Bronger, aquisgrana, europa vetus From fredrik at pythonware.com Tue May 24 16:38:05 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 24 May 2005 22:38:05 +0200 Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com><1116432325.497438.64580@g49g2000cwa.googlegroups.com><1116433218.495131.71260@g49g2000cwa.googlegroups.com><1116440427.255902.36260@g49g2000cwa.googlegroups.com> Message-ID: Dieter Maurer wrote: > Could you elaborate a bit? > > Large peak memory use means that the application got a large > address space. What garantees that the residual memory use > (after the peak) is compact and not evenly spread across > the address space. nothing guarantees that, of course. but I've never seen that happen. and I'm basing my comments on observed behaviour in real systems, not on theoretical worst-case scenarios. every time I've seen serious fragmentation, it's been related to leaks, not peak memory usage. From phark52 at yahoo.com Sun May 1 13:03:11 2005 From: phark52 at yahoo.com (fooooo) Date: 1 May 2005 10:03:11 -0700 Subject: Multiple threads in a GUI app (wxPython), communication between worker thread and app? Message-ID: <1114966991.337599.194500@f14g2000cwb.googlegroups.com> This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new thread is spawned (threading module) and this thread starts listening for data on a socket. When someone connects, a new thread is spawned, It needs to do I/O on that socket and open a GUI window so the user can communicate with the client (socket) that just connected. Any further data that comes in on that socket should be redirected to the newly opened GUI window. Any more connection attempts will open a new GUI window and the same cycle repeats. How would I get the worker thread to open a GUI window in the main GUI thread? After that GUI window is open, how can I send and recv messages from/to the GUI window? From steven.bethard at gmail.com Sat May 21 13:24:18 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sat, 21 May 2005 11:24:18 -0600 Subject: count files in a directory In-Reply-To: References: <200505202125.03838.jstroud@mbi.ucla.edu> Message-ID: <6sydnV96GrVZ8xLfRVn-tQ@comcast.com> rbt wrote: > Heiko Wundram wrote: >>>>> import os >>>>> path = "/home/heiko" >>>>> file_count = sum((len(f) for _, _, f in os.walk(path))) >>>>> file_count > > Thanks! that works great... is there any significance to the underscores > that you used? I've always used root, dirs, files when using os.walk() > do the underscores make it faster... or more efficient? No, they don't make any semantic difference; they work just like any other identifier. It's just that, by convention, single underscores indicate that we don't care what values these names are bound to. So in the example above, Heiko indicates that we don't care about what you would normally call 'root' and 'dirs'. HTH, STeVe From flamesrock at gmail.com Mon May 2 16:14:02 2005 From: flamesrock at gmail.com (flamesrock) Date: 2 May 2005 13:14:02 -0700 Subject: python+windows/linux -> write stdout text to always on top text? Message-ID: <1115064842.454916.305970@f14g2000cwb.googlegroups.com> Hi, I'm curious if theres a way in python to write stdout text to the screen (ie top right) the way they do in some FPS games, so that its always on top, in an invisible window of some set dimensions. No matter what program is on top. Is there a way to make it cross platform? I've looked but nothing seems to turn up on the subject. -thanks in advance. From flyaflya at gmail.com Tue May 10 06:02:28 2005 From: flyaflya at gmail.com (flyaflya) Date: Tue, 10 May 2005 18:02:28 +0800 Subject: why this happend using model random? Message-ID: from random import * col = [0 for i in range(10)] a = [col for i in range(10)] seed() for i in range(10): for j in range(10): a[i][j] = randint(0, 100) print a the result is: [[78, 65, 35, 5, 68, 60, 1, 51, 81, 70], [78, 65, 35, 5, 68, 60, 1, 51, 81, 70], [78, 65, 35, 5, 68, 60, 1, 51, 81, 70], .....] why result isn't true random? but when the code like this: from random import * seed() for i in range(10): for j in range(10): print randint(0, 100) the result is true random, what's deffient between these two segment codes? From nowhere at nothing.com Sat May 28 23:29:03 2005 From: nowhere at nothing.com (Lurker) Date: Sun, 29 May 2005 15:29:03 +1200 Subject: Intellisense and the psychology of typing References: <1117125072.825389.74190@g47g2000cwa.googlegroups.com> Message-ID: <0Fame.3732$U4.528498@news.xtra.co.nz> "James D Carroll" wrote in message news:Td2dndb_0ehebwrfRVn-oA at speakeasy.net... > if I have to type 'boolean' instead of 'boo' I get real cranky real fast. Why? Is your programming speed really limited by the difference between typing "lean" and hitting ? If typing speed is the limitation - go get some touch-typing courses. From doodle4 at gmail.com Thu May 19 16:02:20 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 19 May 2005 13:02:20 -0700 Subject: store mac address Message-ID: <1116532940.490324.122160@f14g2000cwb.googlegroups.com> Hello, I am trying to fill an array with source and destination mac address. The first 6 bytes hold the destination mac address and the next six bytes hold the source mac address. Here's a snippet for filling in broadcast address for the destination mac. # Get destination address data = array('B', '\0' * 512) for i in range(6): data[i] = 0xFF How do i fill in a command line passed mac address for both source and destination(default is FFFFFFFFFFFF). The first six bytes of data[i] should contain destination mac and the next six bytes of data[i] should contain the source mac address. Thanks, Ashton From bearophileHUGS at lycos.com Tue May 10 11:42:56 2005 From: bearophileHUGS at lycos.com (bearophileHUGS at lycos.com) Date: 10 May 2005 08:42:56 -0700 Subject: Merging overlapping spans/ranges In-Reply-To: <4280b31b$0$198$edfadb0f@dread12.news.tele.dk> References: <4280b31b$0$198$edfadb0f@dread12.news.tele.dk> Message-ID: <1115739776.439549.188010@o13g2000cwo.googlegroups.com> This is the problem of finding the connected components inside an interval graph. You can implement the algorithms yourself, of you can use my graph data structure here: http://sourceforge.net/projects/pynetwork/ The graph methods: createIntervalgGraph And: connectedComponents can probably solve your problem quite fast, algorithmically, and with few lines of code. If you need more help, then ask for it and I'll give the little code needed. Bear hugs, Bearophile From harlinseritt at yahoo.com Sun May 8 06:29:33 2005 From: harlinseritt at yahoo.com (Harlin Seritt) Date: 8 May 2005 03:29:33 -0700 Subject: Active Directory Modules? Message-ID: <1115548173.613128.33120@g14g2000cwa.googlegroups.com> Does anyone know if there are any Python Active Directory Modules out there? I looked at LDAP module but there is no version for Python 2.4 and it's support for Active Directory seems to be lacking a bit. Thanks, Harlin Seritt From vcsekhar007 at yahoo.com Sat May 7 02:39:57 2005 From: vcsekhar007 at yahoo.com (V.C.Sekhar) Date: Sat, 07 May 2005 06:39:57 -0000 Subject: Array programming Message-ID: Hi there, I couldnt get to do the following task using Python. Can some pls suggest me a way to do this. I have an array with duplicate strings filled in it. Now am looking for a way to extract only the DISTINCT Values from that array. Could some one pls help me out. Thanks in advance, Sekhar From fredrik at pythonware.com Tue May 17 10:42:38 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 17 May 2005 16:42:38 +0200 Subject: Image.putpalette(Colors)? References: Message-ID: Oliver Albrecht wrote: > Has somebody a example-script how i can put a other palette to a image? here's one of the first google hits for "PIL putpalette": http://effbot.org/zone/pil-pseudocolor.htm > (after this the image should have similar outlook) similar to what? From ccurvey at gmail.com Wed May 11 20:47:14 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 11 May 2005 17:47:14 -0700 Subject: win32com Dispatch() and SetPriorityClass() Message-ID: <1115858834.244312.130110@g43g2000cwa.googlegroups.com> if I'm using Dispatch() to manage a COM object (IE), is there a way to get ahold of the process handle so that I can bump it's priority? From rijishvr at rediffmail.com Mon May 2 03:45:00 2005 From: rijishvr at rediffmail.com (rijish valoorthodi rajan) Date: 2 May 2005 07:45:00 -0000 Subject: No subject Message-ID: <20050502074500.2455.qmail@webmail35.rediffmail.com> hello all I am a member of a team dedicated to make a client server database application and our main concern is the speed with which the system performs. we are very new to python. but after reading a lot of documents and consulting some experts we decided to work it out using PYTHON. we plan to make 2 programs one running in the client systems and one that run in server. can any one please help me by telling the thins that i should take care of while designing the project and what tools and what style we should adopt to make the program optimised. regards -------------- next part -------------- An HTML attachment was scrubbed... URL: From arserlom at gmail.com Sat May 14 09:41:34 2005 From: arserlom at gmail.com (arserlom at gmail.com) Date: 14 May 2005 06:41:34 -0700 Subject: A question about inheritance In-Reply-To: <2tudnU9xaaG2DePfRVn-1A@comcast.com> References: <1115579277.999256.269960@f14g2000cwb.googlegroups.com> <2tudnU9xaaG2DePfRVn-1A@comcast.com> Message-ID: <1116078094.565174.234940@z14g2000cwz.googlegroups.com> Ok, thanks. I didn't know about new-style classes (I had learned python from a book prior to them). After reading about new-style classes, I find that your solution is better because, using super (in general) avoids cl2 from having to know the implementation details of cl1. This is clearly explained in: http://www.python.org/2.2.3/descrintro.html#cooperation Also, when using new-style classes with IDLE, I found some problems which I talk about in "Modifying CallTips.py to work with with new-style classes in IDLE.", which I posted in this group. Steven Bethard wrote: > arserlom at gmail.com wrote: > > Hello I have a question about inheritance in Python. I'd like to do > > something like this: > > > > class cl1: > > def __init__(self): > > self.a = 1 > > > > class cl2(cl1): > > def __init__(self): > > self.b = 2 > > > > But in such a way that cl2 instances have atributes 'b' AND 'a'. > > Obviously, this is not the way of doing it, because the __init__ > > definition in cl2 overrides cl1's __init__. > > > > Is there a 'pythonic' way of achieving this? > > If there's a chance you might have multiple inheritance at some point in > this hierarchy, you might also try using super: > > class cl1(object): # note it's a new-style class > def __init__(self): > self.a = 1 > > class cl2(cl1): > def __init__(self): > super(cl2, self).__init__() > self.b = 2 > > Note that you probably want a new-style class even if you chose not to > use super in favor of Jp Calderone's suggestion. There are very few > cases for using old-style classes these days. > > STeVe From tonino.greco at gmail.com Tue May 17 10:22:35 2005 From: tonino.greco at gmail.com (Tonino) Date: 17 May 2005 07:22:35 -0700 Subject: best way to do this ... In-Reply-To: References: <1116332775.964419.168370@o13g2000cwo.googlegroups.com> Message-ID: <1116339755.240688.109380@g44g2000cwa.googlegroups.com> hmm - but I want to store the data in memory eather than a filesystem ... it is not an issue if the program terminates - it is almost needed while running and does not need to remember where it is .. the dirctionary is detail = {} will try the list() function - thanks Tonino From grante at visi.com Thu May 26 11:15:30 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 26 May 2005 15:15:30 -0000 Subject: Automatically populate and submit HTML Forms References: Message-ID: <119bq0i5r14li9d@corp.supernews.com> On 2005-05-25, rbt wrote: > How can I make a python client script connect to a Web server and > automatically populate form fields and then submit the form? > > For example, say I wanted to check and see if 1924 was a leap year... > how would I populate the 'year' field and then submit it for processing? > I have no control of the server... just the client script. > >

>

Enter a year and find out if it's a leap year: > > > >

Just use urllib() and pass the form data to the urlopen() method. If given data, it will generate a "POST" request instead of a "GET". Here's a snippet of code from an app of mine that "fills in a form" and submits it: postData = urllib.urlencode({'submit':'Remove','disp':'M','action':'change_Msgs'}) for msgid in msgIDs: postData += "&msgid="+msgid req2 = urllib2.Request("http://mc-s6.postini.com/exec/MsgCtr",postData) rsp2 = ClientCookie.urlopen(req2) In this code I've eyeballed the form and the field names are hard-wired into the code. If your form doesn't change from one usage to the next, that's the simplest way to do it. In my example I'm using ClientCookie and urllib2 to create/open the reqeust in two steps because the request seen above won't work without some cookie values previsouly established in code that I've snipped. Otherwise all you'd need to do is something like this: urllib.urlopen('http://whatever', urllib.urlencode({'field1Name':'value1','field2Name':'value2'})) -- Grant Edwards grante Yow! Yes, but will I at see the EASTER BUNNY in visi.com skintight leather at an IRON MAIDEN concert? From kay.schluehr at gmx.net Sat May 21 04:33:48 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 21 May 2005 01:33:48 -0700 Subject: first release of PyPy In-Reply-To: References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116644536.741250.249860@g44g2000cwa.googlegroups.com> <1116653460.808204.74460@g43g2000cwa.googlegroups.com> <87mzqpytep.fsf@wilson.rwth-aachen.de> Message-ID: <1116664428.505172.245270@g14g2000cwa.googlegroups.com> Shane Hathaway wrote: > Now people are experimenting with high level compilers written in high level > languages. Where will this pattern lead? Who knows. :-) Drift from old Europe ( greek Pythons ) to old India to "Nagas" and other snake-beings and goddesses :-) http://www.khandro.net/mysterious_naga.htm#many-headed Regards, Kay From phark52 at yahoo.com Mon May 2 22:26:48 2005 From: phark52 at yahoo.com (fooooo) Date: 2 May 2005 19:26:48 -0700 Subject: Multiple threads in a GUI app (wxPython), communication between worker thread and app? In-Reply-To: <1114986451.990217.148570@f14g2000cwb.googlegroups.com> References: <1114966991.337599.194500@f14g2000cwb.googlegroups.com> <1114986451.990217.148570@f14g2000cwb.googlegroups.com> Message-ID: <1115087208.889987.195470@o13g2000cwo.googlegroups.com> Thanks for the replies. I have a Queue object in the main GUI thread, this gets passed to all the worker threads and they add items to it. This is all well and good, but what is a good way to get the GUI thread to send items back to the worker threads? From edvard+news at majakari.net Mon May 16 03:14:13 2005 From: edvard+news at majakari.net (Edvard Majakari) Date: Mon, 16 May 2005 10:14:13 +0300 Subject: Safe eval, or how to get list from string References: <1115999726.286709.140690@f14g2000cwb.googlegroups.com> Message-ID: <87mzqvd4my.fsf@titan.staselog.com> bwooster47 at gmail.com writes: > I've to use ConfigParser. > > It returns values that are exactly in the config file, so get string > variables like: > int1 with quotes and characers: "42" > this is easy to convert to int: > realint = int(int1) There's already a method getint() for that, you can just say cfgparser.getint('section', 'int1') > if there is list1 = "[ 'filea', 'fileb', ]", I can get at list by > doing: > reallist = eval(list1) Are you sure you need to use ConfigParser for that? If you need to have persistent Python data structures, I'd suggest marshalling data and using (c)Pickle or similar. -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli Deo Gloria! "Debugging is twice as hard as writing the code in the firstplace. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian W. Kernighan From dreamingpython at 163.com Thu May 19 22:04:39 2005 From: dreamingpython at 163.com (ÒÊÃÉɽÈË) Date: Fri, 20 May 2005 10:04:39 +0800 Subject: how to config a comserver in a customize dll? Message-ID: When i use the below code to create a comserver on Windows OS??i find that the com was configed in the file python23com.dll,why? if i want to config it in my customize dll,how should i do? thks class TestPythonCom: _public_methods_ = [ 'SplitString' ] _reg_progid_ = "TestPythonCom.Application" # NEVER copy the following ID # Use "print pythoncom.CreateGuid()" to make a new one. _reg_clsid_ = "{93D78ABA-1F6C-4B1C-97C7-C3700511415A}" def SplitString(self, val): return val From tlviewerSHRUB at yahooCHENEY.com Thu May 5 23:30:47 2005 From: tlviewerSHRUB at yahooCHENEY.com (tlviewer) Date: Fri, 06 May 2005 03:30:47 GMT Subject: win32: structured storage Message-ID: hello, In honor of the chm exploit that I got hit by last week, I trying to code some ActivePython to list the directory inside a CHM. CHM is supposed to be structured storage (ITSF). If a given CHM file is infected it most likely has an embedded EXE file -- mine had one called [Open.exe]. The following code works for Excell sheets, XLS, but fails for CHM files. # begin python from win32com import storagecon as sc import os, win32api import pythoncom as pyc from pywintypes import IID its_clsid = IID('{5d02926a-212e-11d0-9df9-00a0c922e6ec}') its_iid= IID('{88cc31de-27ab-11d0-9df9-00a0c922e6ec}') # pyc.CoInitialize() # commented out after failing on my Win2k box #pyc.CoCreateInstance( its_clsid,None,pyc.CLSCTX_INPROC_SERVER, its_iid) m = sc.STGM_READ | sc.STGM_SHARE_EXCLUSIVE # quarantined CHM virus fname = "e:/batch/junkx.chm" #fname = "C:/Documents and Settings/Administrator/My Documents/02_taxes.xls" pss = pyc.StgOpenStorageEx( fname, m, sc.STGFMT_STORAGE,0, pyc.IID_IStorage) ele = pss.EnumElements( 0, None,0) obj = ele.next() print obj[0] obj = ele.next() print obj[0] # end python with the XLS file, I get the names of the two sheets. Is there another way to parse the central directory out of a CHM file? tia, tlviewer From timothy at open-networks.net Fri May 6 19:02:42 2005 From: timothy at open-networks.net (Timothy Smith) Date: Sat, 07 May 2005 09:02:42 +1000 Subject: py2exe + svn - the final drama In-Reply-To: References: <427AD7E8.1060500@open-networks.net> Message-ID: <427BF792.1020500@open-networks.net> Just wrote: >In article , > David Bolen wrote: > > > >>Are you perhaps trying to update the zip file in-place while it is still >>being used by the application? I'm not sure that's a safe operation. >> >> > >I'm sure it's not :) > >[lots of useful help snipped] > >the zipimport module has an attr called _zip_directory_cache, which is a >dict you can .clear(). Still, reloading modules is hairy at best, its >probably easiest to relaunch your app when the .zip file has changed. > >Just > > what i do is as soon as the update is complete i close the app, but it still gives the error, i tried clear() after update and before it, it still got the same error. it's be nice to not have to fiddle around with the zip file, i really think making py2exe create a dir instead of a zip will be much better here what i do anyway if (os.name == 'nt') or (os.name == 'win32'): client = pysvn.Client() #get current revision number CurrentRev = client.info('').revision.number Check = client.update('') sys.path_importer_cache.clear() if Check.number > CurrentRev: self.Popup('Update installed, click ok and restart ','Update installed') self.Destroy() else: InfoMsg.Update(3,'No Updates needed') From flamesrock at gmail.com Mon May 16 23:14:43 2005 From: flamesrock at gmail.com (flamesrock) Date: 16 May 2005 20:14:43 -0700 Subject: Python on a public library computer In-Reply-To: References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> Message-ID: <1116299683.490847.294300@g43g2000cwa.googlegroups.com> Panix.com seems a little on the expensive side.. 10$/mo? Roy Smith wrote: > Timothy Smith wrote: > > there's a few (brave) public access unix shell providers out there. if > > you could run telnet you could use them > > If you want to go that route, I highly suggest panix.com. They've been in > business forever, are geek friendly, and have a technical support staff > (and attitude) that just can't be beat. I get a unix shell account from > them, mostly for mail and news access (but, on occasion, it's nice to have > a unix box I can ssh into from anywhere). > > They're currently running Python-2.4. A couple of the active pythonistas > that hang out here have panix accounts. From peter at engcorp.com Mon May 23 15:09:56 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 23 May 2005 15:09:56 -0400 Subject: Terminating a thread from the parent In-Reply-To: <1116869282.045234.239040@g14g2000cwa.googlegroups.com> References: <1116869282.045234.239040@g14g2000cwa.googlegroups.com> Message-ID: DE wrote: > I have an app with embedded Python. Python scripts create their own > threads and I need to terminate these threads at the point where the > user wants to leave the application. I use threading.Thread as base > classes. > > I have tried to use call the join method of the python thread objects > from C++. But although the call succeeds, the threads don't exit. join() waits until the thread terminates, but it doesn't cause it to terminate. > What is the proper way of doing this ? (e.g. how does the python shell > do this ? ) You have to poll for a termination request in the thread's main loop, and have the thread terminate itself (by returning from the target function or from the run() method, depending on which technique you used to create the Thread in the first place). Threads cannot be forcibly terminated**. There are numerous examples of this in the archives and probably a Cookbook recipe or two about it, if you look. Otherwise someone can post an example here. -Peter ** The exception is Threads on which .setDaemon(True) has been called, which will terminate immediately when the main thread exits (i.e. when the entire process terminates), though that might not be helpful to you in your particular situation. From mwm at mired.org Tue May 10 20:39:45 2005 From: mwm at mired.org (Mike Meyer) Date: Tue, 10 May 2005 19:39:45 -0500 Subject: Need a little parse help References: <1115756261.255249.299870@f14g2000cwb.googlegroups.com> <1115767302.830054.143810@f14g2000cwb.googlegroups.com> Message-ID: <86br7imw8e.fsf@guru.mired.org> "Michael Hartl" writes: > I'd also like to note that both the inputfiles variable and the > readlines() method are superfluous; to iterate through the file line by > line, use either > > for line in open(inputfilename): > # do something with line > > or (my personal preference, since I like to think of the file as a > thing rather than an action) > > for line in file(inputfilename): > # do something with line I'd like to note that failing to close the file explicitly is a bad habit. You really should invoke the close method, rather than relying on the garbage collector to close them for you. This means you do need a variable to hold the file object. 99% of the time nothing bad will happen if you skip this, but that 1% can always come back to byte you in the *ss. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From cfajohnson at gmail.com Sun May 29 01:36:09 2005 From: cfajohnson at gmail.com (Chris F.A. Johnson) Date: Sun, 29 May 2005 01:36:09 -0400 Subject: How do i read just the last line of a text file? References: <1117341766.166081.132240@o13g2000cwo.googlegroups.com> Message-ID: <9v0om2-5fl.ln1@rogers.com> On Sun, 29 May 2005 at 04:42 GMT, nephish wrote: > Hey there. > i want to set a variable to represent the last line of a text file > how do i do that? > or even better, how do i create a list of the lines of a text file? from sys import argv ## Import argv from sys module file = open(argv[1]) ## Open the file given on the command line all_lines = file.readlines() ## Read all the lines last_line = all_lines[-1] ## Assign the last line -- Chris F.A. Johnson ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress From rkern at ucsd.edu Wed May 11 23:51:15 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 11 May 2005 20:51:15 -0700 Subject: Python Documentation (should be better?) In-Reply-To: <4282D0C5.3A8B3786@pauahtun.org> References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> <428276e8$0$318$626a14ce@news.free.fr> <4282A5DF.44C84B18@pauahtun.org> <4282D0C5.3A8B3786@pauahtun.org> Message-ID: Ivan Van Laningham wrote: > Hi All-- > > Robert Kern wrote: > >>Ivan Van Laningham wrote: >> >> >>>http://www.python.org/doc/ >>> >> >>Searching on docs.python.org goes through just the stuff that's on >>docs.python.org, which is pretty much just documentation. Google's magic >>points to the current documentation. >> >>Searching on www.python.org trolls through the entire www.python.org >>site. The search box doesn't narrow its scope just because you happen to >>be in the Documentation section currently. It doesn't get the current >>documentation because Google's magic gets a bit confused. > > I get that. My question, cleverly concealed in a rant, was, "Why does > clicking on the Documentation link at python.org NOT take me to > docs.python.org?" Why is there a difference? If there must be a > difference, why isn't the difference labelled as such? This is a > difference that makes a difference. I believe that docs.python.org was added mostly to aid Google searches. I *do* think that the Documentation link should go to docs.python.org. I believe there is a mailing list somewhere that discusses improvements to the website. Ah: http://mail.python.org/mailman/listinfo/pydotorg/ -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From Sebastien.Boisgerault at gmail.com Wed May 11 16:33:20 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 11 May 2005 13:33:20 -0700 Subject: optparse In-Reply-To: References: <1115841250.764632.296820@g47g2000cwa.googlegroups.com> Message-ID: <1115843600.174250.16770@f14g2000cwb.googlegroups.com> Steven Bethard wrote: > S?bastien Boisg?rault wrote: > > Any idea why the 'options' object in > > > > # optparse stuff > > (options, args) = parser.parse_args() > > > > is not/couldn't be a real dict ? Or why at least it > > does not support dict's usual methods ? > > Well, it's not a real dict because the original API intends it to be > used as object attributes. Sure ;). But what are the pros of this choice ? The option __str__ mimicks the behavior of a dict. Why not a full interface support of it ? > However, if you need a dict, it's pretty > simple -- use vars() or .__dict__: Agreed. 100%. SB From nyamatongwe+thunder at gmail.com Wed May 18 19:33:58 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Wed, 18 May 2005 23:33:58 GMT Subject: Is Python suitable for a huge, enterprise size app? In-Reply-To: <1116440427.255902.36260@g49g2000cwa.googlegroups.com> References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116440427.255902.36260@g49g2000cwa.googlegroups.com> Message-ID: Steve M: > ... discusses the problem with memory allocation in CPython. > Apparently CPython is not good at, or incapable of, releasing > memory back to the operating system. I'm fairly sure Java does not give memory back to the operating system either. A quick search did not give a definitive answer but there were complaints from people about not being able to do this. Neil From sjmachin at lexicon.net Tue May 10 16:55:19 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 11 May 2005 06:55:19 +1000 Subject: Trouble saving unicode text to file References: <1115500976.571232.76100@z14g2000cwz.googlegroups.com> Message-ID: On Tue, 10 May 2005 07:59:31 +0000 (UTC), Thomas Bellman wrote: >John Machin writes: > >> Which raises a question: who or what is going to read your file? If a >> Unicode-aware application, and never a human, you might like to >> consider encoding the text as utf-16. > >Why would one want to use an encoding that is neither semi-compatible >with ASCII (the way UTF-8 is), nor uses fixed-with characters (like >UTF-32 does)? UTF-32 is yet another encoding. You still need to decode it into the internal form supported by your processing software. With UTF-32xE, you can only skip the decoding step when file's x == software's x and your software uses 32 bits internally. Python (2.4.1) doesn't have a utf_32 codec. Perhaps that's because there isn't much call for it (yet). Let's pretend there is such a codec in Python. Once you have done codecs.open('inputfile', 'rb', 'utf_32') or receivedstring.decode('utf_32'), what do you care whether your *external representation* has fixed-width characters or not? Putting it another way, any advantage of fixed-width characters is to be found in *internal* storage, not *external* transmission or storage. At the other end, if you don't have to squeeze your data through an 8-bit-wide non-binary channel, and you have no need for legibility to humans, then the remaining considerations are efficiency and (if you have no control over what's used at the other end) whether the necessary codec is widely implemented. So rather than utf-16, perhaps I should have written something like: """ Consider utf-8 or utf-16. Consider following this by compression using a widely-implemented protocol (gzip/zip/bzip2). """ Cheers, John From mhartl at post.harvard.edu Tue May 10 19:21:42 2005 From: mhartl at post.harvard.edu (Michael Hartl) Date: 10 May 2005 16:21:42 -0700 Subject: Need a little parse help References: <1115756261.255249.299870@f14g2000cwb.googlegroups.com> Message-ID: <1115767302.830054.143810@f14g2000cwb.googlegroups.com> I'd also like to note that both the inputfiles variable and the readlines() method are superfluous; to iterate through the file line by line, use either for line in open(inputfilename): # do something with line or (my personal preference, since I like to think of the file as a thing rather than an action) for line in file(inputfilename): # do something with line (Note also that the 'r' argument to open/file is the default and so can be omitted.) Michael -- Michael D. Hartl, Ph.D. CTO, Quark Sports LLC http://quarksports.com/ From scharan20 at gmail.com Thu May 26 11:01:34 2005 From: scharan20 at gmail.com (Sri Charan) Date: 26 May 2005 08:01:34 -0700 Subject: __init__() not called automatically In-Reply-To: References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> Message-ID: <1117119694.090630.62360@z14g2000cwz.googlegroups.com> The compiler also calls the default arguement constructor automatically, if such a constructor is provided for the base class(es); but, this becomes a special case of what has been said by Andrew Koenig. So, it is NOT just the no arguement constructor that is automatically called; note that the default arguement constructor is kinda put in place because sometimes, the user may call the constructor with no arguements, while the object actually needs some values for proper construction. From usenet at gungfu.de Mon May 2 11:53:18 2005 From: usenet at gungfu.de (=?iso-8859-1?q?Steffen_Gl=FCckselig?=) Date: 2 May 2005 08:53:18 -0700 Subject: Which IDE is recommended? References: <426f90ac$1_2@rain.i-cable.com> <1114608598.571508.6570@z14g2000cwz.googlegroups.com> <1114611543.156341.198870@o13g2000cwo.googlegroups.com> Message-ID: <1115049198.620989.203450@g14g2000cwa.googlegroups.com> > I'm a fan of PSPad. It's free, light weight, and works with > everything. I want to second that. For small scripts PSPad is definitely very useful and comfortable. For larger scripts I'd consider something with code-completion. Maybe PyDev. best regards Steffen From mefjr75 at hotmail.com Mon May 2 00:39:19 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 1 May 2005 21:39:19 -0700 Subject: Webbrowser On Windows In-Reply-To: References: Message-ID: <1115008759.797584.24510@f14g2000cwb.googlegroups.com> Awesome! works perfectly on win2k -> I.E 6 Python makes COM almost readable ;) M.E.Farmer From martin at v.loewis.de Wed May 18 16:12:00 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 18 May 2005 22:12:00 +0200 Subject: NaN support etc. In-Reply-To: References: Message-ID: <428ba190$0$7687$9b622d9e@news.freenet.de> Andreas Beyer wrote: > How do I find out if NaN, infinity and alike is supported on the current > python platform? To rephrase Sebastian's (correct) answer: by 1. studying the documentation of the CPU vendor 2. studying the documentation of the compiler vendor, and performing extensive tests on how the compiler deals with IEEE-754 3. studying the documentation of the system's C library, reading its source code (if available), and performing extensive tests of the IEEE-754 support in the C libray 4. studying Python's source code (you can spare yourself reading documentation because there is none) > Is there an 'official' handle for obtaining this information? No. > Similar: How do I get the maximum/minimum double for current machine? By experimentation, and/or reading vendor documentation. Regards, Martin From exarkun at divmod.com Fri May 27 15:46:21 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 27 May 2005 19:46:21 GMT Subject: [Twisted-Python] xmlrpc deferred In-Reply-To: <652481677.20050527222806@bounce-software.com> Message-ID: <20050527194621.559.2069217516.divmod.quotient.11292@ohm> On Fri, 27 May 2005 22:28:06 +0300, Catalin Constantin wrote: >Hi there, > >I have the following xmlrpc method: > >class FeederResource(xmlrpc.XMLRPC): > def __init__(self): > xmlrpc.XMLRPC.__init__(self) > self.feeder=Feeder() > > def xmlrpc_getList(self, id): > return self.feeder.get_urls(id) > >The thing is that the self.feeder.get_urls takes too long to execute >and while the request is running all the others are blocked. >I want that while it computes the result the other XML RPC methods to >be available. The only answer here is to make get_urls() take less time. What is it doing? Is it blocking on network I/O? Querying a database? Prompting for user input? _It_ should be creating and returned a Deferred (and later calling it back with a result), most likely, since it is the long-running operation. > >I wanted to use deferrals but i found no viable example. > >Eg what i've tried to do: > def xmlrpc_getList(self, id): > log.debug("getList is here for id %s" % id) > d = defer.Deferred() > d.addCallback(self.feeder.get_urls) > return d Deferred don't make things asynchronous, cooperative, or non-blocking. They only make dealing with callbacks more convenient. If you add a blocking function as the callback to a Deferred, it will block the reactor just as effectively as if you called it yourself (bacause all that happens inside the Deferred is that the function gets called). > >My method feeder.get_urls is never called ! > In the above code, nothing ever "fires" the Deferred - calls .callback() on it - so, never having a result, it never bothers to invoke any of its callbacks. Deferred just hook results up to callbacks. Jp From http Mon May 2 11:07:13 2005 From: http (Paul Rubin) Date: 02 May 2005 08:07:13 -0700 Subject: How to kill a SocketServer? References: <7xwtqj1lh1.fsf@ruckus.brouhaha.com> <7xpswa4wfu.fsf@ruckus.brouhaha.com> <17013.25972.965219.254879@montanaro.dyndns.org> <7xekcq75av.fsf@ruckus.brouhaha.com> <1115046280.413931.16970@g14g2000cwa.googlegroups.com> Message-ID: <7xu0llhdjy.fsf@ruckus.brouhaha.com> "guido at python.org" writes: > > Ah, good point. Something like this should probably be added to > > SocketServer.py (optional timeout parameter to serve_forever), or at > > least the trick should be mentioned in the docs. > > I like this idea, and perhaps you all could come up with some more > useful APIs in this area; I know that I often struggle a bit with > getting these servers to stop. I put an RFE in sourceforge last night, suggesting adding a shutdown() method to socket servers. From vincent at visualtrans.de Sun May 22 07:03:00 2005 From: vincent at visualtrans.de (vincent wehren) Date: Sun, 22 May 2005 13:03:00 +0200 Subject: install python 2.4.1 References: <1116758705.327764.33740@g14g2000cwa.googlegroups.com> Message-ID: schrieb im Newsbeitrag news:1116758705.327764.33740 at g14g2000cwa.googlegroups.com... | hi, | | I use python 2.4 and | I would like to install python 2.4.1. Is it necessary to uninstall the | first version or just install 2.4.1? What platform? If you're on Windows and are using the msi-Installer, uninstalling is recommended. It will also work without uninstalling, but IIRC, Windows Installer will zealously inspect the file version of each individual file down the Python24 tree to detect necessary disk space and so forth, which can take quite some time. | | Does it effect pydef (eclipse editor) or komodo ide ? Don't know.. -- Vincent Wehren | | | pujo | From rbt at athop1.ath.vt.edu Fri May 20 23:05:09 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Fri, 20 May 2005 23:05:09 -0400 Subject: count files in a directory In-Reply-To: References: Message-ID: James Stroud wrote: > Come to think of it > > file_count = len(os.walk(valid_path)[2]) I get this traceback: PythonWin 2.4 (#60, Nov 30 2004, 09:34:21) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond at skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. Traceback (most recent call last): File "C:\Program Files\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Documents and Settings\rbt\Desktop\newa\replicate.py", line 57, in ? A = count_em(X) File "C:\Documents and Settings\rbt\Desktop\newa\replicate.py", line 51, in count_em count = len(os.walk(valid_path)[2]) TypeError: unsubscriptable object From rkern at ucsd.edu Mon May 30 14:53:49 2005 From: rkern at ucsd.edu (Robert Kern) Date: Mon, 30 May 2005 11:53:49 -0700 Subject: decimal numarray In-Reply-To: <20050602072124.GA28107@mrna.tn.nic.in> References: <20050602072124.GA28107@mrna.tn.nic.in> Message-ID: km wrote: > Hi all, > is there any support for decimal type in numarray module ? Not specifically, no. However, there is the concept of an "object array," which are arrays of arbitrary Python objects. See numarray.objects . -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From scharan20 at gmail.com Thu May 26 11:02:46 2005 From: scharan20 at gmail.com (Sri Charan) Date: 26 May 2005 08:02:46 -0700 Subject: __init__() not called automatically In-Reply-To: References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> <1117095907.393269.87540@g44g2000cwa.googlegroups.com> Message-ID: <1117119766.252990.120850@g49g2000cwa.googlegroups.com> I guess you are right. From sjmachin at lexicon.net Mon May 16 19:01:03 2005 From: sjmachin at lexicon.net (John Machin) Date: Tue, 17 May 2005 09:01:03 +1000 Subject: Parsing text into dates? References: <1116277171.492587.38080@g47g2000cwa.googlegroups.com> Message-ID: <317i815ifjtpn3screkeuv4jfk33uu41ck@4ax.com> On 16 May 2005 13:59:31 -0700, "Thomas W" wrote: >I'm developing a web-application where the user sometimes has to enter >dates in plain text, allthough a format may be provided to give clues. >On the server side this piece of text has to be parsed into a datetime >python-object. Does anybody have any pointers on this? > >Besides the actual parsing, my main concern is the different locale >date formats and how to be able to parse those strange us-like >"month/day/year" compared to the clever and intuitive european-style >"day/month/year" etc. Well I'm from a locale that uses the dd/mm/yyyy style and I think it's only marginally less stupid than the mm/dd/yyyy style. How much intuition is required to determine in an international context what was meant by 01/12/2004? First of December or 12th of January? The consequences of misinterpretation can be enormous. If this application is being deployed from a central server where the users can be worldwide, you have two options: (a) try to work out somehow what the user's locale is, and then work with dates in the legacy format "appropriate" to the locale. (b) Use the considerably-less-stupid ISO 8601 standard format yyyy-mm-dd (e.g. 2004-12-01) -- throughout your web-application, not just in your data entry. Having said all of that, [bottom-up question] how are you handling locale differences in language, script, currency symbol, decimal "point", thousands separator, postal address formats, surname / given-name order, etc etc etc? [top-down question] What *is* your target audience? From onurb at xiludom.gro Wed May 4 04:35:30 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 04 May 2005 10:35:30 +0200 Subject: PHPParser pod Zope In-Reply-To: References: <4277d8ea$0$18802$636a15ce@news.free.fr> <1115181234.612599.83930@g14g2000cwa.googlegroups.com> Message-ID: <42788954$0$316$636a15ce@news.free.fr> Josef Meile wrote: (snip) > > I don't find this two replies funy :-(. I think it is impolite to make > fun of the OP. My intent was not to make fun *of* the OP. Now I'm willing to admit that my answer may not be as (kindly) funny as intended, and so I hope the OP has a better sens of humor than you and me !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From rschroev_nospam_ml at fastmail.fm Mon May 2 11:47:56 2005 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Mon, 02 May 2005 15:47:56 GMT Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: <1114828856.889984.171750@g14g2000cwa.googlegroups.com> <1115036638.557573.153250@z14g2000cwz.googlegroups.com> Message-ID: John Hazen wrote: > * mstarzyk at gmail.com [2005-05-02 05:10]: > >>Any hints on level 6 ? >>There is "zip" in the page source, "ZIp" in the >>image data, but have no clue what to do with them >>- tried many things :). > > > Have you found the zip file yet? > > (I did, and I still can't figure it out. I'm wondering if there are > comments embedded in the jpg that none of my viewers will show me. > Hmm, maybe there's a python module that does that... I'll play with it > more after I sleep on it.) > > -John Possible spoiler, so ROT13'ed: Qvq lbh frr naq ernq gur ernqzr.gkg va gur mvc svyr? -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven From nico at bidon.fr Wed May 18 13:49:46 2005 From: nico at bidon.fr (Nicolas Pourcelot) Date: Wed, 18 May 2005 19:49:46 +0200 Subject: wxpython and wxtextctrl Message-ID: <428b8033$0$1342$626a14ce@news.free.fr> Hello, my script worked well until today : when I tried to launch it, I got the following : frame = MyFrame(None,-1,"Geometrie",size=wx.Size(600,400)) File "/home/nico/Desktop/wxGeometrie/version 0.73/geometrie.py", line 74, in __init__ self.commande.Bind(wx.EVT_CHAR, self.EvtChar) AttributeError: wxTextCtrl instance has no attribute 'Bind' (self.commande is a wxTextCtrl instance) I don't understand : why did wxTextCtrl lost its Bind attribute ?? As there's not so much changes on my computer since yesterday, I suppose this is due to Boa package installation on my Ubuntu Hoary ? Does Boa installation changes wxpython version ? Is wxTextCtrl attribute .Bind() obsolete ?? Thanks, Nicolas From kenchanningphd at gmail.com Tue May 17 18:25:54 2005 From: kenchanningphd at gmail.com (kenchanningphd at gmail.com) Date: 17 May 2005 15:25:54 -0700 Subject: win32com interface implementation example Message-ID: <1116368754.643802.115010@g44g2000cwa.googlegroups.com> Can someone post or point me to a fairly simple example where a COM interface (other than the standard ones already exposed by the win32com library) is implemented in python. I fear I am doing it incorrectly. Here is my example: Suppose there is a COM interface "FOO" loaded in the windows registry that has one method: add Also suppose that COM object BAR has a method that expects a COM object that implements FOO ----------------------------------- import pythoncom guid = pythoncom.CreateGuid() class MyImplementation: _public_methods_ = ["add"] _reg_clsid_ = guid _reg_progid_ = "MyImplementation" _com_interfaces_ = [IID('{ID OF THE FOO INTERFACE}')] def add(self,a,b): print a + b import win32com win32com.server.register.UseCommandLine(MyImplementation) MI = win32com.Dispatch("MyImplementation") bar = win32com.Dispatch("BAR") bar.somemethod(MI) -------------------------------- Am I forgetting something here? From martin.witte at gmail.com Mon May 30 09:19:02 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 30 May 2005 06:19:02 -0700 Subject: Newbie learning OOP 2nd ? References: <1117456531.293218.134650@g44g2000cwa.googlegroups.com> Message-ID: <1117459142.635799.100520@g47g2000cwa.googlegroups.com> I would split your code such that the Q&A is seperated from the calculations, and I would model the bill something like : class allbills(object): def __init__(self, bill, tip): self._bill = bill self._tip = tip def gettip(self): return self._tip / 100.0 tip = property(gettip) def gettotal(self): return self._bill * (1 + self.tax + self.tip) total = property(gettotal) def __repr__(self): return 'tip = %.2f, tax = %.2f, total = %.2f ' % \ (self.tip, self.tax, self.total) class usbill(allbills): def __init__(self, bill, tip): super(usbill, self).__init__(bill, tip) def gettax(self): return 0.0675 tax = property(gettax) class chicago_bill(allbills): def __init__(self, bill, tip): super(chicago_bill, self).__init__(bill, tip) def gettax(self): return 0.0725 tax = property(gettax) From duduca007 at yahoo.com Thu May 12 16:00:45 2005 From: duduca007 at yahoo.com (Carlos Moreira) Date: Thu, 12 May 2005 13:00:45 -0700 (PDT) Subject: Python Polymorphism In-Reply-To: 6667 Message-ID: <20050512200045.85674.qmail@web52604.mail.yahoo.com> --- Fredrik Lundh wrote: > so phrases like > (etc) > > doesn't tell you that polymorphism is a fundamental > part of the language, > and used all over the place. or did you have a > non-OO meaning of the > word in mind? Ok, I prefer to think that I could be more specific. So, let's try again. Supose that I want to create two methos (inside a class) with exactly same name, but number of parameters different: class myClass: myAttribute = 0 def myMethod(self): self.myAttribute += 1 def myMethod(self, myValue): self.myAttribute += myValue Both method hold same identifier, the only difference in them signture are parameters. How could I simulate the situation above, using the language dynamic link (or polymorphism, as you prefer)? Look, I don't want to use things like: .... def myMethod(self, myValue=None): if(not myValue): self.myAttribute += 1 else: self.myAttribute += myValue .... I want to use the power of polymorphism to modelate the problem. Thanks and best regards Cadu Moreira __________________________________ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250 From bcannon at gmail.com Tue May 31 16:46:14 2005 From: bcannon at gmail.com (bcannon at gmail.com) Date: 31 May 2005 13:46:14 -0700 Subject: convert a string to tuple In-Reply-To: <1117570449.887422.225670@g43g2000cwa.googlegroups.com> References: <1117570449.887422.225670@g43g2000cwa.googlegroups.com> Message-ID: <1117572374.910751.5400@f14g2000cwb.googlegroups.com> Pass it to eval: >>> eval('(1, 2, 3, 4, 5)') (1, 2, 3, 4, 5) Basically what you are doing it evaluating the repr of the tuple. -Brett From thomas at eforms.co.nz Wed May 18 22:28:20 2005 From: thomas at eforms.co.nz (Thomas) Date: Thu, 19 May 2005 14:28:20 +1200 Subject: source file for kalab's pycron & makezip Message-ID: <20050519022629.18C3B37A01@mail.tintz.co.nz> Hi All, I am trying to get the source files for pycron &makezip. http://www.kalab.com/freeware/pycron/pycron.htm I tried mailing a request to kalab at gmx.net but no joy yet. Cheers Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjb111 at student.canterbury.ac.nz Sun May 29 05:08:05 2005 From: cjb111 at student.canterbury.ac.nz (Crispen) Date: 29 May 2005 02:08:05 -0700 Subject: ControlDesk Automation in dSpace Message-ID: <1117357685.430456.257870@g43g2000cwa.googlegroups.com> I am having trouble using the ControlDesk automation libraries in python. In particluiar running the automation in a thread. My code is as follows, is keeps coming up with this strange error. Any help would be great. Crispen import cdacon from time import sleep from cdautomationlib import * def Auto(): sleep(0.5) # triggering://dSPACE NumericInput Control_1:WriteData Instrumentation().ConnectionController.DisableSystemPoll() Instrumentation().Layouts.Item("c:\\users\\matlab files\\triggering.lay").Instruments.Item("dSPACE NumericInput Control_1").Value = 1.0000000000000000 Instrumentation().ConnectionController.ProcessAnimationEvent ("triggering://dSPACE NumericInput Control_1","WriteData") Instrumentation().ConnectionController.EnableSystemPoll() sleep(0.5) # triggering://dSPACE NumericInput Control_1:WriteData Instrumentation().ConnectionController.DisableSystemPoll() Instrumentation().Layouts.Item("c:\\users\\matlab files\\triggering.lay").Instruments.Item("dSPACE NumericInput Control_1").Value = 0.00000000000000000 Instrumentation().ConnectionController.ProcessAnimationEvent("triggering://dSPACE NumericInput Control_1","WriteData") Instrumentation().ConnectionController.EnableSystemPoll() sleep(0.5) # triggering://dSPACE NumericInput Control:WriteData Instrumentation().ConnectionController.DisableSystemPoll() Instrumentation().Layouts.Item("c:\\users\\matlab files\\triggering.lay").Instruments.Item("dSPACE NumericInput Control").Value = 1.0000000000000000 Instrumentation().ConnectionController.ProcessAnimationEvent ("triggering://dSPACE NumericInput Control","WriteData") Instrumentation().ConnectionController.EnableSystemPoll() sleep(0.5) # triggering://dSPACE NumericInput Control:WriteData Instrumentation().ConnectionController.DisableSystemPoll() sleep(0.5) Instrumentation().Layouts.Item("c:\\users\\matlab files\\triggering.lay").Instruments.Item("dSPACE NumericInput Control").Value = 0.00000000000000000 Instrumentation().ConnectionController.ProcessAnimationEvent("triggering://dSPACE NumericInput Control","WriteData") Instrumentation().ConnectionController.EnableSystemPoll() sleep(0.5) Instrumentation().Layouts.Item("c:\\users\\matlab files\\triggering.lay").Activate() sleep(0.5) Instrumentation().Layouts.Item("c:\\users\\matlab files\\triggering.lay").Activate() thread.start_new_thread(Auto,()) From davidschein at alumni.tufts.edu Mon May 30 14:14:12 2005 From: davidschein at alumni.tufts.edu (David S.) Date: Mon, 30 May 2005 18:14:12 +0000 (UTC) Subject: standard doc style for method signatures Message-ID: Is there a generally accepted way to denote method signatures---that is, expected type or required interface for each argument. From lreder at worldnet.att.net Fri May 20 01:13:03 2005 From: lreder at worldnet.att.net (Leonard J. Reder) Date: Fri, 20 May 2005 05:13:03 GMT Subject: PIL and line drawing Message-ID: Hello, I am using PIL to annotate some images with lines. I could not find anyway to make the line that is drawn from the ImageDraw object thicker. Does anyone have a suggestion or solution for solving this without to much hacking? Thanks for any replies, Len -- =================================== Leonard J. Reder Home office email : reder at ieee.org Lab email : reder at jpl.nasa.gov Lab web page : http://reder.jpl.nasa.gov =================================== From steven.bethard at gmail.com Tue May 24 11:57:23 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Tue, 24 May 2005 09:57:23 -0600 Subject: staticmethod and classmethod In-Reply-To: References: Message-ID: C Gillespie wrote: > Does anyone know of any examples on how (& where) to use staticmethods and > classmethods? My personal experience is that I almost *never* want a staticmethod. The things that I would have written as a staticmethod in Java I simply write as a module-level function in Python. I do occasionally used classmethods though to build alternate constructors. I recently had a class with a constructor that looked like: class C(object): def __init__(self, *args): ... I already had code working with this constructor, but I needed to add an optional 'index' parameter. I found the clearest way to do this was something like: class C(object): def __init__(self, *args): ... @classmethod def indexed(cls, index, *args): ... obj = cls(*args) obj.index = index ... return obj Then the classes that needed the 'index' parameter simply use C.indexed() as the constructor instead of C(). STeVe From modelnine at ceosg.de Tue May 31 21:03:00 2005 From: modelnine at ceosg.de (Heiko Wundram) Date: Wed, 1 Jun 2005 03:03:00 +0200 Subject: ANN: PyAuthD - beta 3 Message-ID: <200506010303.03867.modelnine@ceosg.de> Hi all! I've tagged PyAuthD, beta 3 today. This release marks a milestone, as PyAuthD has superseded PyPAM and PyNSS (the precursors not implemented on a client/server model which are private to my univ) on the mail server which hosts our university's student email accounts. I'm able to release a demo server along with the actual modules (and an !untested! Postfix patch to enable PyAuthD to serve Postfix maps) under an adapted BSD license. What is PyAuthD? ---------------- A client/server implementation of a Python authentication daemon. The initiative to implement a Python authentication daemon came from the fact that MS SQL-Server is used as the backend server for our univ's HIS (Hochschul-Informations-System, university information system), and there are no proper PAM and NSS modules which can access MS SQL-server (as far as I found). Looking at the winbind sources (of the samba project) taking the step to implement short and concise C modules which access a Python daemon which does the actual handling wasn't much farfetched. Currently, PyAuthD offers: 1) PAM authentication 2) NSS handling by dispatching to the server process on get(pw/sp/gr)* functions, which foregoes reentrancy issues 3) PPPd authentication which requires the authentication daemon to hand out clear-text passwords over the socket 4) Untested Postfix map implementation This allows unprecedented abilities for authentication purposes by being able to program authentication logic in a high-level language under a single unified structure. What is it not? --------------- A "round" system. PyAuthD is a system that "works for me and my univ" (TM), and as such I'm just releasing it (minus the actual authentication part we use) for all people out there who want to hack on it just as I do. On the other hand I don't think that creating a single infrastructure is sensible at all, and as such won't spend much time creating any more means to access and compile it than I currently do. If you feel you want to create a distribution or add autoconf/automake handling and are willing to spend the time, feel free to contact me! What about security? -------------------- Currently PyAuthD will run under standard Python. "Standard Python" does not offer security features which enable it to work reliably in a multiuser-environment (as there is a requirement that all users can connect to it), as Python does not clear memory on releasing it making several attacks possible in case users have login-shells on the server. Furthermore Linux offers the possibility to access process information on the connecting process of a Unix-Domain-Socket, but this functionality is not exposed in standard Python. All this has led to the spin-off of a further project also hosted along with PyAuthD called SEPython, which aims at improving this situation. SEPython is currently based on standard Python 2.4.1, and has implemented the necessary recvmsg and sendmsg calls for retrieving process/user information from a unix domain socket. SEPython hasn't implemented clearing of memory yet. As we don't offer user-login shells on the mail-server which uses PyAuthD, we currently don't spend time on SEPython, but this situation will change when the mail-server has been fully migrated to the new infrastructure. If there's interest I'll package my patches on SEPython for inclusion in the standard Python tree, but I don't think that platform-dependent patches like sendmsg/recvmsg will ever make it into the official tree. ChangeLog --------- Please look at the commit log since tag beta-2. Download -------- Access using Subversion: svn co http://svn.asta.mh-hannover.de/svn/repos/PyAuthD/tags/beta-3 PyAuthD or ViewCVS: http://svn.asta.mh-hannover.de/viewcvs/PyAuthD/tags/beta-3/ License ------- PyAuthD as in subversion is released under an adapted BSD-license, except the Postfix module, which is released under the Postfix Secure Mailer license. Contact ------- Heiko Wundram or Heiko Wundram -- --- Heiko. listening to: De/Vision - Miss You More see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From heiko.wundram at ceosg.de Mon May 2 06:58:34 2005 From: heiko.wundram at ceosg.de (Heiko Wundram) Date: Mon, 2 May 2005 12:58:34 +0200 Subject: PyAuthD Beta 2a Message-ID: <200505021258.34970.heiko.wundram@ceosg.de> PyAuthD - Python Authentication Daemon -------------------------------------- PyAuthD is a project to create PAM, NSS and PPPd modules which communicate with a running Python authentication daemon using a Unix Domain socket. The project focusses so far on creating the necessary modules for PAM, NSS and PPPd. As the authentication is done using a single backend daemon, authentication on a Unix system can now be done safely and securely through a single process which need not even run as root as the metalanguage Python offers shields the programmer from handling common mistakes such as buffer-overflows. Choosing Python as the language to implement the daemon has other security implications which I am working on resolving. Current Release --------------- I've released PyAuthD, beta 2a. The project is now available via subversion from the following URL: http://193.174.104.108/svn/repos/tags/PyAuthD-beta2a or through ViewCVS: http://193.174.104.108/viewcvs Beta 2a does not yet implement a single daemon infrastructure, but contains (rather) incomplete samples of how to interact with the modules in question. These daemons were written with the single purpose to test the modules, and may not work with the current state of the modules anymore. License ------- PyAuthD and the modules are released under a "New BSD"-style license. You are required to keep the copyright intact if you plan on using this code, but otherwise are not encumbered in using it except by the common advertising clause. Plans/Bugfixes -------------- - Create autoconf/automake infrastructure for PyAuthD (looking for volunteers) - Implement the single signon daemon in a proper way. - Create Patches for the Python interpreter which cause types to overwrite the memory used by an object with zeros after freeing it. - Security-check the module implementations. - Implement proper error handling in the NSS get*ent functions when memory runs out. - and much, much more... Help ---- I'm working on this project with two other people. If you are interested in joining us, feel free to mail me, and I can arrange commit priviledges to the SVN repository. Otherwise, I'm looking forward to this thursday, where I'll present the project at this years German Linux-User-Groups meeting. Hope to see you there! --- Heiko Wundram. From http Sun May 15 16:19:15 2005 From: http (Paul Rubin) Date: 15 May 2005 13:19:15 -0700 Subject: Schily ueber Deutschland References: Message-ID: <7x3bso6y4c.fsf@ruckus.brouhaha.com> Bernd Nawothnig writes: > On 2005-05-15, mal at lemburg.com [allegedly] wrote: ... I don't think that post was really from MAL. It seems to be a sporgery attack on the newsgroup. Sigh. From tjreedy at udel.edu Sun May 15 14:36:36 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 May 2005 14:36:36 -0400 Subject: Mandrake 10.1 and Python 2.3.4 References: Message-ID: "Joal Heagney" wrote in message news:AsGhe.3663$E7.3600 at news-server.bigpond.net.au... > 'import site' failed; traceback: > Traceback (most recent call last): > File "/usr/lib/python2.3/site.py", line 169, in ? > sys.lib, > AttributeError: 'module' object has no attribute 'lib' Right: the sys module usually has no .lib attribute that I know of >>> import sys; sys.lib Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'lib' > Is this a Mandrake or a Python mistake? It is a site.py code mistake, but who wrote your copy of site.py? > And does anyone know how to fix it? Correct or remove the offending line (169) Terry J. Reedy From mcaloney at cs.queensu.ca Tue May 3 22:27:09 2005 From: mcaloney at cs.queensu.ca (Chris McAloney) Date: Tue, 3 May 2005 22:27:09 -0400 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: <3dg5isF6qe1nhU1@news.dfncis.de> <1f7befae05043000165448b8d@mail.gmail.com> Message-ID: On Tue, 3 May 2005, Leif K-Brooks wrote: > Chris McAloney wrote: > > Okay, so I've been working on level seven for a LONG time now. I've > > decoded the first message to get the hint for the next level. Using the > > same tactics, then I decode the hint as well, but there are non-printable > > characters. > > Frira be srjre pbcvrf bs gur fnzr cvkry va n ebj ner bar punenpgre, ohg > rvtug cvkryf ner gjb punenpgref. Oh dear. I would **never** have gotten this on my own. I mean that, too, since I discarded adjacent duplicates and used the "trimmed" (equivalently: "wrong") version as my ground truth. Thanks very much. -chris ... and now on to number eight ... From sklass at pointcircle.com Tue May 31 18:42:03 2005 From: sklass at pointcircle.com (rh0dium) Date: 31 May 2005 15:42:03 -0700 Subject: Problem with re.match - Newbie needs some advice Message-ID: <1117579323.153831.118090@f14g2000cwb.googlegroups.com> Hi all, I am having a problem with the method cpuNum. Basically I look to see if the "flag" for "ht" is enabled. If it is the total processors should be cpucount/2. It's not working. I can't seem to get into the second re.match. Can someone point out my apparent error? class Sysinfo: def __init__(self, cpuinfo="/proc/cpuinfo", meminfo="/proc/meminfo"): cpustat = open(cpuinfo) self.cpudata = cpustat.readlines() cpustat.close() def cpuNum(self): cpucount=0 ht=0 for line in self.cpudata: # Remove the newlines.. line=line.strip() if re.match(r"^processor\s+:", line): cpucount += 1 if re.match(r"^flags\s+:", line): flags=re.split(r":\s",line) #print "Found flags", flags[1] if re.match(r"\bht\b",flags[1]): print "HT on" ht=1 if ht: return cpucount/2 else: return cpucount s = Sysinfo( cpuinfo="cpuinfo.1", meminfo="meminfo.1" ) print s.cpuNum() ---- cpuinfo.1 (abbreviated) ---- processor : 0 flags : cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid processor : 1 flags : cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid From Bernd.Nawothnig at t-online.de Sun May 15 14:08:17 2005 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sun, 15 May 2005 20:08:17 +0200 Subject: Schily ueber Deutschland References: Message-ID: On 2005-05-15, mal at lemburg.com wrote: > Lese selbst: > http://www.heise.de/newsticker/meldung/59427 Ja, schlimm. Trotzdem ist das hier a) eine englischsprachige NG und b) geht es hier um die Programmiersprache Python Lass es also bitte endlich! Bernd -- Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. [T. Jefferson] From brian at sweetapp.com Wed May 11 08:49:27 2005 From: brian at sweetapp.com (Brian Quinlan) Date: Wed, 11 May 2005 14:49:27 +0200 Subject: Interactive shell for demonstration purposes In-Reply-To: <1115814028.259365.98710@g49g2000cwa.googlegroups.com> References: <1115814028.259365.98710@g49g2000cwa.googlegroups.com> Message-ID: <4281FF57.4010507@sweetapp.com> Can anyone recommend a Python interactive shell for use in presentations? Ideal characteristics (priority order): o configurable font size o full screen mode o readline support o syntax coloring I've tried ipython but, since it runs inside a console window, and the console window has a limited number of selectable fonts, it doesn't work terribly well. I've seen presentations using some sort of PyGame implemented shell. Does anyone have an information on that? Cheers, Brian From fredrik at pythonware.com Thu May 26 06:49:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 26 May 2005 12:49:14 +0200 Subject: assignment, references and list comprehension References: Message-ID: "Jim O'D" wrote: > I was confused as to whether the assignment of a result of a list > comprehension created references to the orginal objects... python never copies objects unless you tell it to, so the answer is yes. all the "values" you pass around are object references, not binary blobs. > and it does (at least for my self-defined object). trust me, it works the same way for all objects. reading this may help: http://effbot.org/zone/python-objects.htm From elbertlev at hotmail.com Sun May 8 14:38:12 2005 From: elbertlev at hotmail.com (elbertlev at hotmail.com) Date: 8 May 2005 11:38:12 -0700 Subject: Database backend? In-Reply-To: <427e55e3$0$79463$14726298@news.sunsite.dk> References: <427e55e3$0$79463$14726298@news.sunsite.dk> Message-ID: <1115577492.721712.144310@o13g2000cwo.googlegroups.com> Look for the packet called "KirbyBase". Small, pythonic, text based files... From nospam at here.com Mon May 16 13:20:30 2005 From: nospam at here.com (Matt Feinstein) Date: Mon, 16 May 2005 13:20:30 -0400 Subject: Applying a function to a 2-D numarray References: Message-ID: <7flh81d00feulgkdfdrh69rbgp4v36mqtl@4ax.com> On Mon, 16 May 2005 11:07:06 -0600, Steven Bethard wrote: > >I must be missing something, because the simplest possible thing seems >to work for me: > >py> import numarray as na >py> def plus1(arr): >... return arr + 1 >... >py> def apply_func(arr, f): >... return f(arr) >... >py> a = na.arange(20, shape=(4, 5)) >py> a >array([[ 0, 1, 2, 3, 4], > [ 5, 6, 7, 8, 9], > [10, 11, 12, 13, 14], > [15, 16, 17, 18, 19]]) >py> apply_func(a, plus1) >array([[ 1, 2, 3, 4, 5], > [ 6, 7, 8, 9, 10], > [11, 12, 13, 14, 15], > [16, 17, 18, 19, 20]]) > >Is this not what you wanted? The problem is that I chose an example function that's too simple. Non-trivial functions aren't so polymorphic, unfortunately. Sorry for the confusion. Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From geraldhereford at yahoo.com Sun May 15 16:29:31 2005 From: geraldhereford at yahoo.com (gerald hereford) Date: Sun, 15 May 2005 13:29:31 -0700 (PDT) Subject: No subject Message-ID: <20050515202931.10762.qmail@web60320.mail.yahoo.com> __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From jabel at plus.net Thu May 12 03:53:37 2005 From: jabel at plus.net (John Abel) Date: Thu, 12 May 2005 08:53:37 +0100 Subject: Defunct Processes With subprocess.Popen In-Reply-To: <86u0l9kqhk.fsf@guru.mired.org> References: <86u0l9kqhk.fsf@guru.mired.org> Message-ID: <42830B81.7060302@plus.net> Mike Meyer wrote: >John Abel writes: > > > >>Hi! >> >>I'm currently writing a script which launches external programs, but >>it keeps leaving zombie/defunct processes behind, until I kill the >>launching script, which is a bit of a pain, as it's supposed to be a >>daemon. The code I'm using is: >> >>newPid = subprocess.Popen( cmdLine[ 1: ], executable=cmdLine[ 0 ], >>close_fds=True ).pid >> >>I've tried calling it using the shell=True flag, but that leaves a >>zombie for the sh, instead. I'm not interested in any output, the >>only thing I need returning, is the pid of the new process. I've >>tried using spawn*, with the same results. Does anyone have any ideas? >> >> > >The processes are hanging around in a zombie state so the parent (or >someone) can get their exit status. > >Try calling os.wait() until it returns the exit status for all the >processes you've started. > > > Ahh, OK. Thanks for that. Works now. J From just at xs4all.nl Sat May 7 05:05:47 2005 From: just at xs4all.nl (Just) Date: Sat, 07 May 2005 11:05:47 +0200 Subject: py2exe + svn - the final drama References: <427AD7E8.1060500@open-networks.net> Message-ID: In article , David Bolen wrote: > Just writes: > > > the zipimport module has an attr called _zip_directory_cache, which is a > > dict you can .clear(). Still, reloading modules is hairy at best, its > > probably easiest to relaunch your app when the .zip file has changed. > > Except that he's getting an error during the process exit of the > current execution, which is needed to restart. And if he updates to a > different copy, there's the bootstrap problem of how to get it back > into the standard location for the next restart since his application > will need to have it to restart in the first place. Right. It sounds like a module is imported at exit that wasn't imported before. If that's the case, it may help to make sure all modules needed for exit are imported beforehand. Just From steven.bethard at gmail.com Thu May 19 16:50:37 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 19 May 2005 14:50:37 -0600 Subject: Convert from numbers to letters In-Reply-To: References: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> <1116528750.285895.27720@f14g2000cwb.googlegroups.com> <1116530403.328825.216120@z14g2000cwz.googlegroups.com> <797fe3d405051913022e35c7c6@mail.gmail.com> <428CF3FF.8050403@ece.utexas.edu> Message-ID: <3sGdnaxJM5aDYRHfRVn-hA@comcast.com> Gary Wilson Jr wrote: > Gary Wilson Jr wrote: > >>alpha = 'abcdefghijklmnopqrstuvwxyz'.upper() >>pairs = [x for x in alpha] + [''.join((x,y)) for x in alpha for y in alpha] > > I forget, is string concatenation with '+' just as fast as join() > now (because that would look even nicer)? Certain looping constructs like: x = '' for y in z: x += y are now (in CPython 2.4) somewhere near the speed of: x = [] for y in z: x.append(y) x = ''.join(x) but this isn't really relevant to your problem because you're only joining two characters: $ python -m timeit -s "import string; a = string.ascii_uppercase" "[''.join([x, y]) for x in a for y in a]" 1000 loops, best of 3: 1.02 msec per loop $ python -m timeit -s "import string; a = string.ascii_uppercase" "[x + y for x in a for y in a]" 1000 loops, best of 3: 295 usec per loop Unsurprisingly, it's actually faster to simply concatenate the two characters. STeVe From luis_lupe2XXX at netvisaoXXX.pt Fri May 13 10:58:16 2005 From: luis_lupe2XXX at netvisaoXXX.pt (Luis P. Mendes) Date: Fri, 13 May 2005 15:58:16 +0100 Subject: Dive into Python java equivalent Message-ID: <3ejtkbF3ifbnU1@individual.net> Hi, do you know if is there any 'Dive into Python' equivalent for the java language? DiP is the best I've seen and I would need to learn some basics of Java and also ways to interact between the two languages. (I'm already aware of Jpype and Jython) Luis From ccurvey at gmail.com Mon May 2 13:19:17 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 2 May 2005 10:19:17 -0700 Subject: xmlrpc server running behind IIS as a CGI Message-ID: <1115054357.061932.322300@z14g2000cwz.googlegroups.com> Here's my server: import os import SimpleXMLRPCServer class Foo: def settings(self): return os.environ def echo(self, something): return something def greeting(self, name): return "hello, " + name handler = SimpleXMLRPCServer.CGIXMLRPCRequestHandler() handler.register_instance(Foo()) handler.handle_request() If I run this behind Apache/CGI, everything works fine. If I run this behind IIS/CGI, everything hangs when I call the server (I have confirmed that a "hello world" program runs fine thru CGI when called via a web browser). Here's the client program: import xmlrpclib server = xmlrpclib.ServerProxy("http://127.0.0.1:81/cms/Foo.py") print server.settings() From Pidaqing at mail.iame.cn Thu May 12 23:33:21 2005 From: Pidaqing at mail.iame.cn (=?gb2312?B?xqS088fs?=) Date: Fri, 13 May 2005 11:33:21 +0800 Subject: property, how to use it? Message-ID: <20050514012648.C48572886F@mail.iame.cn> python???? What is the "property" mean in the python? Who can explain it for me? I don't know how to use it. ????????? ?? ??????????? ????????Pidaqing at mail.iame.cn ??????????2005-05-13 From steve at holdenweb.com Mon May 2 22:32:44 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 02 May 2005 22:32:44 -0400 Subject: Forgot my wrapup of example! Sorry! In-Reply-To: References: <1114709684.096071.109960@l41g2000cwc.googlegroups.com> Message-ID: <4276E2CC.6030001@holdenweb.com> GMane Python wrote: > So, I forgot the last part of my example that might gel in your mind why > Objects are useful in certain situations. Ok so you maybe followed my > example of the shopping cart. Let's just forget for a moment the use for > shopping carts is for websites. Let's just say you were going to write the > lines directly into Python, like maybe at the IDLE interpreter. Like maybe > you're testing the functionality of the routine for correctness, not actual > implementation. > > [good introductory class stuff snipped] > > > In a class, you can have a variable 'total' and you can have a variable > 'self.total'. The first is just accessible from within the structure of the > class. The latter is accessible from outside the class. So, using a class > with the variable self.total, you can from outside the class say: > > > > print ShoppingCart["Dave"].total > > > > to get the value of the variable self.total. (That had me buggered for a > while ..... ) > Thanks for the smile this gave me. We all get to this stage periodically when programming. > > > If you can wrap your mind around this, you're well on your way to using OOP > I believe. If not, , don't give up. I'm just a python/programming newbie > and maybe missed the boat completely with my posting. > Well maybe you did, but you actually managed to demonstrate important parallels between namespaces and dictionaries in Python. > > > Another quite important part I didn't even mention was sub-classing. That's > taking a class, and 'inheriting' it's code to your class as a base, then you > can re-write or adddifferent methods. But, first I think it's important to > understand how to have several instances of a single class running in > memory, each with different values for the defined variables. I'll let > someone else talk about that. > As indeed they almost inevitably will :-) regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From jjl at pobox.com Tue May 17 15:30:53 2005 From: jjl at pobox.com (John J. Lee) Date: 17 May 2005 19:30:53 +0000 Subject: Python on a public library computer References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> <1116329666.566651.42950@z14g2000cwz.googlegroups.com> Message-ID: <87sm0lk5ua.fsf@pobox.com> "Anton Vredegoor" writes: > John J. Lee wrote: > > > Why not Jython? > > There's no command prompt! The file menu from IE is also gone. There is > a sun Java console but it looks like this: [...] ISTR (maybe incorrectly) there's a Jython shell you can run in IE. John From rbt at athop1.ath.vt.edu Wed May 4 08:33:31 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 04 May 2005 08:33:31 -0400 Subject: sha-2 and sha-512 bindings In-Reply-To: References: Message-ID: Almad wrote: > Hi, > > is there any python bindings for sha-2 or sha-512? > > Pycrypto seems to have only sha-1 bindings and I can't see any other package > on net... > > Thanks, On Debian GNU\Linux Testing, Python2.3-crypto contains sha256 hashing. http://packages.debian.org/testing/python/python2.3-crypto From fredrik at pythonware.com Thu May 26 10:34:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 26 May 2005 16:34:18 +0200 Subject: using timeit for a function in a class References: Message-ID: "flupke" wrote: > i tried to use timeit on a function in a class but it doesn't do what i > think it should do ie. time :) > In stead it starts printing line after line of hello time test! > What am i doing wrong in order to time the f function? how do you expect timeit to figure out how long it takes to run your function without calling the function? > class TimeTest(object): > def f(self): > print "hello time test!" From benji at benjiyork.com Sat May 28 16:54:59 2005 From: benji at benjiyork.com (Benji York) Date: Sat, 28 May 2005 16:54:59 -0400 Subject: a dict problem In-Reply-To: <1117300484.637674.97430@f14g2000cwb.googlegroups.com> References: <1117300484.637674.97430@f14g2000cwb.googlegroups.com> Message-ID: <4298DAA3.3080601@benjiyork.com> cheng wrote: > hi all..it a problem about dict: > > print target, dict[target] > > get output: > > keyword > {page3.html, page2.html, page1.html} > > is it some ways to change it to: > > keyword > {page1.html, page2.html, page3.html} First, I would recommend you always post actual code and its output. It is much easier for people to help you that way. Also, "dict" is not a good variable name because it shadows the built-in of the same name. I'll extrapolate from your message that you want to get the values of the dict in sorted order. If so, here's how: >>> d = {'a': 1, 'b': 2, 'c':3} >>> d {'a': 1, 'c': 3, 'b': 2} >>> v = d.values() >>> v [1, 3, 2] >>> v.sort() >>> v [1, 2, 3] -- Benji York From querypk at gmail.com Thu May 26 11:25:35 2005 From: querypk at gmail.com (querypk at gmail.com) Date: 26 May 2005 08:25:35 -0700 Subject: Improve the performance of a loop In-Reply-To: References: <1117058565.920549.221420@g47g2000cwa.googlegroups.com> Message-ID: <1117121135.549427.144480@g44g2000cwa.googlegroups.com> Actually slicing the way you suggested improved it to some extent. I did profile on this and I observed that it reduced the number of calls for __get_item__ and improved the timing to some extent. Which was useful to some extent. Thanks again. From lbates at syscononline.com Mon May 9 11:06:58 2005 From: lbates at syscononline.com (Larry Bates) Date: Mon, 09 May 2005 10:06:58 -0500 Subject: include "apythonscript.py" In-Reply-To: <1115648730.390588.158760@z14g2000cwz.googlegroups.com> References: <1115648730.390588.158760@z14g2000cwz.googlegroups.com> Message-ID: How about? put apythonscript_function.py in a separate file then inculde apythonscript_function.py at the top of maincode.py Looks like you probably need to go back and read the tutorial. -Larry martijn at gamecreators.nl wrote: > H! > > I'm trying to find a python function to use like this: > > -- maincode.py > > Include "apythonscript_function.py" > > -- end > > So I can split the maincode.py file in smalle pieces. > Or yust save the function's in other file and include them once. > I really want to use this because else { the maincode.py will be super > super large. } > > Thanks, > GC-Martijn > > ----- if you don't understand what I mean: http://www.php.net/include > From dominic.fox at gmail.com Mon May 2 05:54:07 2005 From: dominic.fox at gmail.com (Dominic Fox) Date: Mon, 2 May 2005 10:54:07 +0100 Subject: Tripoli: a Python-based triplespace implementation In-Reply-To: References: Message-ID: karouri wrote: > Interesting, but I wonder if you are aware of pylinda > (http://www-users.cs.york.ac.uk/~aw/pylinda/) and if so, what's the > difference? Tripoli trades off some of the generality of PyLinda in order to support some performance tweaks and some additional graph-related operations. Tripoli restricts the tuple space model implemented by PyLinda to 3-tuples, and extends it by adding copy_graph and copy_collect_graph operations to copy and move graphs of triples from one triple space to another. PyLinda allows you to pattern match on types, which is really neat but makes index-based tuple lookups impractical. Tripoli matches literals or wildcards only, but it indexes every triple on all three components so in theory it should be quicker at finding triples, matching blocked requests to incoming triples and so on. Performance is fairly good even with large-ish (10000+). triple sets. Some other respects in which I think Tripoli is different, but aren't familiar enough with PyLinda to say for certain: Tripoli uses callbacks to notify waiting requestors that a matching triple has arrived. Requestors can block waiting for a callback, or continue about their business and handle the callback only when it occurs. Communication between the Tripoli client and server is asynchronous: the client sends a triple request, and at some point in the future the server may contact the client to send a response back. The REST-ful version will also support client polling of a temporary resource representing a pending request. Tripoli will eventually support RDF/XML as a format for importing and exporting triples. Dominic From onfrek at yahoo.com Sun May 29 05:15:32 2005 From: onfrek at yahoo.com (Michael Onfrek) Date: 29 May 2005 02:15:32 -0700 Subject: Copy paste in entry widget In-Reply-To: References: <1117200716.423741.257870@f14g2000cwb.googlegroups.com> Message-ID: <1117358132.626957.306560@z14g2000cwz.googlegroups.com> I need it for Linux, so far only TkInter used. From rkern at ucsd.edu Fri May 13 12:53:16 2005 From: rkern at ucsd.edu (Robert Kern) Date: Fri, 13 May 2005 09:53:16 -0700 Subject: create words of various lengths In-Reply-To: <1116002403.374232.210220@g49g2000cwa.googlegroups.com> References: <1116002403.374232.210220@g49g2000cwa.googlegroups.com> Message-ID: superprad at gmail.com wrote: > "X-No-Archive: yes" > > what I am looking for is > > 1. To create a list of different words of various lengths(1-15) using > A-Z,a-z,0-9 and punctuations.Basically anything that could be found on > a text document. > > 2. The words formed need not be meaningful .FOr example 'ajf' or > 'fcjgdtfhbs' or even 'gfdew!' or '#bang.' would be a valid entry in the > list. > > 3.So I am looking for a random set of words of sizes 1 to 15.The proble > might be the time complexity. I inderstand that there would be too many > permutations. So why don't you take one step back and tell us what you think you need this list *for*? We might be able to come up with feasible alternatives. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From bokr at oz.net Mon May 2 21:49:54 2005 From: bokr at oz.net (Bengt Richter) Date: Tue, 03 May 2005 01:49:54 GMT Subject: empty lists vs empty generators References: <509534af.0505021514.5e49aa2@posting.google.com> Message-ID: <4276d193.519170387@news.oz.net> On 2 May 2005 16:14:57 -0700, brian at mirror.org (Brian Roberts) wrote: >I'm using using generators and iterators more and more intead of >passing lists around, and prefer them. However, I'm not clear on the >best way to detect an empty generator (one that will return no items) >when some sort of special case handling is required. > >Typical code for handling an empty list: > if somelist: > for x in somelist: > something(x) > else: > empty_list_special_case > >But this doesn't work with iterators -- a generator is "true" >regardless of whether its going to return any items. (I understand >why). > >The closest equivalent I know of is: > n = 0 > for n, x in enumerate(somegenerator()): > something(x) > if n == 0: > empty_list_special_case > >Which seems rather awkward -- doesn't read as easily for me, and >introduces another variable. And, if I understood the intent, doesn't work ;-) >>> n = 0 >>> for n, x in enumerate(c for c in 'a'): ... print 'something', x ... something a >>> if n == 0: ... print 'empty list special case ??' ... empty list special case ?? You could have used n = -1 as a sentinel that enumerate would not set, but using a guaranteed-unique sentinel, you don't need enumerate, e.g., >>> x = sentinel = object() >>> for x in (c for c in 'a'): ... print 'something', x ... something a >>> if x is sentinel: ... print 'empty list special case ??' ... (nothing printed there) and for the actually empty sequence >>> x = sentinel = object() >>> for x in (c for c in ''): ... print 'something', x ... >>> if x is sentinel: ... print 'empty list special case ??' ... empty list special case ?? > >Q1: Is there a better or alternate way to handle this? >Q2: Is there a way that handles both lists and generators, so I don't >have to worry about which one I've got? > UIAM this should work for any iterable. You don't have to manufacture a locally bound sentinel as above. You could pick anything to preset the for-target that you know is not going to be produced by the iterable, though you might need to use '==' instead of 'is' depending on your choice. But e.g., I don't think I'd write x = Exception # weird sentinel choice for x in mystring: print x, ord(x) if x is Exception: print 'null sequence' None probably works well a lot of the time, but not always. Similarly ''. Seems like a builtin sentinel binding like sentinel = object() might be handy to standardize usage. Regards, Bengt Richter From ionel.mc at gmail.com Mon May 30 06:19:02 2005 From: ionel.mc at gmail.com (ionel) Date: Mon, 30 May 2005 12:19:02 +0200 Subject: where can i find pylibpcap module for win32? In-Reply-To: References: Message-ID: i've compiled a pcapy http://lenoi.3x.ro/ works fine ( using it :) ) On 5/30/05, jerky wrote: > thanks for your any imformation. > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- ionel. From exarkun at divmod.com Fri May 27 13:57:18 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 27 May 2005 17:57:18 GMT Subject: lambda a plusieurs arguments In-Reply-To: <42975b1a$0$26423$626a14ce@news.free.fr> Message-ID: <20050527175718.559.192528752.divmod.quotient.11246@ohm> On Fri, 27 May 2005 19:38:33 +0200, nico wrote: >Bonjour, > >Comment faire une fonction lambda a plusieurs arguments ? > >>>> (lambda a:a+1)(2) >3 >>>> f=(lambda (a,b):a+b) >>>> f(5,6) >Traceback (most recent call last): > File "", line 1, in ? >TypeError: () takes exactly 1 argument (2 given) >>>> f((5.6)) ^--- , >>> f((5, 6)) 11 >>> Aussi, >>> f = lambda a, b: a + b >>> f(5, 6) 11 >>> Jp From fumanchu at amor.org Sun May 15 18:27:20 2005 From: fumanchu at amor.org (Robert Brewer) Date: Sun, 15 May 2005 15:27:20 -0700 Subject: Is isinstance always "considered harmful"? Message-ID: <3A81C87DC164034AA4E2DDFE11D258E37720AE@exchange.hqamor.amorhq.net> Jordan Rastrick wrote: > Subject: Is isinstance always "considered harmful"? > > Say you're writing, > in Python, the extend() method for a Linked List version of python's > builtin list. Its really important to know what kind of iterable youre > being passed in - because if its another Linked list, and you know it, > you can connect the two in 0(1) time; whereas any other arbitrary > iterable is going to take 0(n), as you're just going to have to append > the items one by one. Is this a case where use of isinstance, to see > exactly what kind of Iterable you have, can be justified? I'd say so, definitely. > There are other solutions I can think of - perhaps the least > hideous is factoring out the 0(1), "point last to first" code > in a separated method, __linkedExtend() or something, and then > do something similar to the above by using an exception, > like this: > > def extend(self, elems): > try: > self.__linkedExtend(elems) > catch NotALinkedListError: > for elem in elems: self.append(elem) > > I dont know, I don't really like this (although it is more BAFP than > the first version, so maybe that makes it more Pythonic?). You've decided to special-case a binary operation based on the type of *both* objects. Whether you use isinstance or __linkedExtend, you're still providing a single-dispatch mechanism, which gets uglier in proportion to the number of types involved. Meh. I'd go with isinstance for now. Your use case is exactly why it's in the language, IMO. If the number of types you're special-casing becomes unwieldy, you might be interested in multiple-dispatch approaches (cf http://gnosis.cx/publish/programming/charming_python_b12.html) and generic functions (cf http://dirtsimple.org/2004/11/generic-functions-have-landed.html). Robert Brewer System Architect Amor Ministries fumanchu at amor.org > To me, > instanceof seems like the infimum of all possible evils in this case. > > It'd be nice if I'd seen the source code for Python's builtin list to > see if any of these kind of considerations are taken into > account there > (ultra fast array copying in C when extend is called on another list, > perhaps)? Luckily, one of the great gifts of Python is I can indeed > look at the source for the entire langauge at any time I want. So I'm > going to go read it (my first time, how exciting!), and in the > meantime, I'll let replies start accumulating froma whole lot of > people who are a lot smarter and more experience in Python than myself > :) > > Several-weeks-in-and-still-liking-Python-better-than-any-other > -previously-learned-language-ly > yours, > Jordan Rastrick > > -- > http://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Wed May 25 21:46:09 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 25 May 2005 21:46:09 -0400 Subject: "...Learning with Python" ...a property that addition andmultiplication have... References: <1117067025.233387.323910@z14g2000cwz.googlegroups.com> Message-ID: wrote in message news:1117067025.233387.323910 at z14g2000cwz.googlegroups.com... > Greetings. > > I'm reading "How to think like a computer scientist: Learning with > Python" and there's a question regarding string operations. The > question is, "Can you think of a property that addition and > multiplication have that string concatenation and repetition do not?" > > I thought it was the commutative property but ""*3 is > equivalent to 3*"". Any ideas? Go back to concatenation instead of repetition. TJR From mefjr75 at hotmail.com Sat May 14 13:44:30 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 14 May 2005 10:44:30 -0700 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> Message-ID: <1116092670.420301.196570@o13g2000cwo.googlegroups.com> David wrote: > Hi I'm trying to teach myself python and so far to good, but I'm having > a bit of trouble getting a function to work the way I think it should > work. Right now I'm taking a simple program I wrote in Fortran and > trying to do it in Python. I got it to work, but now I'm trying to > modularize it. My fortran program uses a subroutine and I was trying > to do the same thing in Python. But I'm still new so I'm having > trouble understanding what I'm doing wrong. Here is my code: > > #! /usr/bin/python > #This program takes two vectors and multiplies them > #against a 10X10 array. It also then gives the dot product, > #sum, and max value of the array. > > import Numeric > def abc(array1,array2,dotprod,sum,maxvalue): > """Takes two arrays and performs predetermined calculations, > Then returns the solutions back as the same array, along > with the dot product, sum, and max value of the array.""" > #TODO: Get this damn thing working!! > print "Array 1 in:",array1 #Debug > data = Numeric.zeros((10,10)) > for i in range(10): > for j in range(10): > data[i,j] = (i+1)+(j+1) > > e = Numeric.matrixmultiply(data, array1) > g = Numeric.matrixmultiply(Numeric.transpose(data),array2) > array1 = e > array2 = g > dotprod = Numeric.dot(array1,array2) > sum = Numeric.sum(array1) > maxvalue = array2[Numeric.argmax(array2)] > print "Array 1 out:",array1 #Debug > > return array1,array2,dotprod,sum,maxvalue #<<-- Not working as I > thought it would. > > x = Numeric.arange(1,11) > y = Numeric.arange(1,11)*2 > dotp,sumx,maxv = 0,0,0 #Is this the only way to declare a variable? > > print 'Array X:',x > print 'Array Y:',y > abc(x,y,dotp,sumx,maxv) > print 'Calling function abc' > print 'Array X:',x > print 'Array Y:',y > print 'Dot Product of X and Y:',dotp > print 'Sum of array X:',sumx > print 'Max value of array Y:',maxv > > If you run it the data gets passed to the function just fine and it > finds the right numbers. Its just getting it to pass them back thats > not working. I put some print statements inside the function just to > see how the data gets passed. So any ideas that would help me? If you > want to see the fortran code just email me. > > David Hello David, welcome to Python! Python always returns 'something' from a function or method if nothing is specified or there is no return you get an implicit None. You have created a function that accepts a few arguments and processes them then returns there value. The problem is that you **have not** used the return values ;) example: def funk(first,second,third): return first,second,third This can be like this: print funk("theses three args can be anything",2,"three") If you need to use the return values you need to assign them to a "name" so you have a handle on them. Variables are don't exist in Python there are only objects and names( hence namespaces ), but not everyone is so strict and you still see mention of 'variables' when they mean 'names'. > ##dotp,sumx,maxv = 0,0,0 # not needed here > print 'Array X:',x > print 'Array Y:',y > ## Notice we assign the return values to names so we can access it later > arr1,arr2,dotp,sumx,maxv = abc(x,y,0,0,0) > print 'Calling function abc' > print 'Array X:',arr1 > print 'Array Y:',arr2 > print 'Dot Product of X and Y:',dotp > print 'Sum of array X:',sumx > print 'Max value of array Y:',maxv Or you could pack all return values into a tuple and access it thru slices. > ##dotp,sumx,maxv = 0,0,0 # not needed here > print 'Array X:',x > print 'Array Y:',y > abcinfo = abc(x,y,0,0,0) > print 'Calling function abc' > print 'Array X:',abcinfo[0] > print 'Array Y:',abcinfo[1] > print 'Dot Product of X and Y:',abcinfo[2] > print 'Sum of array X:',abcinfo[3] > print 'Max value of array Y:',abcinfo[4] Or you could use a dictionary, or etc... The possibilities are endless. Be sure to study up on namespaces, it will ease your Python woes. Namespaces are the most fundamental part of Python that new users don't understand. Namespace mastery will take you far. Just remember there are only two scopes local and global ;) http://docs.python.org hth, M.E.Farmer From peter at engcorp.com Mon May 16 12:59:12 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 May 2005 12:59:12 -0400 Subject: newbie - variable "buried in quotes" In-Reply-To: <7pmdnSlf65zMTRXfRVn-2A@powergate.ca> References: <1116260476.332975.87680@g49g2000cwa.googlegroups.com> <7pmdnSlf65zMTRXfRVn-2A@powergate.ca> Message-ID: Peter Hansen wrote: > The % operator goes immediately after the string on which it operates: > > gp.FeatureclassToCoverage_conversion("'Database > Connections\\%s at GIS_srv-earth.sde\\GIS.GIS.Cadastral\\GIS.GIS.Parcels' > POLYGON" % luser, prcl83, "", "DOUBLE") Missed your buried question about line continuations. Yes, there is one, and it's the conventional \ at the end of the line. On the other hand, there are better approaches: gp.FeatureclassToCoverage_conversion("'Database Connections" "\\%s at GIS_srv-earth.sde\\GIS.GIS.Cadastral\\GIS.GIS.Parcels'" "POLYGON" % luser, prcl83, "", "DOUBLE") That, for example, uses the fact that adjacent strings are combined into one by the parser. Since they are all enclosed in parentheses, they are considered "adjacent" even though they come on different lines without line continuation characters. It's pretty rare to need to use \ to continue lines, unless it's just a style you don't mind or prefer. (Personally, I'd write this differently. Create a variable called path or something just above that line, doing the string substitution when you build it. Then the call to FeatureclassToCoverage_conversion() can come all on one line using "path", even with its unwieldy name. :-) -Peter From mauriceling at acm.org Sat May 7 00:03:34 2005 From: mauriceling at acm.org (Maurice LING) Date: Sat, 07 May 2005 14:03:34 +1000 Subject: hard memory limits References: <427c258b.868346285@news.oz.net> Message-ID: John Machin wrote: > On Sat, 07 May 2005 02:29:48 GMT, bokr at oz.net (Bengt Richter) wrote: > > >>On Sat, 07 May 2005 11:08:31 +1000, Maurice LING wrote: >> >>>It doesn't seems to help. I'm thinking that it might be a SOAPpy >>>problem. The allocation fails when I grab a list of more than 150k >>>elements through SOAP but allocating a 1 million element list is fine in >>>python. >>> >>>Now I have a performance problem... >>> >>>Say I have 3 lists (20K elements, 1G elements, and 0 elements), call >>>them 'a', 'b', and 'c'. I want to filter all that is in 'b' but not in >>>'a' into 'c'... >>> >>> >>>>>>a = range(1, 100000, 5) >>>>>>b = range(0, 1000000) >>>>>>c = [] >>>>>>for i in b: >>> >>>... if i not in a: c.append(i) >>>... >>> >>>This takes forever to complete. Is there anyway to optimize this? >>> >> >>Checking whether something is in a list may average checking equality with >>each element in half the list. Checking for membership in a set should >>be much faster for any significant size set/list. I.e., just changing to >> >> a = set(range(1, 100000, 5)) >> >>should help. I assume those aren't examples of your real data ;-) >>You must have a lot of memory if you are keeping 1G elements there and >>copying a significant portion of them. Do you need to do this file-to-file, >>keeping a in memory? Perhaps page-file thrashing is part of the time problem? > > > Since when was 1000000 == 1G?? > > Maurice, is this mucking about with 1M or 1G lists in the same > exercise as the "vm_malloc fails when allocating a 20K-element list" > problem? Again, it might be a good idea if you gave us a little bit > more detail. You haven't even posted the actual *PYTHON* error message > and stack trace that you got from the original problem. In fact, > there's a possible interpretation that the (system?) malloc merely > prints the vm_malloc message and staggers on somehow ... > > Regards, > John This is the exact error message: *** malloc: vm_allocate(size=9203712) failed (error code=3) *** malloc[489]: error: Can't allocate region Nothing else. No stack trace, NOTHING. maurice From saravanan.d at siemens.com Tue May 10 03:52:52 2005 From: saravanan.d at siemens.com (Saravanan D) Date: Tue, 10 May 2005 13:22:52 +0530 Subject: Exception in Python 2.3.3 Interpreter References: <1114434259.853654.272420@z14g2000cwz.googlegroups.com> Message-ID: "Fredrik Lundh" wrote in message news:mailman.252.1115707861.29826.python-list at python.org... > "Saravanan D" wrote: > > > > > 03 023ffaa4 1e013182 00000000 055b1250 00637470 python23!cmp_outcome(int > > op > > > > = 88026108, struct _object * v = 0x00000001, struct _object * w = > > > > 0x00000000)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880] > > > > 04 023ffb18 1e016ba4 014f3318 00000002 0099f170 > > python23!eval_frame(struct > > > > _frame * f = 0x053f2bfc)+0x542 > > [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c > > > > @ 1965] > > > > 05 023ffb30 1e016a69 0099f170 023ffb7c 00000002 > > > > python23!fast_function(struct _object * func = , > > struct > > > > _object *** pp_stack = , int n = > error>, > > > > int na = , int nk = )+0x94 > > > > > > the above doesn't look very healthy. does your application involve > > > non-standard extensions (including extensions you've written your- > > > self)? does the extensions contain callbacks into Python code? > > > > > > > My application uses extension modules which devliers the callbacks to Python > > Code. Im using SWIG 1.3.19 version to generate relevant python interfaces > > for the C++ code. > > how are you accessing the callbacks? if you're doing that from threads > created at the C++ level, you must make sure that the thread state is > properly set up. see: Callbacks have been called from the threads which are created in C++ code. Before calling the callback, the thread state has been properly set (as per python documentation). The application runs 3 to 4 days continuously with out having any issues. But, crash happens sparadically. (once in a week / once in 4 days ) > do you keep track of the thread state, so that callbacks run in the > same state as they were registered in? > > > > > From pinard at iro.umontreal.ca Sat May 7 12:10:46 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Sat, 7 May 2005 12:10:46 -0400 Subject: Q: The `print' statement over Unicode In-Reply-To: <427cc8b2$0$26179$9b622d9e@news.freenet.de> References: <427cc8b2$0$26179$9b622d9e@news.freenet.de> Message-ID: <20050507161046.GA9912@phenix.progiciels-bpi.ca> [Martin von L?wis] > Fran?ois Pinard wrote: > > > Am I looking in the wrong places, or else, should not the standard > > documentation more handily explain such things? > It should, but, alas, it doesn't. Contributions are welcome. My contributions are not that welcome. If they were, the core team would not try forcing me into using robots and bug trackers! :-) > The algorithm to set sys.std{in,out}.encoding is in > sysmodule.c:_PySys_Init and pythonrun.c:Py_InitializeEx > and goes roughly as follows: > - On Windows, if isatty returns true, use GetConsoleCP and > GetConsoleOutputCP. > - On Unix, if isatty returns true, langinfo.h is present, > CODESET is defined, and nl_langinfo(CODESET) returns a > non-empty string, use that. > - otherwise, .encoding will not be set. Thanks. Your kind explanation, above, should make it, as is, somewhere in the documentation -- until Xah decides to rewrite it, of course! :-). -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From rogerb at rogerbinns.com Tue May 10 02:45:59 2005 From: rogerb at rogerbinns.com (Roger Binns) Date: Mon, 9 May 2005 23:45:59 -0700 Subject: M2Crypto SSL memory leaks - fixes or alternatives ?? References: <1115652793.232733.310800@f14g2000cwb.googlegroups.com> Message-ID: > I notice that M2Crypto (a python wrap of OpenSSL) leaks (haemorrhages) > memory significantly and affects my long running app very badly. > > Does anyone know of fixes to this problem? > > Does anyone recommmend alternatives to M2C ? e.g pyopenssl. If you control both ends of the connection then you can do what I did and switch to SSH. The Python Paramiko library implements it really well. (I ended up doing XML-RPC over SSH). Roger From http Sun May 1 22:03:20 2005 From: http (Paul Rubin) Date: 01 May 2005 19:03:20 -0700 Subject: How to kill a SocketServer? References: <7xwtqj1lh1.fsf@ruckus.brouhaha.com> <7xpswa4wfu.fsf@ruckus.brouhaha.com> <17013.25972.965219.254879@montanaro.dyndns.org> Message-ID: <7xekcq75av.fsf@ruckus.brouhaha.com> Skip Montanaro writes: > def serve_forever(self): > while self.serving: > r,w,e = select.select([self.socket], [], [], self.pause) > if r: > self.handle_request() > > and set self.pause to something short-ish. The select call times out and > the server exits. Ah, good point. Something like this should probably be added to SocketServer.py (optional timeout parameter to serve_forever), or at least the trick should be mentioned in the docs. Thanks. From timr at probo.com Sat May 14 03:11:42 2005 From: timr at probo.com (Tim Roberts) Date: Sat, 14 May 2005 00:11:42 -0700 Subject: Problems with csv module References: Message-ID: "Fredrik Lundh" wrote: > >does the CSV format even support Unicode-encoded data streams? Since there is no RFC or ISO standard for CSV, I'd say the answer was "yes". I just tried it with Excel, which is probably as close as we can get to the canonical csv application. It can read a UCS-16 csv file, but it mishandles it. It doesn't split at the commas. It treats each line as a single cell. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From prabapython at yahoo.co.in Mon May 16 08:45:13 2005 From: prabapython at yahoo.co.in (praba kar) Date: Mon, 16 May 2005 13:45:13 +0100 (BST) Subject: Reg Date string conversion into timestamp function Message-ID: <20050516124514.17075.qmail@web8402.mail.in.yahoo.com> Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type function 1) parsedate function failed if a date string like below format "16-MAY-2005 01:26" 2)parsedate_tz function also failed if a date string is different format if any one find some other date string conversion function kindly let me know ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From arserlom at gmail.com Sat May 14 08:02:03 2005 From: arserlom at gmail.com (arserlom at gmail.com) Date: 14 May 2005 05:02:03 -0700 Subject: Modifying CallTips.py to work with with new-style classes in IDLE. Message-ID: <1116071397.262755.38550@f14g2000cwb.googlegroups.com> When using Idle, Call Tips are floating windows which display function, class, and method parameter and docstring information when you type an opening parenthesis, and which disappear when you type a closing parenthesis. But when you use new-style classes, they don't work fine and don't show the arguments of the __init__ method. There is a topic in this newsgroup (new style classes and an IDLE "grump"), where a solution was given to the problem (in Mar 27 2002): > The solution seems to be simply changing line 115 in CallTips.py (in the > Tools/Idle/ directory) as folows: > > if type(ob)==types.ClassType: > > to > > if type(ob)==types.ClassType or type(ob) == types.TypeType: I've tried it (Python 2.4.1 - IDLE 1.1.1) and it works fine (CallTips was in the \Lib\idlelib directory for me). Why isn't this the default behaviour? Is this the right place to post this? From fredrik at pythonware.com Sun May 1 11:43:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 1 May 2005 17:43:27 +0200 Subject: tkMessageBox dialog help References: <1179elj56ralk70@news.supernews.com> <1114949390.876896.322200@o13g2000cwo.googlegroups.com> Message-ID: Harlin Seritt wrote: > >From what I've seen I'm afraid this is the way it is. If you call an > instance of tkMessageBox and you don't have a 'master' Tk instance > running, it will create its own. > > Still, I'm sure with a bit of voodoo you can hide the self created tk > window while showing the message box. no voodoo needed: just create the root window yourself (root = Tk()), and call the withdraw method on it before you do anything else. From phillip.watts at anvilcom.com Wed May 18 21:27:29 2005 From: phillip.watts at anvilcom.com (phil) Date: Wed, 18 May 2005 20:27:29 -0500 Subject: Tkinter Return/Enter key handling References: Message-ID: <428BEB81.2010107@anvilcom.com> If you are talking Linux there's .Xdefaults Which I had to resort to for tn5250. For Tkinter apps its a LOT easier to just use bind. Win32? dunno. Bob Greschke wrote: > I have a Tkinter Text() widget in a program that the user can type stuff > into. Most of our keyboards have the regular keys with a "Return" key, and > a numeric keypad with an "Enter" key. The Return key generates events with > "" for the keysym, and the Enter key generates events with > "" as the keysym. The Text() widget does a carriage > return/linefeed when the Return key is pressed, but does nothing when the > Enter key is pressed. So I did a > > Text.bind(" > with a suitable > > def Return(e): > TheText.insert(END, linesep) > > But isn't there a way to handle this with some sort of keyboard remapping > thingy?? I'm right on the edge of understanding half of what I read about > Tkinter. :) > > Thanks! > > Bob > > > From jrastrick at student.usyd.edu.au Wed May 18 13:21:40 2005 From: jrastrick at student.usyd.edu.au (Jordan Rastrick) Date: 18 May 2005 10:21:40 -0700 Subject: "End Of Line" Confusion In-Reply-To: <1116399590.659940.204770@g14g2000cwa.googlegroups.com> References: <1116370499.324399.8920@z14g2000cwz.googlegroups.com> <1116396681.298692.289380@g43g2000cwa.googlegroups.com> <1116399590.659940.204770@g14g2000cwa.googlegroups.com> Message-ID: <1116436900.136691.312880@g47g2000cwa.googlegroups.com> If you email the script to me, I'd be happy to take a look at it and see if I come up with the same error (I'm running IDLE on a Windows XP box here, cant remember if the filesystem is FAT or NTFS ;-)) Although as a relative newbie I've never come across it myself, one possible source of such mysterious errors in Python, apparently, is mixing tabs and spaces in your indentation. Its also one of the few factors I can think of that would have been lost in the email-copy-paste process, which could explain why the code snippet works on my machine and not yours. My only other suggestion is to try my personal first rule for fixing mysterious, unusual bugs in small, trivial pieces of code - which is to delete the whole thing and type it out again from scratch. It works surprisingly often. Good luck - Jordan From danb_83 at yahoo.com Sun May 29 12:22:48 2005 From: danb_83 at yahoo.com (Dan Bishop) Date: 29 May 2005 09:22:48 -0700 Subject: how to convert string to list or tuple References: Message-ID: <1117383768.099922.308760@o13g2000cwo.googlegroups.com> Simon Brunning wrote: > On 5/26/05, flyaflya wrote: > > a = "(1,2,3)" > > I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',', > > '2', ',', '3', ')') not (1,2,3) > > Short answer - use eval(). > > Long answer - *don't* use eval unless you are in control of the source > of the string that you are evaluating. Or if you do use eval, don't give it access to any names. >>> import os >>> eval(raw_input(), {}) os.system("rm -rf *") Traceback (most recent call last): File "", line 1, in ? File "", line 0, in ? NameError: name 'os' is not defined From skip at pobox.com Tue May 17 16:06:17 2005 From: skip at pobox.com (Skip Montanaro) Date: Tue, 17 May 2005 15:06:17 -0500 Subject: Python forum In-Reply-To: <87k6lxk51a.fsf@pobox.com> References: <87k6lxk51a.fsf@pobox.com> Message-ID: <17034.20153.201703.465946@montanaro.dyndns.org> John> Web forums do reach a different audience. Maybe python.org should John> have a 'web forum' link to gmane.org's web interface for c.l.py? Any idea if the gmane folks could be convinced to move gmane.comp.python.general to gmane.comp.lang.python so it's with the rest of the programming languages? Skip From phillip.watts at anvilcom.com Wed May 18 18:00:10 2005 From: phillip.watts at anvilcom.com (phil) Date: Wed, 18 May 2005 17:00:10 -0500 Subject: iso_8859_1 mystery/tkinter References: Message-ID: <428BBAEA.4070806@anvilcom.com> > | > s.const['DEG'] = '%c' % (0xb0) > | > But the symbol for degrees, a little circle, produces > | > a vertical bar in Tkinter Text box or Canvas. > t.insert(0.0, u'%c' % 0xb0) > > should do the trick though. > COOL! Thanks, though that seems a little odd. As far as I know %c ignores the sign bit everywhere else, including X11 and Win consoles. But I'll just note it and do it. Thanks again. From evenprimes at gmail.com Tue May 31 15:17:54 2005 From: evenprimes at gmail.com (Chris Cioffi) Date: Tue, 31 May 2005 15:17:54 -0400 Subject: working with pointers In-Reply-To: References: Message-ID: Nope, numbers too. When you do: a = 4 You are storing a reference to the literal 4 in a. >>> a = 4 >>> dir(a) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__ div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', '__getne wargs__', '__hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__', '__lshif t__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__p os__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__redu ce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', ' __rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr __', '__str__', '__sub__', '__truediv__', '__xor__'] >>> Unlike a list, there is no way to alter the interger value of 4. If we go further, and then do something like: >>> b = a >>> b 4 >>> Both a and b refer to the same object, in this case the 4 object. If you want a copy of the object check out the copy module. Chris On 31/05/05, Michael wrote: > > except numbers?? > > "Dave Brueck" wrote in message > news:mailman.299.1117566077.18027.python-list at python.org... > > Michael wrote: > > > sorry, I'm used to working in c++ :-p > > > > > > if i do > > > a=2 > > > b=a > > > b=0 > > > then a is still 2!? > > > > > > so when do = mean a reference to the same object > > > > Always. > > > > > and when does it mean make a copy of the object?? > > > > Never. > > > > -Dave > > > -- > http://mail.python.org/mailman/listinfo/python-list > -- "I was born not knowing and have had only a little time to change that here and there." -- Richard Feynman -------------- next part -------------- An HTML attachment was scrubbed... URL: From lsumnler at uniqueinsuranceco.com Mon May 30 08:17:09 2005 From: lsumnler at uniqueinsuranceco.com (LenS) Date: 30 May 2005 05:17:09 -0700 Subject: Newbie learning OOP In-Reply-To: <429a2379@news.eftel.com> References: <1117374143.284962.3080@z14g2000cwz.googlegroups.com> <429a2379@news.eftel.com> Message-ID: <1117455429.752703.253800@g49g2000cwa.googlegroups.com> You are correct, the code so far is just a simple problem to learn OOP. Oh by the way I don't work for Dept. of Homeland Security just remember "drop those fingernail clipers and step away from those shoes:-) From hancock at anansispaceworks.com Mon May 23 00:24:55 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Sun, 22 May 2005 23:24:55 -0500 Subject: Running a python program during idle time only In-Reply-To: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> References: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> Message-ID: <200505222324.55103.hancock@anansispaceworks.com> On Friday 20 May 2005 08:06 pm, los wrote: > I'm wondering if anyone knows of a way that I could make so that the > program will run at full speed only runs after the computer has been > idle for a while. I've looked at the "nice" command but that's not > exactly what I want. You need to define what "idle" means: Screensavers do this in more than one way, but typically, "idle" means "no user input has occured", in which case you are looking for the time since the last input signal from keyboard or mouse (not sure how to do this off the top of my head, but that's the "screensaver" approach). This is much less meaningful on a multiuser / multiple terminal machine, of course. And it's really nonsense on a machine that is also acting as a server. That's why "nice" seems like a more logical solution for these types of machines. Someone's already mentioned checking the load average, which sounds like a good idea for your application. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From kbk at shore.net Tue May 10 23:43:45 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Tue, 10 May 2005 23:43:45 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200505110343.j4B3hjB1003013@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 332 open (+10) / 2834 closed ( +2) / 3166 total (+12) Bugs : 927 open ( +7) / 4959 closed ( +7) / 5886 total (+14) RFE : 186 open ( +0) / 157 closed ( +1) / 343 total ( +1) New / Reopened Patches ______________________ Feature enhancement for C socket module (2005-05-03) http://python.org/sf/1194378 opened by Heiko Wundram pydoc requires o.__nonzero__() = True (2005-05-03) http://python.org/sf/1194449 opened by Jay T Miller [AST] throw SyntaxError in "from x import y," (2005-05-03) http://python.org/sf/1194895 opened by logistix simple callback system for Py_FatalError (2005-05-05) http://python.org/sf/1195571 opened by m utku in IDLE, assume new text files are python source by default (2005-05-06) http://python.org/sf/1196895 opened by Jeff Shute smarter behaviour for home key in IDLE (2005-05-06) http://python.org/sf/1196903 opened by Jeff Shute change recall in IDLE shell to not overwrite current command (2005-05-06) http://python.org/sf/1196917 opened by Jeff Shute allow using normal indent width in shell in IDLE (2005-05-06) http://python.org/sf/1196946 opened by Jeff Shute _ssl.mak Makefile patch (Win32) (2005-05-07) http://python.org/sf/1197150 opened by Joachim Kessel Add proxies arg to urllib.urlretrieve (2005-05-07) http://python.org/sf/1197207 opened by John Dubery test_locale fix on modern linux (2005-05-07) http://python.org/sf/1197218 opened by Anthony Baxter Cygwin case-sensitive import patch (2005-05-07) http://python.org/sf/1197318 opened by Jason Tishler Patches Closed ______________ Minimal cleanup of run.py (2005-04-26) http://python.org/sf/1190163 closed by kbk Decimal interaction with __rop__ (2005-03-19) http://python.org/sf/1166602 closed by facundobatista New / Reopened Bugs ___________________ parsedate and Y2K (2005-05-02) http://python.org/sf/1194222 opened by Mark Nottingham Minor bug in urllib docs (2005-05-03) http://python.org/sf/1194249 opened by Georg Brandl Reading from a killed shell script with popen* under linux (2005-05-03) http://python.org/sf/1194328 opened by Vinz ImportError: No module named os (2005-05-03) CLOSED http://python.org/sf/1194497 opened by Will L G [AST] Patch [ 1190012 ] should've checked for SyntaxWarnings (2005-05-04) http://python.org/sf/1195576 opened by logistix SystemError: error return without exception set (2005-05-05) http://python.org/sf/1195984 opened by Niraj Bajpai Error: ... ossaudiodev.c, line 48: Missing type specifier (2005-05-05) http://python.org/sf/1196154 opened by Will L G WeakValueDictionary.__init__ is backwards (2005-05-05) http://python.org/sf/1196315 opened by Pavel Pergamenshchik string.rstrip strips more than supposed to in some cases (2005-05-06) CLOSED http://python.org/sf/1196824 opened by Francois Payette trivial bug in error message text (2005-05-06) http://python.org/sf/1196980 opened by Jeff Shute % gives wrong results (2005-05-08) CLOSED http://python.org/sf/1197806 opened by Jonathan Installation path sent to configure (2005-05-09) http://python.org/sf/1197883 opened by Bj?rn Lindqvist time module ignores timezone changes (2005-05-09) CLOSED http://python.org/sf/1198275 opened by David Lambert string.Template not flexible enough to subclass (regexes) (2005-05-09) http://python.org/sf/1198569 opened by Ian Bicking subprocess _active.remove(self) self not in list _active (2005-05-10) http://python.org/sf/1199282 opened by cheops Bugs Closed ___________ SimpleHTTPServer sends wrong c-length and locks up client (2005-04-26) http://python.org/sf/1190580 closed by alexanderweb ImportError: No module named os (2005-05-03) http://python.org/sf/1194497 closed by rhettinger Error in section 4.2 of Python Tutorial (2005-05-02) http://python.org/sf/1194209 closed by rhettinger Error in section 4.2 of Python Tutorial (2005-05-02) http://python.org/sf/1194209 closed by rhettinger string.rstrip strips more than supposed to in some cases (2005-05-06) http://python.org/sf/1196824 closed by goodger % gives wrong results (2005-05-08) http://python.org/sf/1197806 closed by mwh time module ignores timezone changes (2005-05-09) http://python.org/sf/1198275 closed by bcannon calendar.weekheader not found in __all__ (2005-05-02) http://python.org/sf/1193890 closed by rhettinger RFE Closed __________ logging module root logger name (2005-04-27) http://python.org/sf/1190689 closed by vsajip From andreas.lobinger at netsurf.de Fri May 27 04:59:26 2005 From: andreas.lobinger at netsurf.de (Andreas Lobinger) Date: Fri, 27 May 2005 10:59:26 +0200 Subject: Writing a bytecode interpreter (for TeX dvi files) In-Reply-To: <4295776D.2070601@pytex.org> References: <4295776D.2070601@pytex.org> Message-ID: Aloha, Jonathan Fine wrote: > I'm writing some routines for handling dvi files. > In case you didn't know, these are TeX's typeset output. > These are binary files containing opcodes. > I wish to write one or more dvi opcode interpreters. > Are there any tools or good examples to follow for > writing a bytecode interpreter? As far as i know, dvi is a very straight forward format, commands followed by parameters, no conditionals, no loops. For similar designs i used something like the following approach: s = file('a.dvi','r').read() # read complete file to string while s: command = ord(s[0]) if command < 128: #typeset command s = s[1:] elif command = 139: #bop command param = s[:40] #interpret param c = struct.unpack('D',param[:3]) #consume s s = s[41:] else: #undefined command s = s[1:] You can work directly on strings, or convert to a list. If you don't want long if/elif lists, you can use a dict as a dispatcher (python cookbook has an example?). For most of the commands you can use a lookup table for the parameter list length. TeX ?591 claims, that dvi is stricly interpretable from front to end. The description in Tex?585++ can be transcripted to struct definitions easily. Wishing a happy day LOBI From andre.roberge at gmail.com Tue May 31 21:09:02 2005 From: andre.roberge at gmail.com (=?ISO-8859-1?Q?Andr=E9_Roberge?=) Date: Tue, 31 May 2005 22:09:02 -0300 Subject: ANN: Version 0.9 of RUR-PLE Message-ID: Version 0.9 of RUR: a Python Learning Environment has been released. Information about RUR-PLE can be obtained at http://rur-ple.sourceforge.net Note that the project website is slightly out of date. Among the changes in this new version: ***Spanish translation added.* Changed image for language selection to reflect addition. Changed directory structure of lessons. Fixed "non-existent file" problem when changing language with unstranslated lesson file open in browser; the browser will open the default file in the chosen language instead. Changed dialogs (beepers to robot and resize world) to use GridBagSizer for layout as opposed to specific coordinates. Added parameter wx.BUFFER_VIRTUAL_AREA in dc = wx.BufferedPaintDC(self, self.buffer, wx.BUFFER_VIRTUAL_AREA) in world_display.py; this is required to get proper scrolling since wxPython 2.5.4.1. Added SetFocus() when positioning sizer on "Robot: code and learn" page. This gets rid of the unwanted grey background. Changed list of beepers that can be placed at an intersection from 0 ... 15, 16, 17, 18, 19, 20 to 0 ... 15, 20, 40, 60, 80, 99. Removed the "from __future__ import division" command to the interpreter. Since this is not likely to be the default version for a *long* time, it seems a better idea to revert to the default behaviour for the interpreter. TODO: The lesson needs to be updated to reflect this change. World redrawn immediately after selecting a new language, so that the words "streets" and "avenues" are updated right away. Corrected tooltip language setting on speed selection slider. Added possibility to change background colour of robot world through user program. This is to be used in the random maze escape lesson. Changed the 20 robot images so that their background is transparent. Removed obsolete self-testing code in various files as well as redundant import statements. Fixed problem with seemingly random "invalid world file" error. This occured when a robot was removed from the world, and an attempt was made at resetting the world. Added SetFocus() to WorldGui.OnLeftDown(). Somehow, the WorldGUI (i.e. robot world) would no longer get focus as a matter of course when left-clicked. This meant that it was no longer possible to position the robot using the cursor keys. This problem has appeared since I made the switch to wxPython 2.6. From dalke at dalkescientific.com Sun May 1 04:06:39 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Sun, 01 May 2005 08:06:39 GMT Subject: How to kill a SocketServer? References: <7xwtqj1lh1.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > Let's say you have a SocketServer with the threading mix-in and you > run serve_forever on it. How can you shut it down, or rather, how can > it even shut itself down? I looked at CherryPy's server because I know it uses Python's BaseHTTPServer which is derived from SocketServer, and I know it's multithreaded. Turns out I don't know enough about it to make a reasonable summary, unless I do a lot more research. Here's some text from _cphttpserver class PooledThreadServer(SocketServer.TCPServer): allow_reuse_address = 1 """A TCP Server using a pool of worker threads. This is superior to the alternatives provided by the Python standard library, which only offer (1) handling a single request at a time, (2) handling each request in a separate thread (via ThreadingMixIn), or (3) handling each request in a separate process (via ForkingMixIn). It's also superior in some ways to the pure async approach used by Twisted because it allows a more straightforward and simple programming model in the face of blocking requests (i.e. you don't have to bother with Deferreds).""" which means it went a different route. Looks like a request comes in and is put to a work queue. Clients get from it. There's a special work queue item to tell the threads to stop. Andrew dalke at dalkescientific.com From exarkun at divmod.com Fri May 13 09:52:07 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 13 May 2005 13:52:07 GMT Subject: doc tags? In-Reply-To: Message-ID: <20050513135207.15422.800969735.divmod.quotient.36650@ohm> On Fri, 13 May 2005 06:44:46 -0700, Robert Kern wrote: >Larry Bates wrote: >> In python they are called decorators, but I've never had a >> need to use them myself, but then I'm a little old fashioned. > >Decorators only work on function and method definitions. I don't think >that's what Wolfram is referring to. Decorator syntax may only work there. Decorators are a more general concept orthogonal to the '@' syntax, which can be applied to any kind of object. Jp From tzot at sil-tec.gr Thu May 26 17:35:42 2005 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 27 May 2005 00:35:42 +0300 Subject: Encryption with Python? References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com><001301c552db$dd19d3e0$0201a8c0@mcuf7> <6vh881d59bbecnc45fojknt0rohgt27crl@4ax.com> Message-ID: On Tue, 24 May 2005 10:16:15 +0200, rumours say that "Anthra Norell" might have written: >Why whack someone over the head who tries to develop an idea of his own. >Such an approach isn't uncommon to earn extra credit in educational >settings. I would never whack someone over the head (WSOTH) who tries to develop an idea of his own, and never will (intentionally at least --I myself like reinventing the wheel once in a while just to make sure my synapses still work). However I do WSOTH for >>I rolled my own for relatively short sequences, like passwords. The key is >>an integer. To decrypt use the negative encryption key. I consider the >>encryption unbreakable, as it is indistinguishable from a random sequence. So, to be clear, my reason was your declaring that "I consider the encryption unbreakable, as it...", and that is why I actually challenged you to either support the unbreakability of your algorithm by supplying sensitive data for you, or back off and simply say "ok guys, my words were a *little* over the top". That's all. I see you took up the challenge and indirectly replied to my last question, and in good spirit I say you earned a little respect from me, at least for standing up to your words. Now I hope no-one gives a try to your data (for your own sake :) -- TZOTZIOY, I speak England very best. "Be strict when sending and tolerant when receiving." (from RFC1958) I really should keep that in mind when talking with people, actually... From philippe at philippecmartin.com Sun May 29 10:10:16 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sun, 29 May 2005 14:10:16 GMT Subject: Trying to understand pickle.loads withou class declaration References: <3L2me.3465$3D6.2238@newssvr12.news.prodigy.com> <1117368665.235350.54450@g14g2000cwa.googlegroups.com> Message-ID: Thanks, Philippe S?bastien Boisg?rault wrote: > Even > > class A: > pass > > should do the trick. Only the instance attributes are saved by a > pickle, > not the methods or the class itself. The unpickler tries to merge the > saved data and the class/method info that is not saved to recreate > the fully functional instance... but of course this info should still > be available. The unpickler will even import the class from the > appropriate module if necessary. > > If you want your unpickler to manufacture a class for you when > it is not available, you may use the gnosis xml pickler with the > appropriate security ("paranoia") level. > > http://gnosis.cx/download/gnosis/xml/pickle/ > > Cheers, > > Seb From shanna_perkins_02 at hotmail.com Sun May 29 22:55:32 2005 From: shanna_perkins_02 at hotmail.com (lostinpython) Date: 29 May 2005 19:55:32 -0700 Subject: prime number Message-ID: <1117421732.677244.237730@g49g2000cwa.googlegroups.com> I'm having trouble writing a program that figures out a prime number. Does anyone have an idea on how to write it? All I know is that n > 2 is prim if no number between 2 and sqrt of n (inclusivly) evenly divides n. From percivall at gmail.com Mon May 23 16:43:05 2005 From: percivall at gmail.com (Simon Percivall) Date: 23 May 2005 13:43:05 -0700 Subject: overhead of starting threads In-Reply-To: <4291b2f5$0$24496$da0feed9@news.zen.co.uk> References: <4291b2f5$0$24496$da0feed9@news.zen.co.uk> Message-ID: <1116880985.778686.72440@g44g2000cwa.googlegroups.com> How much you gain by starting threads is also determined by what you're doing in those threads. Remember (or learn): In CPython only one thread at a time can execute python code, so depending on your task threading might gain you little. If you're doing I/O or calling functions written in C (and if they release the Global Intepreter Lock [GIL]) you might gain a lot by using threads. As for overhead: profile, profile, profile. You'll have to do sample runs and find your sweet-spot. It all depends on what you're doing in the threads. From gralex1974 at ua.fm Mon May 23 01:53:55 2005 From: gralex1974 at ua.fm (gralex) Date: Mon, 23 May 2005 08:53:55 +0300 Subject: GridCellEditor References: Message-ID: > >>Hi,all! >> >>How i can manually start CellEditor in wxGrid for spicified Cell in grid >>in >>my programm: >> >>mygrid.SetGridCursor(2,3) >>mygrid.MakeCellVisible(2,3) >>#.... starting editing....... ?????????????? >>mygrid.ShowCellEditControl() don't working... >> >>help me, please... >> > Try: > mygrid..EnableCellEditControl(True) Thanks you. It's working... From anandr86 at gmail.com Tue May 3 13:42:43 2005 From: anandr86 at gmail.com (anandr86 at gmail.com) Date: 3 May 2005 10:42:43 -0700 Subject: trouble with lists Message-ID: <1115142163.472256.205930@o13g2000cwo.googlegroups.com> I'm new to python. I tried doing this >>> x = [[]] * 3 >>> print x [ [] [] [] ] >>> x[0].append( 2 ) [ [2] [2] [2] ] I confused with the last line output. I actually expected something like [ [2] [] [] ] Can anyone give me an explanation. help!! From mcdesigns at walla.com Mon May 23 12:28:15 2005 From: mcdesigns at walla.com (Marcus Lowland) Date: 23 May 2005 09:28:15 -0700 Subject: Memory errors with large zip files In-Reply-To: References: <1116609022.526500.317990@g44g2000cwa.googlegroups.com> <1116637462.076589.287880@g47g2000cwa.googlegroups.com> Message-ID: <1116865695.363808.104620@g47g2000cwa.googlegroups.com> Thank for the detailed reply John! I guess it turned out to be a bit tougher than I originally thought :-).... Reading over your links, I think I better not attempt rewriting the zipfile.py program... a little over my head :-). The best solution, from everything I read seems to be calling an unzipper program from a subprocess. I assume you mean using execfile()? I can't think of another way. Anyway, thank you very much for your help, it's been very educational. Best regards, Lorn From martin.witte at gmail.com Sat May 7 12:10:43 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 7 May 2005 09:10:43 -0700 Subject: Shell Commands in Python Code In-Reply-To: References: Message-ID: <1115482243.284015.212550@z14g2000cwz.googlegroups.com> start to take a look at the call function of the subprocess module - see http://docs.python.org/lib/node231.html From ville at spammers.com Wed May 11 09:44:28 2005 From: ville at spammers.com (Ville Vainio) Date: 11 May 2005 16:44:28 +0300 Subject: Interactive shell for demonstration purposes References: <1115814028.259365.98710@g49g2000cwa.googlegroups.com> Message-ID: >>>>> "Brian" == Brian Quinlan writes: Brian> Can anyone recommend a Python interactive shell for use in Brian> presentations? Brian> I've tried ipython but, since it runs inside a console Brian> window, and the console window has a limited number of Brian> selectable fonts, it doesn't work terribly well. Hmm, do you consider the fonts in a console window unreadable? I've given a few presentations using ipython on win32 and it worked alright - but I suppose the projector quality is a factor here... -- Ville Vainio http://tinyurl.com/2prnb From cam.ac.uk at mh391.invalid Mon May 2 19:33:06 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Tue, 03 May 2005 00:33:06 +0100 Subject: python and os.system() failure In-Reply-To: <1115075139.022119.321880@l41g2000cwc.googlegroups.com> References: <1115075139.022119.321880@l41g2000cwc.googlegroups.com> Message-ID: Anthony wrote: > I only have a tempfile object: > > tmp = tempfile.mkstemp(dir="/var/tmp/") Why aren't you using NamedTemporaryFile instead? Using mkstemp adds a lot of complications that are usually unnecessary. > I will try to explicitly call a close() or whatever the syntax is to > finalize the object to deletion by garbage collection. Files created with mkstemp are neither closed nor deleted when they are finalized. I don't see how GC comes into it either. -- Michael Hoffman From news at NOwillmcguganSPAM.com Tue May 17 11:35:55 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 17 May 2005 16:35:55 +0100 Subject: Reading image dimensions with PIL Message-ID: <428a0f5c$0$13769$db0fefd9@news.zen.co.uk> Hi, I'm writing an app that downloads images. It rejects images that are under a certain size - whithout downloading them completely. I've implemented this using PIL, by downloading the first K and trying to create a PIL image with it. PIL raises an exception because the file is incomplete, but the image object is initialised with the image dimensions, which is what I need. It actualy works well enough, but I'm concerened about side-effects - since it seems an unconventional way of working with PIL. Can anyone see any problems with doing this? Or a better method? Thanks, Will McGugan -- http://www.willmcgugan.com "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz" ] ) From Scott.Daniels at Acm.Org Wed May 25 10:10:00 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 25 May 2005 07:10:00 -0700 Subject: python24.zip In-Reply-To: References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> <428faddd$0$26322$9b622d9e@news.freenet.de> <4290dc79$0$9989$9b622d9e@news.freenet.de> Message-ID: <42948097$1@nntp0.pdx.net> Dieter Maurer wrote: > "Martin v. L?wis" writes on Sun, 22 May 2005 21:24:41 +0200: >>... >>>The application was Zope importing about 2.500 modules >>>from 2 zip files "zope.zip" and "python24.zip". >>>This resulted in about 12.500 opens -- about 4 times more >>>than would be expected -- about 10.000 of them failing opens. I'll bet this means that the 'zope.zip', 'python24.zip' would drop you to "about 12500 - 10000 = 2500" failing opens. That should be an easy test: sys.path.insert(0, 'zope.zip') or whatever. If that works and you want to drop even more, make a copy of zope.zip, update it with python24.zip, and call the result python24.zip. --Scott David Daniels Scott.Daniels at Acm.Org From anton.vredegoor at gmail.com Tue May 17 07:33:45 2005 From: anton.vredegoor at gmail.com (Anton Vredegoor) Date: 17 May 2005 04:33:45 -0700 Subject: Python on a public library computer In-Reply-To: <87r7g6rbz0.fsf@pobox.com> References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> Message-ID: <1116329625.869440.110810@z14g2000cwz.googlegroups.com> John J. Lee wrote: > Why not Jython? There's no command prompt! The file menu from IE is also gone. There is a sun Java console but it looks like this: Java(TM) Plug-in: Version 1.4.2_06 Using JRE version 1.4.2_06 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\xxxxx ---------------------------------------------------- c: clear console window f: finalize objects on finalization queue g: garbage collect h: display this help message l: dump classloader list m: print memory usage o: trigger logging p: reload proxy configuration q: hide console r: reload policy configuration s: dump system properties t: dump thread list v: dump thread stack x: clear classloader cache 0-5: set trace level to Thanks for replying anyway! Anton From mwooden at dtptypes.com Fri May 27 08:24:36 2005 From: mwooden at dtptypes.com (Malcolm Wooden) Date: Fri, 27 May 2005 12:24:36 +0000 (UTC) Subject: Strings for a newbie References: <42970d69@news.eftel.com> Message-ID: Sorry John but that don't do it for me. Just get errors comming back "John Machin" wrote in message news:42970d69 at news.eftel.com... > Malcolm Wooden wrote: >> I'm trying to get my head around Python but seem to be failing miserably. >> I use RealBasic on a Mac and find it an absolute dream! But >> Python....UGH! >> >> I want to put a sentence of words into an array, eg "This is a sentence >> of words" >> >> In RB it would be simple: >> >> Dim s as string >> Dim a(-1) as string >> Dim i as integer >> >> s = "This is a sentence of words" >> For i = 1 to CountFields(s," ") >> a.append NthField(s," ",i) >> next >> >> That's it an array a() containing the words of the sentence. >> >> Now can I see how this is done in Python? - nope! >> >> UGH! >> >> Malcolm >> (a disillusioned Python newbie) > > > >>> s = "This is a sentence of words" > >>> a = s.split() > >>> a > ['This', 'is', 'a', 'sentence', 'of', 'words'] > >>> From mauriceling at acm.org Sat May 7 20:45:43 2005 From: mauriceling at acm.org (Maurice LING) Date: Sun, 08 May 2005 10:45:43 +1000 Subject: hard memory limits References: <427c258b.868346285@news.oz.net> <427cdb37.914854991@news.oz.net> Message-ID: Bengt Richter wrote: > On Sat, 07 May 2005 14:03:34 +1000, Maurice LING wrote: > > >>John Machin wrote: >> >>>On Sat, 07 May 2005 02:29:48 GMT, bokr at oz.net (Bengt Richter) wrote: >>> >>> >>> >>>>On Sat, 07 May 2005 11:08:31 +1000, Maurice LING wrote: >>>> >>>> >>>>>It doesn't seems to help. I'm thinking that it might be a SOAPpy >>>>>problem. The allocation fails when I grab a list of more than 150k >>>>>elements through SOAP but allocating a 1 million element list is fine in >>>>>python. >>>>> >>>>>Now I have a performance problem... >>>>> >>>>>Say I have 3 lists (20K elements, 1G elements, and 0 elements), call >>>>>them 'a', 'b', and 'c'. I want to filter all that is in 'b' but not in >>>>>'a' into 'c'... >>>>> >>>>> >>>>> >>>>>>>>a = range(1, 100000, 5) >>>>>>>>b = range(0, 1000000) >>>>>>>>c = [] >>>>>>>>for i in b: >>>>> >>>>>... if i not in a: c.append(i) >>>>>... >>>>> >>>>>This takes forever to complete. Is there anyway to optimize this? >>>>> >>>> >>>>Checking whether something is in a list may average checking equality with >>>>each element in half the list. Checking for membership in a set should >>>>be much faster for any significant size set/list. I.e., just changing to >>>> >>>> a = set(range(1, 100000, 5)) >>>> >>>>should help. I assume those aren't examples of your real data ;-) >>>>You must have a lot of memory if you are keeping 1G elements there and >>>>copying a significant portion of them. Do you need to do this file-to-file, >>>>keeping a in memory? Perhaps page-file thrashing is part of the time problem? >>> >>> >>>Since when was 1000000 == 1G?? >>> >>>Maurice, is this mucking about with 1M or 1G lists in the same >>>exercise as the "vm_malloc fails when allocating a 20K-element list" >>>problem? Again, it might be a good idea if you gave us a little bit >>>more detail. You haven't even posted the actual *PYTHON* error message >>>and stack trace that you got from the original problem. In fact, >>>there's a possible interpretation that the (system?) malloc merely >>>prints the vm_malloc message and staggers on somehow ... >>> >>>Regards, >>>John >> >>This is the exact error message: >> >>*** malloc: vm_allocate(size=9203712) failed (error code=3) >>*** malloc[489]: error: Can't allocate region >> >>Nothing else. No stack trace, NOTHING. >> > > 1. Can you post minimal exact code that produces the above exact error message? > 2. Will you? ;-) > > Regards, > Bengt Richter I've re-tried the minimal code mimicking the error in interactive mode and got this: >>> from SOAPpy import WSDL >>> serv = WSDL.Proxy('http://eutils.ncbi.nlm.nih.gov/entrez/eutils/soap/v1.1/eutils.wsdl' ) >>> result = serv.run_eSearch(db='pubmed', term='mouse', retmax=500000) *** malloc: vm_allocate(size=9121792) failed (error code=3) *** malloc[901]: error: Can't allocate region Traceback (most recent call last): File "", line 1, in ? File "/sw/lib/python2.3/site-packages/SOAPpy/Client.py", line 453, in __call__ return self.__r_call(*args, **kw) File "/sw/lib/python2.3/site-packages/SOAPpy/Client.py", line 475, in __r_call self.__hd, self.__ma) File "/sw/lib/python2.3/site-packages/SOAPpy/Client.py", line 347, in __call config = self.config) File "/sw/lib/python2.3/site-packages/SOAPpy/Client.py", line 212, in call data = r.getfile().read(message_len) File "/sw/lib/python2.3/socket.py", line 301, in read data = self._sock.recv(recv_size) MemoryError >>> When changed retmax to 150000, it works nicely. From tim.leslie at gmail.com Thu May 26 00:46:49 2005 From: tim.leslie at gmail.com (Tim Leslie) Date: Thu, 26 May 2005 14:46:49 +1000 Subject: __init__() not called automatically In-Reply-To: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> Message-ID: On 25 May 2005 21:31:57 -0700, Sriek wrote: > hi, > i come from a c++ background. i ws happy to find myself on quite > familiar grounds with Python. But, what surprised me was the fact that > the __init__(), which is said to be the equivlent of the constructor in > c++, is not automatically called. I'm sure there must be ample reason > for this. I would like to know why this is so? This is my view is more > burden on the programmer. >>> class C: ... def __init__(self): print "Hello" ... >>> c = C() Hello This looks like __init__ being called automatically to me. Are you doing something different? > Similarly, why do we have to explicitly use the 'self' keyword > everytime? http://www.python.org/doc/faq/general.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls > > Every kind of help would be welcome. No worries, Tim > > -- > http://mail.python.org/mailman/listinfo/python-list > From Amitpython5 at aol.com Mon May 23 13:56:14 2005 From: Amitpython5 at aol.com (Amitpython5 at aol.com) Date: Mon, 23 May 2005 13:56:14 EDT Subject: Problems installing SOAPpy. Message-ID: Hello, I'm having some problems installing SOAPpy module on my host, which has python 2.1 First when it attempts it import logging, it complains that classmethod is not defined. When I commented out (import logging), I got a different errror, about missing module thread. Specifically: Traceback (most recent call last): File "setup.py", line 8, in ? from SOAPpy.version import __version__ File "SOAPpy/__init__.py", line 5, in ? from Client import * File "SOAPpy/Client.py", line 57, in ? from Parser import parseSOAPRPC File "SOAPpy/Parser.py", line 10, in ? from wstools.XMLname import fromXMLname File "SOAPpy/wstools/__init__.py", line 6, in ? import WSDLTools File "SOAPpy/wstools/WSDLTools.py", line 16, in ? from XMLSchema import XMLSchema, SchemaReader, WSDLToolsAdapter File "SOAPpy/wstools/XMLSchema.py", line 18, in ? from threading import RLock File "/usr/local/abinitio-V2-13-1/lib/python2.1/threading.py", line 5, in ? import thread ImportError: No module named thread Is there way I can install thread module? Any help will be greatly appreciated. Thanks, Amit. -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin at v.loewis.de Tue May 3 17:50:53 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Tue, 03 May 2005 23:50:53 +0200 Subject: xml.parsers.expat and utf-8 In-Reply-To: <1115135968.071417.42560@z14g2000cwz.googlegroups.com> References: <1115135968.071417.42560@z14g2000cwz.googlegroups.com> Message-ID: <4277f23d$0$31538$9b622d9e@news.freenet.de> dagurp at gmail.com wrote: > I think I've tried all variations possible but I always get errors. > Anyone know what I'm doing wrong? You are passing Unicode strings to Parse. Try byte strings instead. Regards, Martin From jstroud at mbi.ucla.edu Wed May 25 16:04:39 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Wed, 25 May 2005 13:04:39 -0700 Subject: Tkinter Text Question In-Reply-To: References: <200505241547.49091.jstroud@mbi.ucla.edu> Message-ID: <200505251304.39555.jstroud@mbi.ucla.edu> Thank you Fredrik, this worked beautifully. I had no idea about the "@" prefix. Incidentally, I had to change the code to w.index("@%s,%s" % (e.x, e.y)) Maybe the x,y is a python 2.4 thing. I'm still stuck in 2.3. James On Wednesday 25 May 2005 12:18 am, Fredrik Lundh wrote: > w.index("@x,y" % (event.x, event.y)) -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From qwweeeit at yahoo.it Tue May 10 11:05:18 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 10 May 2005 08:05:18 -0700 Subject: Strip white spaces from source In-Reply-To: References: <1115590492.587606.108810@z14g2000cwz.googlegroups.com> <1115664921.611530.85510@f14g2000cwb.googlegroups.com> Message-ID: <1115737518.888653.265640@o13g2000cwo.googlegroups.com> Hi Richie, I did not post my solution because I did not want to "pollute" the pythonic way of programming. Young programmers, don't follow me! I hate (because I am not able to use them...) classes and regular expressions. Instead I like lists, try/except (to limit or better eliminate debugging) and os.system + shell programming (I use Linux). The problem of stripping white spaces from python source lines could be easily (not for me...) solved by RE. Instead I choosed the hard way: Imagine you have a lot of strings representing python source lines (in my case I have almost 30000 lines). Let's call a generic line "sLine" (with or without the white spaces representing indentation). To strip the un-necessary spaces you need to identify the operands. Thanks to the advice of Alex Martelli, there is a parsing method based on tokenize module, to achieve this: import tokenize, cStringIO try: . for x in tokenize.generate_tokens(cStringIO.StringIO(sLine).readline): . . if x[0]==50: . . . sLine=sLine.replace(' '+x[1],x[1]) . . . sLine=sLine.replace(x[1]+' ',x[1]) except tokenize.TokenError: . pass - x[0] is the 1st element of the x tuple, and 50 is the code for OPERAND. (For those who want to experiment on the x tuple, you can print it merely by a "print str(x)". You obtain as many tuples as the elements present in the line). - x[1] (the 2nd element of the x tuple) is the Operand itself. The try/except is one of my bad habits: the program fails if the line is a multiline. Ask Alex... I haven't gone deeper. At the end you have sLine with white spaces stripped... There is yet a mistake...: this method strip white spaces also inside strings. (I don't care...). A last word of caution: I haven't tested this extract from my routine... This small script is part of a bigger program: a cross-reference tool, but don't ask me for that... Bye. From arserlom at gmail.com Sun May 8 16:01:58 2005 From: arserlom at gmail.com (arserlom at gmail.com) Date: 8 May 2005 13:01:58 -0700 Subject: A question about inheritance In-Reply-To: References: <1115579277.999256.269960@f14g2000cwb.googlegroups.com> Message-ID: <1115582518.303610.210000@f14g2000cwb.googlegroups.com> Thanks. Jp Calderone wrote: > On 8 May 2005 12:07:58 -0700, arserlom at gmail.com wrote: > >Hello I have a question about inheritance in Python. I'd like to do > >something like this: > > > > class cl1: > > def __init__(self): > > self.a = 1 > > > > class cl2(cl1): > > def __init__(self): > > self.b = 2 > > > >But in such a way that cl2 instances have atributes 'b' AND 'a'. > >Obviously, this is not the way of doing it, because the __init__ > >definition in cl2 overrides cl1's __init__. > > > >Is there a 'pythonic' way of achieving this? > > class cl2(cl1): > def __init__(self): > cl1.__init__(self) > self.b = 2 > > Jp From theller at python.net Wed May 4 11:58:53 2005 From: theller at python.net (Thomas Heller) Date: Wed, 04 May 2005 17:58:53 +0200 Subject: Q: The `print' statement over Unicode References: Message-ID: Fran?ois Pinard writes: > Hi, people. I hope someone would like to enlighten me. > > For any application handling Unicode internally, I'm usually careful > at properly converting those Unicode strings into 8-bit strings before > writing them out. > > However, this morning, I mistakenly forgot to do so before using one > Unicode string (containing a non-ASCII character) as an argument to > the `print' statement, and I did _not_ get an error. This is rather > surprising to me. I reread the section of the Python reference manual > (version 2.3.4, this machine uses 2.3.3 currently), and it does not say > anything about a special processing for Unicode strings. > > In my understanding, when `print' is given an argument which is not > already a string (I read: 8-bit string), it first gets converted into > a string (I read: calling __str__). But if I call `str()' explicitly, > _then_ I get an error as expected. The question is, why is there no > error if I do not call `str()' explicity? > > For example, given file `question.py' with this contents: > > # -*- coding: UTF-8 -*- > texte = unicode("Fran\xe7ois", 'latin1') > print type(texte), repr(texte), texte > print type(texte), repr(texte), str(texte) > > doing `python question.py' yields: > > u'Fran\xe7ois' Fran?ois > u'Fran\xe7ois' > Traceback (most recent call last): > File "question.py", line 4, in ? > print type(texte), repr(texte), str(texte) > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' \ > in position 4: ordinal not in range(128) > > (last line wrapped for legibility). > > So (trying to be crystal clear), why is the first `print' working over > its third argument, but not the second? How does `print' convert that > Unicode string to a 8-bit string for output, if not through `str()'? > What is missing to the documentation, or to my way of understanding it? AFAIK, print uses sys.stdout.encoding to encode the unicode string. Thomas From could.net at gmail.com Sat May 7 01:43:11 2005 From: could.net at gmail.com (could ildg) Date: Sat, 7 May 2005 13:43:11 +0800 Subject: Found python for delphi new web site In-Reply-To: <1115443739.747455.200590@f14g2000cwb.googlegroups.com> References: <1115443739.747455.200590@f14g2000cwb.googlegroups.com> Message-ID: <311b5ce1050506224361a26ead@mail.gmail.com> I haven't compile the PyScripter IDE project yet. Does it support code-insight? On 6 May 2005 22:28:59 -0700, James wrote: > It has been around for a while now. But I am glad I visited it again. > The new PyScripter IDE is great. They should really announce new > software like these here. > > -- > http://mail.python.org/mailman/listinfo/python-list > From mwooden at dtptypes.com Fri May 27 09:23:19 2005 From: mwooden at dtptypes.com (Malcolm Wooden) Date: Fri, 27 May 2005 13:23:19 +0000 (UTC) Subject: Strings for a newbie References: Message-ID: Yes Sergei, as 3 of the lines are Dim statements, the real code is just 4 lines, a totally logical. It's not the amout of code thats a probelm, it's following the logic and structure thats important. As I said Python.. UGH! Malcolm "Sergei Organov" wrote in message news:d7730r$qrb$1 at n6.co.ru... > "Malcolm Wooden" writes: > >> I'm trying to get my head around Python but seem to be failing miserably. >> I >> use RealBasic on a Mac and find it an absolute dream! But Python....UGH! >> >> I want to put a sentence of words into an array, eg "This is a sentence >> of >> words" >> >> In RB it would be simple: > > Simple?! 7 lines of code for such a trivial task is simple?! > >> Dim s as string >> Dim a(-1) as string >> Dim i as integer >> >> s = "This is a sentence of words" >> For i = 1 to CountFields(s," ") >> a.append NthField(s," ",i) >> next >> >> That's it an array a() containing the words of the sentence. >> >> Now can I see how this is done in Python? - nope! > > from string import split > s = "This is a sentence of words" > a = split(s) > > or, > > s = "This is a sentence of words" > a = s.split() > > or even > > a = "This is a sentence of words".split() > > -- > Sergei. From steven.bethard at gmail.com Thu May 5 14:07:40 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 05 May 2005 12:07:40 -0600 Subject: min max of a list In-Reply-To: <1115259992.558123.189580@g14g2000cwa.googlegroups.com> References: <1115245476.036508.273930@g14g2000cwa.googlegroups.com> <1115259992.558123.189580@g14g2000cwa.googlegroups.com> Message-ID: querypk at gmail.com wrote: > Thanks for that. My version of python does'nt find "groupby". I am > using python 2.3.2. Is there a way I could do it with out using groupby itertools.groupby is in Python 2.4. The docs[1] give a Python equivalent, so if for some reason you can't upgrade to the current version of Python, you can just copy the groupby code from there. STeVe [1]http://docs.python.org/lib/itertools-functions.html#l2h-1379 From kst-u at mib.org Tue May 10 14:58:34 2005 From: kst-u at mib.org (Keith Thompson) Date: Tue, 10 May 2005 18:58:34 GMT Subject: Language documentation ( was Re: Computing Industry shams) References: <1115509201.680334.140840@f14g2000cwb.googlegroups.com> <874qdezh76.fsf@kafka.homenet> <1415322.AzhuxSBQdk@yahoo.com> <1955897.My2EmLpO4s@yahoo.com> <1212926.3xzUY5Pt1A@yahoo.com> <1562690.uMvC404mSK@yahoo.com> Message-ID: alex goldman writes: > Lawrence Kirby wrote: [snip] >> My response talks about relevance, not ambiguity. > > Well, your response was irrelevant. This entire discussion is irrelevant to most, if not all, of the newsgroups to which it's being posted. comp.lang.c, where I'm reading this, is for discussion of the C programming language; I see nothing about C. -- Keith Thompson (The_Other_Keith) kst-u at mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. From peter at engcorp.com Fri May 13 09:10:13 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 May 2005 09:10:13 -0400 Subject: stop a thread safetely In-Reply-To: References: Message-ID: Zunbeltz Izaola wrote: > I have a wxPython application that call makes a thread (with threading > module). In some moment i've to stop the thread but i need to finish a > funtion in the thread before it can stop. How can i achive this? How did you intend to stop the thread in a manner which might be unsafe? (Hint, unless you're doing something unusual, you can't.) -Peter From maxm at mxm.dk Tue May 10 07:56:47 2005 From: maxm at mxm.dk (Max M) Date: Tue, 10 May 2005 13:56:47 +0200 Subject: Regarding Mail sending Module In-Reply-To: References: Message-ID: <4280a0e1$0$253$edfadb0f@dread12.news.tele.dk> praba kar wrote: > Dear All, > In Php we can do all the mailing operations like > sending a text as a message, adding attachment to a > mail, adding additional headers and so on using > Mail_mime class. I want to know like that class or > modules in Python. > I already gone through MimeWriter,smtplib and so > on. But I can't get clear details. so if anyone know > regarding this kindly give me answer You need the 'email' module for reading and writing email messages, and the 'smtplib' module for sending them. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science From tim.peters at gmail.com Tue May 3 20:34:06 2005 From: tim.peters at gmail.com (Tim Peters) Date: Tue, 3 May 2005 20:34:06 -0400 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <874qdjc2lb.fsf@uwo.ca> References: <3dg5isF6qe1nhU1@news.dfncis.de> <1f7befae05043000165448b8d@mail.gmail.com> <1f7befae05050313286dd4a254@mail.gmail.com> <874qdjc2lb.fsf@uwo.ca> Message-ID: <1f7befae05050317344f9c715@mail.gmail.com> [Tim Peters, whines about level 7] [Dan Christensen, gives a huge hint] The first time I looked at it, I thought "hmm, I should use PIL for this". I kept thinking that too -- but for some reason wanted to see if there was a clear way to do it without something that "fancy". I eventually gave up and did the obvious thing (and of course that worked). simple's-good-but-braindead-simple-ain't-always-enough-ly y'rs - tim From mj at zopatista.com Thu May 5 07:34:36 2005 From: mj at zopatista.com (Martijn Pieters) Date: Thu, 05 May 2005 13:34:36 +0200 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <1115268997.066368.208690@o13g2000cwo.googlegroups.com> References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> <8764y29x3m.fsf@uwo.ca> <877jihc7qv.fsf@uwo.ca> <4279366B.6070800@zopatista.com> <1115268997.066368.208690@o13g2000cwo.googlegroups.com> Message-ID: [SNIP me whining then cheering about level 13] Dan Bishop wrote: > You mean there's a hint in that XML-RPC fault? No, there is a hint in level 12. Remember how you could manipulate the URL of the image of level 12 to get to the data file for that level. Now continue that manipulation and don't believe the suggestion about no more evils. *Then* pay close attention to what you find. If you get a 'Not Found' you either didn't pay attention in the previous step and have passed over the hint, or you searched in the wrong direction. Martijn Pieters -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 264 bytes Desc: OpenPGP digital signature URL: From jepler at unpythonic.net Mon May 23 08:23:42 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 23 May 2005 07:23:42 -0500 Subject: Strange behaviour of floating point constants in imported modules In-Reply-To: <4291b2c0$1@news.home.net.pl> References: <4291b2c0$1@news.home.net.pl> Message-ID: <20050523122341.GF18155@unpythonic.net> This may be relevant to the problems you're seeing: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=774665&group_id=5470 The short story, as the tracker item paints it, is that setting LC_NUMERIC to anything other than 'C' can give results like the ones you describe---Python itself should never do this, but third parties code may. A web search for python LC_NUMERIC should turn up more about this topic, probably even some past threads on this mailing list/newsgroup. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From facundobatista at gmail.com Sun May 15 12:09:16 2005 From: facundobatista at gmail.com (Facundo Batista) Date: Sun, 15 May 2005 13:09:16 -0300 Subject: Unique Elements in a List In-Reply-To: <200505091624.39598.jstroud@mbi.ucla.edu> References: <200505091624.39598.jstroud@mbi.ucla.edu> Message-ID: On 5/9/05, James Stroud wrote: > > Is there an easy way to grab the Unique elements from a list? >>> from sets import Set as set >>> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9] >>> for x in set(data): ... print x ... 0.5 0.9 0.6 0.4 0.1 . Facundo Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/ From steve at holdenweb.com Fri May 27 11:27:45 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 27 May 2005 11:27:45 -0400 Subject: CygWin ODBC In-Reply-To: <4296f337$0$38045$5a6aecb4@news.aaisp.net.uk> References: <4296f337$0$38045$5a6aecb4@news.aaisp.net.uk> Message-ID: <42973C71.6030007@holdenweb.com> Simon Faulkner wrote: > Hi All, > > I am new to Cygwin and am hoping that someone here will be able to tell > me how to get ODBC running in Python on Cygwin. > > Maximum gratefullness... > > > Simon There's a trick to this which involves recompiling from source. If you aren't experienced with Unix/Linux this might seem a bit intimidating. The latest version I worked on is mxODBC 2.0.7. If Egenix have released something later it may incorporate these changes. Sorry they aren't "diff -c" format. I also remember the need in the past to rename some ".cpp" files to ".c", but I believe this has now been done in the distributions. regards Steve diff -rc egenix-mx-commercial-2.0.7/mxCOMMERCIAL.py egenix-mx-commercial-2.0.7cygwin/mxCOMMERCIAL.py *** egenix-mx-commercial-2.0.7/mxCOMMERCIAL.py Wed Dec 1 13:10:27 2004 --- egenix-mx-commercial-2.0.7cygwin/mxCOMMERCIAL.py Sat Dec 18 09:56:27 2004 *************** *** 55,61 **** packages = ['mx.ODBC', 'mx.ODBC.Misc'] ! if sys.platform[:3] == 'win': packages[len(packages):] = [ 'mx.ODBC.Windows' --- 55,61 ---- packages = ['mx.ODBC', 'mx.ODBC.Misc'] ! if sys.platform[:3] == 'win' or sys.platform == 'cygwin': packages[len(packages):] = [ 'mx.ODBC.Windows' *************** *** 89,95 **** # ext_modules = [] ! if sys.platform[:3] == 'win': ext_modules[len(ext_modules):] = [ Extension('mx.ODBC.Windows.mxODBC', --- 89,95 ---- # ext_modules = [] ! if sys.platform[:3] == 'win' or sys.platform == 'cygwin': ext_modules[len(ext_modules):] = [ Extension('mx.ODBC.Windows.mxODBC', *************** *** 167,173 **** ] ! if sys.platform[:3] == 'win': data_files[len(data_files):] = [ 'mx/ODBC/Windows/COPYRIGHT', --- 167,173 ---- ] ! if sys.platform[:3] == 'win' or sys.platform == 'cygwin': data_files[len(data_files):] = [ 'mx/ODBC/Windows/COPYRIGHT', -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From usenet at terabytemusic.cjb.net Sat May 21 06:49:51 2005 From: usenet at terabytemusic.cjb.net (DJTB) Date: Sat, 21 May 2005 12:49:51 +0200 Subject: ZODB memory problems (was: processing a Very Large file) Message-ID: <118u4igq47fl9e0@corp.supernews.com> [posted to comp.lang.python, mailed to zodb-dev at zope.org] Hi, I'm having problems storing large amounts of objects in a ZODB. After committing changes to the database, elements are not cleared from memory. Since the number of objects I'd like to store in the ZODB is too large to fit in RAM, my program gets killed with signal 11 or signal 9... Below a minimal working (or actually: it doesn't work because of memory errors) example code with hopefully enough comments: # This was suggested by Tim Peters in comp.lang.python thread # 'processing a Very Large file' # It is to make sure that no two or more copies of the same object # reside in memory class ObjectInterning: def __init__(self): self.object_table = {} def object_intern(self,o): return self.object_table.setdefault(o, o) from sets import Set # An ExtentedTuple is a tuple with some extra information # (hence: 'Extended'). Furthermore, the elements of the tuple are # unique. # As you can see, ExtendedTuple does not inheret from Persistent. # It will not be stored in the root of a database directly, it will # be stored in a Persistent ExtendedTupleTable (see below). class ExtendedTuple(tuple): def __init__(self, els): tuple.__init__(self,els) # This is a set containing other ExtendedTuple objects # which conflicts with self # e.g. if self = ExtendedTuple([1,2,3,4]) and # other = ExtendedTuple([3,4,5]) then self conflicts with # other, because they share one or more elements (in this # case:. 3 and 4) # So, self.conflicts = Set([ExtendedTuple([3,4,5])]) # other.conflicts = Set([ExtendedTuple([1,2,3,4])]) self.conflicts = Set() def __hash__(self): return hash(tuple(self)) def __repr__(self): return 'ExtendedTuple(%s)' % str(list(self)) import ZODB from persistent import Persistent import random # The Persistent ExtendedTupleTable generates and stores a large # amount of ExtendedTuple objects. Since ExtendedTuple contains a # Set with other ExtendedTuple objects, each ExtendedTuple object # may get very large. class ExtendedTupleTable(Persistent): def __init__(self): self.interning = ObjectInterning() # This Set stores all generated ExtendedTuple objects. self.ets = Set() # et(s): ExtendedTuple object(s) # This dictionary stores a mapping of elements to Sets of # ExtendedTuples. # eg: self.el2ets[3] = Set([(1,2,3), (3,4,5), (1,3,9)]) # self.el2ets[4] = Set([(3,4,5), (2,4,9)]) self.el2ets = {} # el: element of an ExtendedTuple object # These dictionaries are here for performance optimizations. # It is being used to prevent billions of hash() # calculations (relatively slow compared to dictionary # lookups) self._v_el2hs = {} # h(s): hash(es) of ExtendedTuple object(s) self._v_h2et = {} self._v_et2h = {} # The keys of el2ets (and thus the elements of the # ExtendedTuple objects) are all in a prespecified range. # In this example: range(200): self.__el_count = 200 # Number of ExtendedTuple objects in this ExtendedTupleTable self.__et_count = 5000 # Start generation of ExtendedTuple objects and calculation of # conflicts for each ExtendedTuple object def calculate_all(self): self.calc_ets() self.calc_el2ets() self.calc_conflicts() def add(self, et_uninterned): et = self.interning.object_intern(et_uninterned) h = self.interning.object_intern(hash(et)) self.ets.add(et) self._v_h2et[h] = et self._v_et2h[et] = h self._p_changed = True def calc_ets(self): # Calculate a large amount of ExtendedTuple objects. # In this example, the tuples are random, the elements of # the tuples are within a prespecified range. # The elements of each tuple are unique. print 'generating %s random ExtendedTuple objects' % self.__et_count for i in xrange(self.__et_count): # Create random tuple with unique elements l = [] for el in xrange(self.__el_count/3): l.append(random.randint(0,self.__el_count-1)) et = ExtendedTuple(tuple(Set(l))) self.add(et) self.__et_count = len(self.ets) def calc_el2ets(self): '''For each el, calculate which et uses that el''' for el in xrange(self.__el_count): print 'calculating all ExtendedTuple objects using', el self.el2ets[el] = Set([ et for et in self.ets if el in et]) self._v_el2hs[el] = Set([ self._v_et2h[et] for et in self.el2ets[el] ]) self._p_changed = True def calc_conflicts(self): '''For each et, calculate the set of conflicting ets''' self.__et_count = len(self.ets) commit_interval = 100 for i, et in enumerate(self.ets): print 'calculating conflicting ExtendedTuple %.2f%%' % ((i+1)*100./self.__et_count) # use the el2et dictionary (faster than 'Cartesian' # comparison of each ExtendedTuple objects) and an # optimization dictionary _v_el2hs to prevent billions # of hash() calculations later on conflicts_h = [ h for el in et for h in self._v_el2hs[el] ] # Make sure each element is unique and store the # result as conflicts Set in the current ExtendedTuple # object conflicts_unique = Set(conflicts_h) - Set([ et ]) et.conflicts_set = Set([ self._v_h2et[h] for h in conflicts_unique ]) self._p_changed = True if i % commit_interval == 0: print 'committing data to database...' # This does NOT seem to work, the memory usage will # increase until all memory + swap is used. Then the # process gets killed... get_transaction().commit(True) get_transaction().commit(True) from ZODB import FileStorage, DB # Open Database storage = FileStorage.FileStorage('/tmp/test_extendedtuples.fs') db = DB(storage) conn = db.open() root = conn.root() name = 'test' if root.has_key(name): del root[name] root[name] = ExtendedTupleTable() rt = root[name] rt.calculate_all() # if needed, commit final changes and close the database get_transaction().commit() conn.close() db.pack() db.close() storage.close() What should I do to make sure RAM is no longer a limiting factor? (in other words: The program should work with any (large) value of self.__range and self.__et_count Because in my case, self.__et_count = 5000 is only a toy example...) I'm now working on a PC with 2.5 GB RAM and even that's not enough! If you think the design of this program is bad, please let me know what you would do to solve this problem (calculating and saving tuples + set of conflicts). The only thing I can't change is that ExtendedTuple inherits from tuple Thanks in advance, Stan. From exarkun at divmod.com Fri May 27 18:30:32 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 27 May 2005 22:30:32 GMT Subject: write to the same file from multiple processes at the same time? In-Reply-To: <7xmzqgnwbq.fsf@ruckus.brouhaha.com> Message-ID: <20050527223032.559.367933371.divmod.quotient.11362@ohm> On 27 May 2005 15:22:17 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> wrote: >Jp Calderone writes: >> >Oh, ok. But what kind of locks does it use? >> >> It doesn't really matter, does it? > >Huh? Sure, if there's some simple way to accomplish the locking, the >OP's act can do the same thing without SQlite's complexity. > >> I'm sure the locking mechanisms it uses have changed between >> different releases, and may even be selected based on the platform >> being used. > >Well, yes, but WHAT ARE THEY?????? Beats me, and I'm certainly not going to dig through the code to find out :) For the OP's purposes, the mechanism I mentioned earlier in this thread is almost certainly adequate. To briefly re-summarize, when you want to acquire a lock, attempt to create a directory with a well-known name. When you are done with it, delete the directory. This works across all platforms and filesystems likely to be encountered by a Python program. Jp From qwejohn at hotmail.com Mon May 23 06:34:09 2005 From: qwejohn at hotmail.com (qwejohn at hotmail.com) Date: 23 May 2005 03:34:09 -0700 Subject: what is addMethod ? In-Reply-To: References: <1116841257.937815.61910@g43g2000cwa.googlegroups.com> Message-ID: <1116844449.826578.245720@g49g2000cwa.googlegroups.com> Thnks, I wrongly took it for a standard method; I found where it is defined (it's part of the project); Tnnks. John From ml at dynkin.com Fri May 20 03:18:16 2005 From: ml at dynkin.com (George Yoshida) Date: Fri, 20 May 2005 16:18:16 +0900 Subject: Shift-JIS to UTF-8 conversion In-Reply-To: <1116536705.864784.163540@o13g2000cwo.googlegroups.com> References: <1116536705.864784.163540@o13g2000cwo.googlegroups.com> Message-ID: PyTJ wrote: > I need to convert a Japanese Shift-JIS CSV file to Unicode UTF-8. > > My machine is a Windows 98 english computer with Python 2.3.4 > > Any hints?. > First, you need to install codecs to support japanese encodings. Python 2.3.* does not support SJIS by default. I'll give you two options. - Japanese Codecs http://www.python.jp/Zope/download/JapaneseCodecs http://ftp.python.jp/pub/JapaneseCodecs/JapaneseCodecs-1.4.10.win32-py2.3.exe - CJKCodecs http://cjkpython.i18n.org/ http://download.berlios.de/cjkpython/cjkcodecs-1.1.win32-py2.3.exe If you only need Japanese support, Japanese Codecs might be handy. On the other hand, CJKCodecs can handle much broader encodings. Aside from that, starting from 2.4, Python ships with CJKCodecs, so I'd recomment CJKCodecs without reservations. -- george From yhdanid at yahoo.com Mon May 16 17:18:43 2005 From: yhdanid at yahoo.com (Obaid R.) Date: 16 May 2005 14:18:43 -0700 Subject: Like Christ PBBUH Prayed References: <1116096706.696830.275140@g44g2000cwa.googlegroups.com> Message-ID: <1116278323.413749.302480@z14g2000cwz.googlegroups.com> THE POSTER vs. CHRIST ===================== For those who follow this frequently re-appearing thread, and the various responses to it, I wish to remind them of the following: 1. There is a detailed response to the claims of the poster here: http://groups-beta.google.com/group/microsoft.public.windowsxp.network_web/browse_thread/thread/526d20b74c0c5389/4416e29e5d258dd6?q=%22Ron+Grossi:+God+is+not+a+man%22&rnum=1#4416e29e5d258dd6 or as a tinyurl: http://tinyurl.com/dagan 2. The poster has yet to respond to the issues raised. 3. The poster seems to be preaching a doctrine that is at odds with what Christ peace and blessings be upon him (PBBUH) is reported to have preached in the Gospels. For one thing, the poster seems to claim that Christ PBBUH was sent to all peoples, when in fact the "no one" in the verse he relies on above is taken out of the gospel's context. The "no one" cannot be understood as "all people" as this would conflict with Christ PBBUH explicit and clear words in Matthew: "But he answered and said, I am not sent but unto the lost sheep of the house of Israel." (Matthew 15: 24) And so unless the poster wants to pursue and preach a line that is in direct contradiction to the explicit and clear preaching of Christ PBBUH, then he too must accept that the "no one" of (John 14: 6) and the "whoever believes in him" of (John 3: 16, more on this verse and book later) actually refer to those lost sheep of the house of Israel only, and only do so in the span of time while Christ's PBBUH walked this earth, not to the people of the Gentiles and all the times past and present. Repeating the claim of the "no one" and the "whoever", so as to claim that Christ PBBUH was sent to all people past and present including those of the Gentiles, from now until the end of time will not help the cause of the poster. For as long as (Matthew 15: 24) is still considered as part of the Gospel then the poster's case is defeated and he is shown to be preaching an Anti- Christ doctrine. Remember that opinions cannot replace scripture. And repetition cannot make falsehood into truth, or vice versa. Secondly, do note that the poster is relying now on the the book of John, which Christian scholars themselves tell us that not only is it anonymous (imagine a court admitting anonymous evidence as proof) but they also proclaim that the book is actually adulterated scripture; and this they do both in words[1] and deeds.[2] LIKE CHRIST PBBUH PRAYED ======================== For those truth seekers reading this, perhaps it is worth it to remind you that Christ PBBUH, whom the poster seems to consider his "Lord", actually prayed to Almighty God! What is most amazing here is not only that the poster is drumming for the worship of a "man" (Acts 2: 22) and "the son of man" (Luke 9: 58), when his own scripture proclaims that "God is not a man ... neither the son of man" (Numbers 23: 19), but he is also calling for the taking as "Lord" a man and a son of man who has prayed and did so in the same manner taught to all the prophets, including Muhammad peace and blessings be upon them all. * "And Abram fell on his face: and God talked with him, saying," (Genesis 17:3) * "Then Abraham fell upon his face, and laughed, and said in his heart, Shall a child be born unto him that is an hundred years old? and shall Sarah, that is ninety years old, bear?" (Genesis 17:17) * "And Moses made haste, and bowed his head toward the earth, and worshipped." (Exodus 34:8) * "And the LORD spake unto Moses and unto Aaron, saying, Separate yourselves from among this congregation, that I may consume them in a moment. And they fell upon their faces, and said, O God, the God of the spirits of all flesh, shall one man sin, and wilt thou be wroth with all the congregation?" (Numbers 16:20-22) * "And he said, Nay; but as captain of the host of the LORD am I now come. And Joshua fell on his face to the earth, and did worship, and said unto him, What saith my Lord unto his servant?" (Joshua 5:14) * "And it came to pass, while they were slaying them, and I was left, that I fell upon my face, and cried, and said, Ah Lord GOD! wilt thou destroy all the residue of Israel in thy pouring out of thy fury upon Jerusalem?" (Ezekiel 9:8) * "And Jehoshaphat bowed his head with his face to the ground: and all Judah and the inhabitants of Jerusalem fell before the LORD, worshipping the LORD." (2 Chronicles 20:18) * "And it came to pass, when I prophesied, that Pelatiah the son of Benaiah died. Then fell I down upon my face, and cried with a loud voice, and said, Ah Lord GOD! wilt thou make a full end of the remnant of Israel." (Ezekiel 11:13) * "And when the disciples heard it, they fell on their face, and were sore afraid." (Matthew 17:6) * "And he (Jesus) went a little farther, and fell on his face, and prayed, saying, O my Father, if it be possible, let this cup pass from me: nevertheless not as I will, but as thou wilt." (Matthew 26:39) IN THE NEWS =========== Here is a quote from the Qur'an, which was part of the news very recently, from Chapter/Sura "The Prophets": "And unto Solomon (We subdued) the wind in its raging. It set by his command toward the land which We had blessed. And of everything We are Aware. "And of the evil ones (subdued We unto him) some who dived (for pearls) for him and did other work, and We were warders unto them. "And Job, when he cried unto his Lord, (saying): Lo! adversity afflicteth me, and Thou art Most Merciful of all who show mercy. "Then We heard his prayer and removed that adversity from which he suffered, and We gave him his household (that he ad lost) and the like thereof along with them, a mercy from Our store, and a remembrance for the worshippers; "And (mention) Ishmael, and Idris, and Dhu'l-Kifl. All were of the steadfast. "And We brought them in unto Our mercy. Lo! they are among the righteous. "And (mention) Dhu'n-Nun, when he went off in anger and deemed that We had no power over him, but he cried out in the darkness, saying: There is no Allah save Thee. Be Thou Glorified! Lo! I have been a wrong-doer. "Then we heard his prayer and saved him from the anguish. Thus we save believers. "And Zachariah, when he cried unto his Lord: My Lord! Leave me not childless, though Thou art the Best of inheritors. "Then We heard his prayer, and bestowed upon him John, and adjusted his wife (to bear a child) for him. Lo! they used to vie one with the other in good deeds, and they cried unto Us in longing and in fear, and were submissive unto Us. "And she who was chaste, therefor We breathed into her (something) of Our Spirit and made her and her son a token for (all) peoples. "Lo! this, your religion, is one religion, and I am your Lord, so worship Me. "And they have broken their religion (into fragments) among them, (yet) all are returning unto Us. "Then whoso doeth some good works and is a believer, there will be no rejection of his effort. Lo! We record (it) for him." (Translation, Qur'an, 21: 81-94) RESOURCES ========= [1] Jackson, H. Latimer: "The Problem of the Fourth Gospel", April 2005, http://www.earlychristianwritings.com/jackson/chapter1.html [2] The word "begotten" is now absent from (John 3: 16) in almost all new revised Bibles. See the Revised Standard Version for one. From michele.simionato at gmail.com Tue May 17 12:58:56 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 17 May 2005 09:58:56 -0700 Subject: Quick Reference from module doc strings. In-Reply-To: References: <1116199904.205240.58300@g49g2000cwa.googlegroups.com> <42880d98$1@nntp0.pdx.net> <1116320306.737808.313530@g44g2000cwa.googlegroups.com> Message-ID: <1116349136.477233.205260@z14g2000cwz.googlegroups.com> Ron Adam: > Sound great! Adding a command line parser, I'm going to add a brief > command line parser to it today, but nothing as elaborate as you have > already. Could you post a part of the output as an example? How is the > index built? For the command line parser, see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278844 Here is an example of output: http://www.phyast.pitt.edu/~micheles/python/ms.html (it is a package called "ms" (as "My Stuff") where I put my utilities). The system works for module of the standard library too, but since most of the time they do not have docstrings in reST format, there are ugly formatting errors. But this is a bug of the standard library, not of my tool ;) For the index: "minidoc" associates a footnote number to every name, and then prints the names in alphabetical order. You can reach the documentation for that name with a click. Michele Simionato From timr at probo.com Mon May 23 02:18:29 2005 From: timr at probo.com (Tim Roberts) Date: Sun, 22 May 2005 23:18:29 -0700 Subject: how to config a comserver in a customize dll? References: Message-ID: <0bt2919dke9qaticnc9fbk6ii60mah68ha@4ax.com> "????????" wrote: >When i use the below code to create a comserver on Windows OS??i find that >the com was configed in the file >python23com.dll,why? if i want to config it in my customize dll,how should i >do? Python is not a compiled language. It does not produce DLLs. The real executable code for a Python COM server is always contained in python23com.dll. The registry will tell the interpreter that is called by python23com.dll where it can find your script. >class TestPythonCom: > _public_methods_ = [ 'SplitString' ] > _reg_progid_ = "TestPythonCom.Application" > # NEVER copy the following ID > # Use "print pythoncom.CreateGuid()" to make a new one. > _reg_clsid_ = "{93D78ABA-1F6C-4B1C-97C7-C3700511415A}" > > def SplitString(self, val): > return val -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From steve at holdenweb.com Mon May 16 08:56:09 2005 From: steve at holdenweb.com (Steve Holden) Date: Mon, 16 May 2005 08:56:09 -0400 Subject: An example in point 2 In-Reply-To: <888ECD77-032C-4B6E-A679-4FDC66FC27B2@mac.com> References: <888ECD77-032C-4B6E-A679-4FDC66FC27B2@mac.com> Message-ID: <42889869.5030708@holdenweb.com> Lee Cullens wrote: > *From: * lee_cullens at mac.com > *Subject: * *RE:** **An example in point 2* > *Date: * May 15, 2005 8:35:01 PM EDT > *To: * postmaster at python.org > > I guess Python is just a cover for this list. Since the holly rollers > can post whatever they want, now the survivalists are chiming in also. > Yet Python content with some harmless vernacular gets kicked. No point > in feeding the idiots that post this garbage so maybe we (as in > interested in Python) should start sending it all to you. > More annoying than the occasionaly spam is the fact that we can't just let it come and go instead of chiming in with funny/intolerant/impatient replies. The signal-noise ration on this group is incredibly high considering its volume. Your own message that didn't make it may have been canned in some mass dumping activity on marginally-scoring posts. Don't take it personally. You have *NO* idea how much spam gets canned every day. There is a specific problem at this time, but we shoud all be grateful to the unsung heroes who work daily to keep c.l.py so free of the annoying spam that many other groups suffer from. regards Steve > ======================================================================================================== > *From: *TheConcernedOne at elsewhere.com > *Date: *May 15, 2005 7:33:38 PM EDT > *To: *python-list at python.org > *Subject: The world is really unstable these days......* > > > We've got a lot to deal with these days. Terrorism, Recession, blah, blah> > > > ======================================================================================================== > > > An example in point. You let the holly rollers clutter up the list, but > this little test message gets blocked. Very inconsiderate and > inconsistent of you. If you can block this then you can block all the > holly roller garbage. > > ======================================================================================================== > *From: * lee_cullens at mac.com > *Subject: * *Re: Jesus said, "..."* > *Date: * May 15, 2005 1:52:43 PM EDT > *To: * python-list at python.org > > The annoying thing about this junk mail is if one receives just a digest > (otherwise the junk mail filter cans it). Funny how one perfectly > innocent word can hold up a post for review, but this sort of thing gets > through every time???? > > Lee C > > > -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From m at m.com Mon May 2 09:11:45 2005 From: m at m.com (monkey) Date: Mon, 2 May 2005 21:11:45 +0800 Subject: Comparision of GUI framworks References: Message-ID: <4276270e$1_1@rain.i-cable.com> wxPython rules ( ; Go to http://wxpython.org for details... "Florian Lindner" ??? news:d554en$rm7$02$1 at news.t-online.com ???... > Hello, > I've read the chapter in the Python documentation, but I'm interested in a a > more in-depth comparision. Especially regarding how pythonic it is and how > well it performs and looks under Windows. > I've some C++ experiences with Qt, so I'm very interested to have PyQt > compared to wxWindows and Tk. How fast does PyQt catches up with the > versiones released from Trolltech? etc.. > > Thx, > Florian From mwm at mired.org Mon May 16 09:22:16 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 16 May 2005 08:22:16 -0500 Subject: Reg Date string conversion into timestamp function References: Message-ID: <861x87b913.fsf@guru.mired.org> praba kar writes: > Dear All, > > I have doubt regarding date string to time > conversion function. In Python I cannot find flexible > date string conversion function like php strtotime. I > try to use following type > function > 1) parsedate function failed if a date string > like below format "16-MAY-2005 01:26" parsedate is documented as trying to parse RFC 2822 dates. Your example isn't one. > 2)parsedate_tz function also failed if a date string > is different format See the above comments for why. > if any one find some other date string conversion > function kindly let me know In my experience, it's not very common to have to deal with arbitrary time/date strings formats. Typically, a source will only provide date strings in one format, so you only have to be able to deal with that format in your application. For instance, all dates in email headers should follow RFC2822, which means the parsedate you found is adequate for any application dealing with email headers. Given the wide variety of date strings possible in the wild, a routine that swallows a such a string and produces a date is going to have to guess what format is being used - and there are formats that can't be told apart for some dates. As such, such a routine isn't very pythonic. With all that said, you can use strptime to buid a date/time parser. If you really need to deal with multiple formats from one source, maybe if you describe your application some help could be provided. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From greg at cosc.canterbury.ac.nz Fri May 27 00:50:57 2005 From: greg at cosc.canterbury.ac.nz (Greg Ewing) Date: Fri, 27 May 2005 16:50:57 +1200 Subject: Pyrex: step in for loop In-Reply-To: <3fmtshF8hj7vU1@individual.net> References: <3fmtshF8hj7vU1@individual.net> Message-ID: <3fnn9vF8busmU1@individual.net> Luis P. Mendes wrote: > I'm trying to improve speed in a module and substituted the pythonic > 'for in range()' for 'for i from min < i < max:' > > But, I need to define a step for the i variable. How can I do it? If you want maximum clarity, I'd suggest using the for-loop to iterate over a contiguous range of integers and an expression that maps the loop variable to whatever you want. If you want the maximum possible speed, it *may* be faster to use a while loop instead and do your own index updating. But profile to make sure. -- Greg Ewing, Computer Science Dept, University of Canterbury, Christchurch, New Zealand http://www.cosc.canterbury.ac.nz/~greg From mauriceling at acm.org Fri May 6 04:24:21 2005 From: mauriceling at acm.org (Maurice LING) Date: Fri, 06 May 2005 18:24:21 +1000 Subject: hard memory limits Message-ID: Hi, I think I've hit a system limit in python when I try to construct a list of 200,000 elements. My error is malloc: vm_allocate (size = 2400256) failed...... Just wondering is this specific to my system or what? Will adding more RAM helps in this case? Thanks and cheers Maurice From piet at cs.uu.nl Thu May 26 09:22:37 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Thu, 26 May 2005 15:22:37 +0200 Subject: What are OOP's Jargons and Complexities? References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> <3584469.Aerji1NdQr@yahoo.com> Message-ID: >>>>> "Tassilo v. Parseval" (TvP) wrote: >TvP> Most often, languages with strong typing can be found on the functional >TvP> front (such as ML and Haskell). These languages have a dynamic typing >TvP> system. What do you mean with: 'Haskell has a dynamic typing system'? -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: piet at vanoostrum.org From jurgenex at hotmail.com Thu May 12 22:55:59 2005 From: jurgenex at hotmail.com (Jürgen Exner) Date: Fri, 13 May 2005 02:55:59 GMT Subject: [perl-python] Range function References: <1115951576.138445.51080@z14g2000cwz.googlegroups.com> Message-ID: <3HUge.14415$nX1.6455@trnddc09> Xah Lee wrote: > Today we'll be writing a function called Range. I don't think so. Unless you meant to write "Today WE'll be writing ...." > The Perl documentation is as follows. Bullshit. The Perl documentation is part of any Perl installation but you didn't link to it anywhere left alone quote it. Actually I'm glad you didn't, it's quite large after all. jue From zunbeltz at gmail.com Tue May 31 03:17:55 2005 From: zunbeltz at gmail.com (Zunbeltz Izaola) Date: Tue, 31 May 2005 09:17:55 +0200 Subject: avl tree References: Message-ID: On Mon, 30 May 2005 21:13:57 +0200, Berthold H?llmann wrote: > > I'm afraid you won't be happy with the code. It's very old and likely > won't compile. We have an inhouse version of this module which > compiles and run on Sparc solaris (32 Bit) and linux x86 with Python > up to 2.4. I fixed some warnigs just today for compilation on Linux > x86_64, it also seems to work on this platform now. Installation is > setup.py based. I'm quite sure we once sent patches to Sam Rushing, > but they never made it into his release. I'll try to publish our > version the next days. Thanks. I will be looking forward to the release. regards, Zunbeltz > > Regards > Berthold From fredrik at pythonware.com Thu May 12 16:56:01 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 12 May 2005 22:56:01 +0200 Subject: Python Polymorphism References: <20050512200045.85674.qmail@web52604.mail.yahoo.com> Message-ID: Carlos Moreira wrote: > Supose that I want to create two methos (inside a > class) with exactly same name, but number of > parameters different: that's known as multimethods, or multiple dispatch. it's a kind of polymorphism; it's not the only way to do it, nor is it the only thing that qualifies as polymorphism. (in OO lingo, polymorphism usually means that a variable can hold objects of different types/classes, and that the language can per- form a given operation on an object without having to know in ad- vance what type/class it belongs to). Python only supports single-dispatch in itself, but you can use the existing mechanisms to implement multimethods in different ways. for some ways to do it, see: http://www.artima.com/weblogs/viewpost.jsp?thread=101605 http://www-106.ibm.com/developerworks/library/l-pydisp.html however, solving your problem is of course trivial; just change > class myClass: > myAttribute = 0 > def myMethod(self): > self.myAttribute += 1 > def myMethod(self, myValue): > self.myAttribute += myValue to class myClass: myAttribute = 0 def myMethod(self, myValue=1): self.myAttribute += myValue and you're done. > I want to use the power of polymorphism to modelate > the problem. the problem you described can be trivially solved with a default argument. maybe you should come up with a more realistic pro- blem? From martin.witte at gmail.com Fri May 6 18:46:19 2005 From: martin.witte at gmail.com (wittempj@hotmail.com) Date: 6 May 2005 15:46:19 -0700 Subject: Reference to self not passed to member function In-Reply-To: References: Message-ID: <1115419579.413239.97130@z14g2000cwz.googlegroups.com> I think it is more clear to rephrase your code as: -#!/usr/bin/env python -class bob(object): - def __init__(self,**kwargs): - print kwargs - for fname,func in kwargs.items(): - setattr(self, fname, lambda *args : func(*args)) - -def doit(): - print "wuzzup?" - - -abob = bob(sayyoudo=doit) - -abob.sayyoudo() outpu is now: martin at ubuntu:~$ ./test.py {'sayyoudo': } wuzzup? martin at ubuntu:~$ so property sayyoudo points to method doit From claird at lairds.us Wed May 11 11:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Wed, 11 May 2005 15:08:03 GMT Subject: pyvm -- faster python References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> Message-ID: <2fi9l2-tft.ln1@lairds.us> In article , Roger Binns wrote: >> could You tell us a bit more about Your motivation to create an >> alternative C-Python interpreter? > >I'd also be curious to know if the performance gains would remain >once it gets fleshed out with things like closures, long numbers, >new style classes and a C library compatibility shim. > >Roger > > And Unicode. And ... From philippe at philippecmartin.com Sat May 28 17:43:08 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 28 May 2005 21:43:08 GMT Subject: String manipulations References: <1117316427.826830.189260@g14g2000cwa.googlegroups.com> Message-ID: Multiply them by 10000 ? Lorn wrote: > I'm trying to work on a dataset that has it's primary numbers saved as > floats in string format. I'd like to work with them as integers with an > implied decimal to the hundredth. The problem is that the current > precision is variable. For instance, some numbers have 4 decimal places > while others have 2, etc. (10.7435 vs 1074.35)... all numbers are of > fixed length. > > I have some ideas of how to do this, but I'm wondering if there's a > better way. My current way is to brute force search where the decimal > is by slicing and then cutoff the extraneous numbers, however, it would > be nice to stay away from a bunch of if then's. > > Does anyone have any ideas on how to do this more efficiently? > > Many Thanks, > Lorn From sjmachin at lexicon.net Wed May 18 22:36:09 2005 From: sjmachin at lexicon.net (John Machin) Date: Thu, 19 May 2005 12:36:09 +1000 Subject: Extracting multiple zip files in a directory References: <1116462658.723097.134390@g43g2000cwa.googlegroups.com> Message-ID: <5vtn81h8qt9mk73etq0r3e02uqsdjf5jo1@4ax.com> On 18 May 2005 17:30:58 -0700, "Lorn" wrote: >I've been working on this code somewhat succesfully, however I'm unable >to get it to iterate through all the zip files in the directory. As of >now it only extracts the first one it finds. If anyone could lend some >tips on how my iteration scheme should look, it would be hugely >appreciated. Here is what I have so far: > >import zipfile, glob, os > >from os.path import isfile >fname = filter(isfile, glob.glob('*.zip')) >for fname in fname: Here's your main problem. See replacement below. > zf =zipfile.ZipFile (fname, 'r') > for file in zf.namelist(): > newFile = open ( file, "wb") > newFile.write (zf.read (file)) > newFile.close() > zf.close() zipnames = filter(isfile, glob.glob('*.zip')) for zipname in zipnames: zf =zipfile.ZipFile (zipname, 'r') for zfilename in zf.namelist(): # don't shadow the "file" builtin newFile = open ( zfilename, "wb") newFile.write (zf.read (zfilename)) newFile.close() zf.close() Instead of filter, consider: zipnames = [x for x in glob.glob('*.zip') if isfile(x)] Cheers, John From franz.steinhaeusler at utanet.at Mon May 2 09:34:03 2005 From: franz.steinhaeusler at utanet.at (Franz Steinhaeusler) Date: Mon, 02 May 2005 15:34:03 +0200 Subject: Which IDE is recommended? References: <426f90ac$1_2@rain.i-cable.com> <9f7v619jhigbtoksslnr88f4idoc6ejvu3@4ax.com> <1115039282.069052.287920@o13g2000cwo.googlegroups.com> Message-ID: On Mon, 02 May 2005 15:29:58 +0200, Franz Steinhaeusler wrote: >3) I think, you meant "Code Completition": >for example you type: os. and with the "." os.chmod, os.chdir, ... >appear in a completition list box. BTW: If it doesn't seem to work: Make sure, to enable it in Options=>Enable Autocompletition. You can also select under Plugin Preferences "Code Completition Enabled by default". For other questions, you are welcome to ask in the tracker or Public Forums. -- Franz Steinh?usler http://drpython.sourceforge.net/ http://mitglied.lycos.de/drpython/ From jerf at jerf.org Wed May 4 14:44:37 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Wed, 04 May 2005 14:44:37 -0400 Subject: How to write this regular expression? References: Message-ID: On Wed, 04 May 2005 20:24:51 +0800, could ildg wrote: > Thank you. > > I just learned how to use re, so I want to find a way to settle it by > using re. I know that split it into pieces will do it quickly. I'll say this; you have two problems, splitting out the numbers and verifying their conformance to some validity rule. I strongly recommend treating those two problems separately. While I'm not willing to guarantee that an RE can't be written for something like ("[A number A]_[A number B]" such that A < B) in the general case, it won't be anywhere near as clean or as easy to follow if you just write an RE to extract the numbers, then verify the constraints in conventional Python. In that case, if you know in advance that the numbers are guaranteed to be in that format, I'd just use the regular expression "\d+", and the "findall" method of the compile expression: Python 2.3.5 (#1, Mar 3 2005, 17:32:12) [GCC 3.4.3 (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> m = re.compile("\d+") >>> m.findall("344mmm555m1111") ['344', '555', '1111'] >>> If you're checking general matching of the parameters you've given, I'd feel no shame in checking the string against r"^(_\d+){1,3}$" with .match and then using the above to get the numbers, if you prefer that. (Note that I believe .match implies the initial ^, but I tend to write it anyways as a good habit. Explicit better than implicit and all that.) (I just tried to capture the three numbers by adding a parentheses set around the \d+ but it only gives me the first. I've never tried that before; is there a way to get it to give me all of them? I don't think so, so two REs may be required after all.) From lycka at carmen.se Tue May 31 07:46:53 2005 From: lycka at carmen.se (Magnus Lycka) Date: Tue, 31 May 2005 13:46:53 +0200 Subject: eric3 question In-Reply-To: References: Message-ID: Gerrit van Dyk wrote: > Try using raw_input() instead of the sys.stdin.readline(). raw_input() > is the preferred way of getting console input. Is it? Guido's "Python Regrets" slides (Google for them) seems to say the opposite. Besides, that's not the problem here... Alexander Zatvornitskiy wrote: > I'am using eric3 IDE under win32 (snapshot 2005-04-10), and have a trouble. I > use this code: > print "enter q to quit, or smthing else to continue" > while not sys.stdin.readline()=="q": > smthing(else) That will actually work in a vanilla Unix Python interpreter if you type q followed by Ctrl-D twice, but I suspect that's not what you intended... The readline method includes the whole line, including the linefeed character if you press q followed by ENTER. If you change it to... while not sys.stdin.readline()=="q\n": ...I guess it will work in eric3. (It works in IDLE then.) You might even want something more robust, such as while not sys.stdin.readline().strip().lower() == "q": In general, your construct makes it a bit difficult for you to debug your own code. If you had written it like below... while True: inp = sys.stdin.readline() if inp == 'q': break smthing(else) # Not that you can use else as a name... ...it would have been trivial to insert "print repr(inp)" which ought to have given you a clue of what was going on... Changes and experiments like that are very easy to do in Python. It beats staring at the code in confusion 99 times out of 100. It's typically much faster than asking on c.l.py, although not educational for as many people... ;) From rbt at athop1.ath.vt.edu Wed May 11 15:36:26 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 11 May 2005 15:36:26 -0400 Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever separated from the love of God in a place called Hell. The Holy Bible descibes Hell as a place of eternal torment, suffering, pain and agony for all those who have rejected Jesus Christ. The good news is that you can avoid Hell by allowing Jesus Christ to save you today. Only then will you have true peace in your life knowing that no matter what happens you are on your way to Heaven. by BluWater0523@yahoo.com In-Reply-To: References: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> Message-ID: don freeman wrote: > The truth is, Jesus should never have torn down the fig tree. He got so > pissed off at the fig tree for not having figs, even though it wasn't > fig season. This was not the action of someone who has even a little > truth and light. > > Imagine if Jesus came back now. I'd hate to see his road rage. > Who is this Jesus you are talking about? Does he know Python or something? What do fig trees have to do with Python and/or Jesus? From tjreedy at udel.edu Wed May 11 19:57:20 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 May 2005 19:57:20 -0400 Subject: Python Args By Reference References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com><1182j1daaepv6f4@corp.supernews.com> <1115787330.723188.295610@f14g2000cwb.googlegroups.com> Message-ID: "ncf" wrote in message news:1115787330.723188.295610 at f14g2000cwb.googlegroups.com... > Example C Code: > #define P(a,b,c,d,e,f,g,h,x,K) \ > { \ > temp1 = h + S3(e) + F1(e,f,g) + K + x; \ > temp2 = S2(a) + F0(a,b,c); \ > d += temp1; h = temp1 + temp2; \ > } > Python Code: > def P(a,b,c,d,e,f,g,h,x,K): > temp1 = h + S3(e) + F1(e,f,g) + K + x > temp2 = S2(a) + F0(a,b,c) > d += temp1; h = temp1 + temp2 Your problem is that you are replacing a C macro, which is inlined and affects the original 'namespace' in which it appears, and which does not have a direct Python equivalent, with a Python function (admittedly slower), which performs its calculation in a separate namespace. So you have to pass the results back to the calling namespace. Simple enough: make the last line of P return d+temp1, temp1+temp2 and the call a4,a8 = P(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) The stuff about mutability and calling conventions is important to learn eventually but seems beside the point for your immediate application. Terry J. Reedy From jjl at pobox.com Tue May 17 15:48:17 2005 From: jjl at pobox.com (John J. Lee) Date: 17 May 2005 19:48:17 +0000 Subject: Python forum References: Message-ID: <87k6lxk51a.fsf@pobox.com> Jonas Melian writes: > I'm going to say a suggestion, why don't you create a forum like the one > of Ruby (http://www.rubyforums.com/)? for the novices this is a great > help, better than a mail list [...] Web forums do reach a different audience. Maybe python.org should have a 'web forum' link to gmane.org's web interface for c.l.py? John From nicolas.lehuen at gmail.com Wed May 25 03:44:48 2005 From: nicolas.lehuen at gmail.com (nicolas.lehuen at gmail.com) Date: 25 May 2005 00:44:48 -0700 Subject: Comparing 2 similar strings? In-Reply-To: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> References: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> Message-ID: <1117007088.255960.87120@o13g2000cwo.googlegroups.com> William Park a ?crit : > How do you compare 2 strings, and determine how much they are "close" to > each other? Eg. > aqwerty > qwertyb > are similar to each other, except for first/last char. But, how do I > quantify that? > > I guess you can say for the above 2 strings that > - at max, 6 chars out of 7 are same sequence --> 85% max > > But, for > qawerty > qwerbty > max correlation is > - 3 chars out of 7 are the same sequence --> 42% max > > (Crossposted to 3 of my favourite newsgroup.) Hi, If you want to use phonetic comparison, here are some algorithms that are reportedly more efficient than Soundex : Double-Metaphone NYSIIS Phonex Of course, phonetic algorithms have a lot of disadvantages, the main one being that they know about one way to pronounce words (usually a rather rigid, anglo-saxon way) which may not be the right way (hence the examples given before for Gaellic surnames). But these ones are far "better" than soundex. Regards, Nicolas Lehuen From piet at cs.uu.nl Tue May 31 17:28:17 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Tue, 31 May 2005 23:28:17 +0200 Subject: The need to put "self" in every method References: <1117554344.938440.54700@g14g2000cwa.googlegroups.com> Message-ID: >>>>> "Fernando M." (FM) wrote: >FM> Hi, >FM> i was just wondering about the need to put "self" as the first >FM> parameter in every method a class has because, if it's always needed, >FM> why the obligation to write it? couldn't it be implicit? >FM> Or is it a special reason for this being this way? There is. Inside a method there are 3 kinds of identifiers: - local ones e.g. parameters and local variables - global ones (actually module-level) - instance variables and methods Because Python has no declarations there must be a different way to indicate in which category an identifier falls. For globals it is done with the 'global' keyword (which actually is a declaration), for instance variables the dot notation (object.name) is used and the rest is local. Therefore every instance variable or instance method must be used with the dot notation, including the ones that belong to the object `itself'. Python has chosen that you can use any identifier to indicate the instance, and then obviously you must name it somewhere. It could have chosen to use a fixed name, like 'this' in Java or C++. It could even have chosen to use a keyword 'local' to indicate local ones and let instance ones be the default. But if instance variable would be implicit, local ones should have been explicit. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: piet at vanoostrum.org From mefjr75 at hotmail.com Sun May 15 01:34:33 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 14 May 2005 22:34:33 -0700 Subject: incorrect(?) shlex behaviour References: <1116102603.247959.284790@g49g2000cwa.googlegroups.com> Message-ID: <1116135273.280659.23590@g47g2000cwa.googlegroups.com> bill wrote: > Consider: > >>> import shlex > >>> shlex.split('$(which sh)') > ['$(which', 'sh)'] > > Is this behavior correct? It seems that I should > either get one token, or the list > ['$','(','which','sh',')'], > but certainly breaking it the way it does is > erroneous. > > Can anyone explain why the string is being split > that way? This may help. http://www.python.org/dev/doc/devel/lib/module-shlex.html This works on Python 2.4: >>> import shlex >>> sh = shlex.shlex('$(which sh)') >>> sh.get_token() '$' >>> sh.get_token() '(' >>> sh.get_token() 'which' >>> sh.get_token() 'sh' >>> sh.get_token() ')' >>> sh.get_token() etc... Python 2.2 and maybe lower: >>> import shlex >>> import StringIO >>> s = StringIO.StringIO('$(which sh)') >>> sh = shlex.shlex(s) >>> sh.get_token() '$' >>> sh.get_token() '(' >>> sh.get_token() 'which' >>> sh.get_token() 'sh' >>> sh.get_token() ')' >>> sh.get_token() etc... Hth, M.E.Farmer From news at NOwillmcguganSPAM.com Tue May 24 18:00:36 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 24 May 2005 23:00:36 +0100 Subject: pygame 1.6 for windows (python2.4) In-Reply-To: <1116969098.442603.193670@g43g2000cwa.googlegroups.com> References: <1116959151.370529.261690@g49g2000cwa.googlegroups.com> <429380c5$0$24449$da0feed9@news.zen.co.uk> <1116969098.442603.193670@g43g2000cwa.googlegroups.com> Message-ID: <4293a405$0$23946$db0fefd9@news.zen.co.uk> bc wrote: > Thanks for the reply, Will... I have been to the site, but I get a "URL > not found error" when I try the pygame 1.6 for python24 link; I guess > I will just keep trying until the HTML is fixed. > Does seem to be broken at the moment. I've uploaded a copy to my server.. http://www.willmcgugan.com/pygame-1.6.win32-py2.4.exe Will -- http://www.willmcgugan.com "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz" ] ) From mefjr75 at hotmail.com Sun May 15 13:12:30 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 15 May 2005 10:12:30 -0700 Subject: A new to Python question In-Reply-To: <4286fffb.215424243@news.oz.net> References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> <4286fffb.215424243@news.oz.net> Message-ID: <1116177150.371043.212050@o13g2000cwo.googlegroups.com> Fredrik and Bengt: Thank you for the time. I will study the docs and play with the shell till this is firm. M.E.Farmer From jean_seb at videotron.ca Tue May 17 13:21:11 2005 From: jean_seb at videotron.ca (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 17 May 2005 13:21:11 -0400 Subject: Problem listing services with wmi In-Reply-To: <9A28C052FF32734DACB0A288A3533991EBB821@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991EBB821@vogbs009.gb.vo.local> Message-ID: <428A2807.1010908@videotron.ca> Hi again Tim, >Well I honestly don't know if this will go any further, >but the following code uses the win32service module from >pywin32 to collect the service information, on the off-chance >that it *won't* fail where WMI does. I can't easily test it >since the script doesn't raise an error on my machine. > > Seems like your hunch was right, the first loop completes correctly. Adding a counter to both loops shows that getting services from win32service.EnumServicesStatus() gets 108 services, and getting them through WMI gets to 87 and then halts with the previously mentioned error : Traceback (most recent call last): File "", line 1, in ? File "G:\Python-2.4\Lib\site-packages\win32com\client\util.py", line 83, in next return _get_good_object_(self._iter_.next()) pywintypes.com_error: (-2147217398, 'OLE error 0x8004100a', None, None) From examining your code I imagine you tried to catch the exception, but it didn't work because the exception is thrown on the "for" line and not when getting the service's Caption property... So it stopped at 87 anyways. And indeed, the "only in win32" list shows 21 entries ( len(win32_names - wmi_names) = 108-87 = 21 ). [...snip code...] ># Not sure if you're running 2.3/2.4 > > Python 2.4 on Windows XP SP2 here. Do you think we're getting anywhere with this? If not, then I'll just use the "win32" method of getting the service list, even though it isn't as pretty. I don't want to waste your time on something that may have more to do with my machine than anything else... But if you want to try and get to the bottom of this, I have no problem with trying out other suggestions. Thanks a lot, just by your small scripts I've already learned a lot more about Python! J-S -- ___________________________________________ Jean-S?bastien Guay jean_seb at videotron.ca http://whitestar02.webhop.org/ From peter at engcorp.com Sat May 14 10:27:21 2005 From: peter at engcorp.com (Peter Hansen) Date: Sat, 14 May 2005 10:27:21 -0400 Subject: Multiple "cmp"s chained one after another In-Reply-To: References: Message-ID: vincent wehren wrote: > "Volker Grabsch" schrieb im > Newsbeitrag news:d64io9$s6o$05$1 at news.t-online.com... > | However, I don't want to sort them the default way. These are birthdays, > | so only the month and day do matter, not the year. E.g.: > | ... > If you don't care about the year, why not just "normalize" the year > to all be the same using the replace method of the date instance? > Something like: > > d1 = datetime.date(2004, 12, 2) > d2 = datetime.date(2001, 12, 3) > d3 = datetime.date(2002, 12, 6) > d4 = datetime.date(1977, 12, 7) > dates =[d1,d2,d3,d4] > datesNorm = [obj.replace(year=1900) for obj in (dates)] > datesNorm.sort() > print datesNorm # etcetera Or just use the .timetuple() method on datetime objects and sort on the 8th element of the 9-element tuple, which is the day-of-the-year. -Peter From erinhouston at gmail.com Mon May 9 12:50:55 2005 From: erinhouston at gmail.com (erinhouston at gmail.com) Date: 9 May 2005 09:50:55 -0700 Subject: Outlook-MAPI In-Reply-To: References: Message-ID: <1115657455.375205.319790@o13g2000cwo.googlegroups.com> This code should help. code import win32com.client olMailItem = 0x0 obj = win32com.client.Dispatch("Outlook.Application") newMail = obj.CreateItem(olMailItem) newMail.Subject = "This works" newMail.Body = "It worked aging\n" newMail.display() V.C.Sekhar wrote: > Hi there, > > Can any one please help in getting me Python-Outlook > programming issue clarified. > > > > I just wanted to do the following using Python: > > 1)Open a New Oulook Mail Window > > 2) Fill the field: to-email address and Write some body to it.(I > DON't want to send it automatically) > > > > That's all. But, I am getting an error when I try to initiate the > MAPI-Session using > > object = win32com.client.Dispatch("Outlook.Application") > > ns = object.GetNamespace("MAPI") > > mapi = win32com.client.dynamic.Dispatch("MAPI.session") > > > > Error I see is : > > File "C:\Program Files\GNU\WinCvs 2.0\Macros\TemplateCvsMacro.py", > line 140, in SendMAPIMail > > mapi = win32com.client.Dispatch("MAPI.session") > > File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", > line 95, in Dispatch > > dispatch, userName = dynamic._GetGoodDispatchAndUserName > (dispatch,userName,clsctx) > > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", > line 91, in _GetGoodDispatchAndUserName > > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", > line 79, in _GetGoodDispatch > > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > > pywintypes.com_error: (-2147221005, 'Invalid class string', None, > None) > > > > Can any one please help me in this regard. > > > > Thanks, > > Sekhar From siona at chiark.greenend.org.uk Wed May 11 10:53:31 2005 From: siona at chiark.greenend.org.uk (Sion Arrowsmith) Date: 11 May 2005 15:53:31 +0100 (BST) Subject: Regarding Mail sending smtplib Module References: Message-ID: <-Ks*ACiOq@news.chiark.greenend.org.uk> praba kar wrote: >Here I want to avoid this line "Received: from unknown >(HELO prabahar.enmail.com) (59.92.13.47) by >mailserver with SMTP; 11 May 2005 10:09:11 -0000 " How >can I do this? . Why python give this line? . Mail >sending Module in php will not give this type line. To quote http://docs.python.org/lib/SMTP-objects.html : "The SMTP[sic] does not modify the message headers in any way." The Received: header is being added by your SMTP server. Goodness knows how PHP avoids it -- direct use of sendmail maybe? >Here I have another doubt Php mail sending module give >MessageId automatically >but python doesn't set that. why? Because "The SMTP[sic] does not modify the message headers in any way." Or, to look at it another way, there are obvious advantages to having message ids created by the client app rather than the library. (OTOH, the library author is more likely to write better id-producing code than the average client app author, but IMHO this is outweighed by the greater utility of having the app do it and the consistency of not having SMTP touch the headers.) If PHP mail adds a message id, that would be consistent with it using sendmail rather than talking directly to the SMTP server. -- \S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become? se bera eadward ofdun hl?ddre heafdes b?ce bump bump bump From webmaster at smallco.com Tue May 24 02:47:47 2005 From: webmaster at smallco.com (Webmaster) Date: Tue, 24 May 2005 02:47:47 -0400 (EDT) Subject: Automatic response to your mail (Error) Message-ID: The automatic reply to this e-mail which you should have received in response to your e-mail to webmaster at smallco.com has not been defined. Please contact postmaster at smallco.com for assistance. From http Wed May 11 01:56:39 2005 From: http (Paul Rubin) Date: 10 May 2005 22:56:39 -0700 Subject: Python Args By Reference References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> <1182j1daaepv6f4@corp.supernews.com> <1115787330.723188.295610@f14g2000cwb.googlegroups.com> <7xbr7igy12.fsf@ruckus.brouhaha.com> <1115790189.005940.158030@f14g2000cwb.googlegroups.com> Message-ID: <7xr7gemhk8.fsf@ruckus.brouhaha.com> "ncf" writes: > As I fail to see how an array could be used in this (my own > stupidity?), would you have any such example? How's this (untested): state = [A,B,C,D,E,F,G,H] magic = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98 ] def P(state, i, magic): a,b,c,d,e,f,g,h = state[i:] + state[:i] temp1 = h + S3(e) + F1(e,f,g) + K + x temp2 = S2(a) + F0(a,b,c) # d += temp1; h = temp1 + temp2 state[(i+3)%8] += temp1; state[(i+7)%8] = temp1 + temp2 for i in range(9): P(state, i, W, magic) Actually this isn't so good. You have to be careful about arithmetic overflow, i.e. do all the additions mod 2**32, so you don't get Python longs. I'll leave that as an exercise. From peter at engcorp.com Thu May 26 07:42:01 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 May 2005 07:42:01 -0400 Subject: Problem in Building a Simple EXE In-Reply-To: References: Message-ID: ParE wrote: > I wrote a small script which I have been trying to > convert to an Executable. I have tried py2exe and > McMillians. Both will convert it just fine but when I > run it on a machine that does not have Python > installed it will run the script twice. Any ideas on > how I may fix this? I think (unless someone else recognizes this problem) that you'll have to explain more about the situation. What does "run twice" really mean? How are you running it (command line, and icon, or what)? Have you tried reducing your script down to the smallest version that still causes the undesirable behaviour? For example, if you use the same techniques to compile, install, and run the following script, does it still "run twice" (whatever that means)? if __name__ == '__main__': print "I'm running now." -Peter From mwm at mired.org Thu May 19 16:40:38 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 19 May 2005 15:40:38 -0500 Subject: Convert from numbers to letters References: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> <1116519193.037429.93560@o13g2000cwo.googlegroups.com> <1116529140.470352.129690@z14g2000cwz.googlegroups.com> Message-ID: <86wtpvymnt.fsf@guru.mired.org> Bill Mill writes: > On 19 May 2005 11:59:00 -0700, rh0dium wrote: >> This is great but backwards... >> >> Ok because you all want to know why.. I need to convert Excel columns >> A2 into , [1,0] and I need a simple way to do that.. >> >> ( The way this works is A->0 and 2->1 -- Yes they interchange -- So >> B14 == [13,1] ) > > why didn't you say this in the first place? > > def coord2tuple(coord): > row, col = '', '' > alpha = 'abcdefghijklmnopqrstuvwxyz'.upper() > pairs = [''.join((x,y)) for x in alpha for y in [''] + [z for z in alpha]] > pairs = sorted(pairs, key=len) > coord = coord.upper() > for c in coord: > if c in alpha: > row += c > else: > col += c > return (int(col)-1, pairs.index(row)) That seems like the long way around. Python can search strings for substrings, so why not use that? That gets the search loop into C code, where it should be faster. from string import uppercase def coord2tuple2(coord): if len(coord) > 1 or uppercase.find(coord) < 0: raise ValueError('coord2tuple2 expected a single uppercase character, got "%s"' % coord) return uppercase.index(coord) + 1 Without the initial test, it has a buglet of return values for "AB" and similar strings. If searching uppercase twice really bothers you, you can drop the uppercase.find; then you'll get less informative error messages if coord2tuple2 is passed single characters that aren't in uppercase. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From Sebastien.Boisgerault at gmail.com Wed May 11 13:28:28 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 11 May 2005 10:28:28 -0700 Subject: Importing modules In-Reply-To: <1115816747.292060.292200@o13g2000cwo.googlegroups.com> References: <1115816747.292060.292200@o13g2000cwo.googlegroups.com> Message-ID: <1115832507.991053.55270@o13g2000cwo.googlegroups.com> qwwee... at yahoo.it wrote: [...] > In some cases there is a further complication: module importing through > an indirect mechanism, like: exec "from " + xxx + " import *". Don't do that. Please ;). If you need too import some modules based on the module name, stored in a string, consider the using __import__ (http://www.python.org/doc/2.4/lib/built-in-funcs.html). It's a bit tricky but you may define your own help functions on top of it. > A part the fact that I have not understood the "real" difference > between import and from ... import (or also from... import *), >>> a = exp(1.0) # does not work >>> import math >>> e = math.exp(1.0)# works >>> e = exp(1.0) # does not work >>> from math import exp >>> e = exp(1.0) # works >>> from math import * >>> e = exp(1.0) # works >>> o = sqrt(1.0) # works too > is it > possible to re-build the application in only one chunck? > This is only to better understand the application's structure, in order > to implement a flow chart tool. uh ? From philippe at philippecmartin.com Sat May 28 17:07:07 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 28 May 2005 21:07:07 GMT Subject: Getting value of radiobutton trouble References: <3fs17rF9b8edU1@news.dfncis.de> Message-ID: <%35me.194$Dq7.159@newssvr11.news.prodigy.com> Hi, I think your second call to Tk() does it: this works although the look is different: from Tkinter import * class GetVariant: def __init__(self): self.root = Tk() self.mainframe = Frame(self.root,bg="yellow") self.mainframe.pack(fill=BOTH,expand=1) self.firstframe = Frame(self.mainframe,bg="red") self.firstframe.pack(side=BOTTOM,expand=1) global v v = StringVar() self.radiobutton = Radiobutton(self.firstframe,text= "Variant 1", variable=v, value="Variant 1") self.radiobutton.pack(side=TOP,anchor=W) self.radiobutton.select() self.radiobutton = Radiobutton(self.firstframe,text= "Variant 2", variable=v, value="Variant 2") self.radiobutton.pack(side=TOP,anchor=W) self.radiobutton = Radiobutton(self.firstframe,text= "Variant 3", variable=v, value="Variant 3") self.radiobutton.pack(side=TOP,anchor=W) self.secondframe = Frame(self.mainframe,bg="blue") self.secondframe.pack() self.var = Button(self.secondframe,text="What Variant",command=self.call) self.var.pack(expand=1,side=BOTTOM) def call(self): self.variant = v.get() print 'Input => "%s"' % self.variant class OneButton: def __init__(self): self.root = Tk() Button(self.root,text="click me",command=self.getvar).pack() def getvar(self): a=GetVariant() d = OneButton() d.root.mainloop() VK wrote: > Hi! > What I'm missing in following code? Cannot get the values of > radiobuttons. Starting only one class (GetVariant), it works. When I put > two classes together, it doesn't. > Regards, VK > > from Tkinter import * > class GetVariant: > def __init__(self): > self.root = Tk() > self.mainframe = Frame(self.root,bg="yellow") > self.mainframe.pack(fill=BOTH,expand=1) > > self.firstframe = Frame(self.mainframe,bg="red") > self.firstframe.pack(side=BOTTOM,expand=1) > > global v > v = StringVar() > self.radiobutton = Radiobutton(self.firstframe,text= "Variant > 1", variable=v, value="Variant 1") > self.radiobutton.pack(side=TOP,anchor=W) > self.radiobutton.select() > self.radiobutton = Radiobutton(self.firstframe,text= "Variant > 2", variable=v, value="Variant 2") > self.radiobutton.pack(side=TOP,anchor=W) > self.radiobutton = Radiobutton(self.firstframe,text= "Variant > 3", variable=v, value="Variant 3") > self.radiobutton.pack(side=TOP,anchor=W) > > > > self.secondframe = Frame(self.mainframe,bg="blue") > self.secondframe.pack() > self.var = Button(self.secondframe,text="What > Variant",command=self.call) > self.var.pack(expand=1,side=BOTTOM) > > > > def call(self): > self.variant = v.get() > print 'Input => "%s"' % self.variant > > class OneButton: > def __init__(self): > self.root = Tk() > Button(self.root,text="click me",command=self.getvar).pack() > def getvar(self): > a=GetVariant() > > d = OneButton() > d.root.mainloop() From fredrik at pythonware.com Thu May 19 03:13:11 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 19 May 2005 09:13:11 +0200 Subject: ElementTree and xsi to xmlns conversion? References: Message-ID: Matthew Thorley wrote: > Why does ElementTree.parse convert my xsi to an xmlns? because it is a namespace prefix, perhaps? > When I do this > from elementtree import ElementTree > > # Sample xml > mgac =""" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://www.chpc.utah.edu/~baites/mgacML > http://www.chpc.utah.edu/~baites/mgacML/mgac.xsd"> name="Si4H"> > """ > > xml = ElementTree.fromstring(mgac) > ElementTree.tostring(xml) > > I get this > ' xmlns:ns0="http://www.chpc.utah.edu/~baites/mgacML" > xmlns:ns1="http://www.w3.org/2001/XMLSchema-instance"> name="Si4H" />' > > The xsi is gone and has been replaced by a new xmlns, which is also NOT > inherited by the child elements. the xsi is a namespace prefix, which maps to a namespace URI. the child element doesn't use that namespace, so there's no need to add a namespace declaration. > ElementTree.tostring(xml.getchildren()[0]) > > ' xmlns:ns0="http://www.chpc.utah.edu/~baites/mgacML" />' > > If some one could please explain where I'm off I'd really appreciate it. > I need to use xsi: to validate the document are you sure? the prefix shouldn't matter; it's the namespace URI that's important. if you're writing code that depends on the namespace prefix rather than the name- space URI, you're not using namespaces correctly. when it comes to namespaces, elementtree forces you to do things the right way: http://www.jclark.com/xml/xmlns.htm (unfortunately, the XML schema authors didn't understand namespaces so they messed things up: http://www.w3.org/2001/tag/doc/qnameids-2002-04-30 to work around this, see oren's message about how to control the namespace/prefix mapping. in worst case, you can manually insert xsi:-attributes in the tree, and rely on the fact that the default writer only modifies universal names) From gduzan at bbn.com Thu May 12 16:10:36 2005 From: gduzan at bbn.com (Gary D. Duzan) Date: Thu, 12 May 2005 20:10:36 GMT Subject: Python features References: <1115536911.106882.166230@z14g2000cwz.googlegroups.com> Message-ID: <0LOge.1436$bm5.654@newsread3.news.atl.earthlink.net> In article , Peter Dembinski wrote: > > >On Sun, 08 May 2005 10:02:42 +0200, Andr?? Roberge > wrote: > >> Imperative programming languages are the most commonly used languages. >> Examples of this type of language are C, C++, Ada, Fortran, Algol, Java, >> Python, Perl, and so on. > >How about lambda construction? Isn't Python imperative language that >includes some functional mixins? > >I mean -- can you say Python is fully imperative language? I don't know that "fully imperative" is necessarily meaningful. We could say that Python supports statements which don't rebind a variable to a value, but that doesn't seem helpful. You can do things without side effects in Python, and you can use things in a functional style like map, but the overall language more closely reflects an imperative style, so we call it an imperative language. Gary Duzan BBN Technologies From pdemb at gazeta.pl Mon May 23 08:09:27 2005 From: pdemb at gazeta.pl (Peter Dembinski) Date: Mon, 23 May 2005 14:09:27 +0200 Subject: Access lotus notes using Python References: Message-ID: <87r7fyywi0.fsf@hector.domek> "Sateesh" writes: > Hi, > Is it possible to access Lotus notes using Python? Can anyone > provide me some pointers? jython + LN Java bindings may be usable -- http://www.peter.dembinski.prv.pl From __peter__ at web.de Wed May 4 17:04:37 2005 From: __peter__ at web.de (Peter Otten) Date: Wed, 04 May 2005 23:04:37 +0200 Subject: How do you convert a string obj to a file obj? References: <42790d0c$0$79465$14726298@news.sunsite.dk> Message-ID: Matthew Thorley wrote: > Ok you're right. tarfile.open expects a string; the path to the file > open. I thought that I had tried it with open file objects but I guess I > was mistaken. tarfile.open()? That would have been important information in your initial post. It would have been even better to just type help(tarfile.open) at the interactive prompt (remember that next time). Reading the documentation for you: """ open([name[, mode [, fileobj[, bufsize]]]]) ... If fileobj is specified, it is used as an alternative to a file object opened for name. """ So try passing value.file as the third parameter. Peter From skip at pobox.com Mon May 2 12:22:33 2005 From: skip at pobox.com (Skip Montanaro) Date: Mon, 2 May 2005 11:22:33 -0500 Subject: How to kill a SocketServer? In-Reply-To: <1115046280.413931.16970@g14g2000cwa.googlegroups.com> References: <7xwtqj1lh1.fsf@ruckus.brouhaha.com> <7xpswa4wfu.fsf@ruckus.brouhaha.com> <17013.25972.965219.254879@montanaro.dyndns.org> <7xekcq75av.fsf@ruckus.brouhaha.com> <1115046280.413931.16970@g14g2000cwa.googlegroups.com> Message-ID: <17014.21449.421677.445431@montanaro.dyndns.org> >> > set self.pause to something short-ish. The select call times out >> > and the server exits. Guido> [Paul Rubin] >> Ah, good point. Something like this should probably be added to >> SocketServer.py (optional timeout parameter to serve_forever), or at >> least the trick should be mentioned in the docs. Guido> I like this idea, and perhaps you all could come up with some Guido> more useful APIs in this area... I stumbled on a somewhat cleaner way to do this using socket timeouts: class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer): pause = 0.25 allow_reuse_address = True def __init__(self, server_address, RequestHandlerClass): SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass) self.socket.settimeout(self.pause) self.serving = 1 ... def serve_forever(self): while self.serving: self.handle_request() As far as my simple testing went (a trivial little xmlrpc server exposing only "noop" and "exit" methods), the above worked fine. I was mildly surprised that I didn't have to catch socket.timeout exceptions. Skip From teamuhlig at gmail.com Thu May 26 17:38:08 2005 From: teamuhlig at gmail.com (john67) Date: 26 May 2005 14:38:08 -0700 Subject: Problem accessing Python Business Forum Message-ID: <1117143488.353879.151600@g43g2000cwa.googlegroups.com> Every time I attempt to look at the Python Business Forum (www.python-in-business.org), I encounter an error that starts like this: Site Error An error was encountered while publishing this resource. KeyError Sorry, a site error occurred. Traceback (innermost last): Module ZPublisher.Publish, line 150, in publish_module.... I thought it might be temporary, but I have encountered the same error for a couple of weeks. I know other parts of the Python Business Forum site work since I have been sent links to the European PyCon 2005 for example. Is there another URL for the Python Business Forum that has a site map or something similar? I am guessing someone has had and been given an answer to the problem I am having, but I have not been able to locate it. I did a search of this forum, but almost all references to "Python Business Forum" were in Dr. Dobbs postings. Thanks for your help, John From xah at xahlee.org Sun May 15 12:30:19 2005 From: xah at xahlee.org (Xah Lee) Date: 15 May 2005 09:30:19 -0700 Subject: Range function In-Reply-To: References: <1115951576.138445.51080@z14g2000cwz.googlegroups.com> <1116150732.766217.258960@g47g2000cwa.googlegroups.com> Message-ID: <1116174619.859728.297260@g14g2000cwa.googlegroups.com> the previous posted solutions are badly botched. Here's a better solution. Any further correction will appear on the website instead. (http://xahlee.org/tree/tree.html) Similar change needs to be made for the Perl code... Java code will come tomorror. By the way, the code from me are not expected to be exemplary. These are exercises for all, also as a intro to functional programing to industry programers. Also, later on there will be non-trivial problems. # -*- coding: utf-8 -*- # Python # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 import math; def Range(iMin, iMax=None, iStep=None): if (iMax==None and iStep==None): return Range(1,iMin) if iStep==None: return Range(iMin,iMax,1) if iMin <= iMax and iStep > 0: if (isinstance(iStep,int) or isinstance(iStep,long)): return range( iMin, iMax+1, iStep) else: result=[] for i in range(int(math.floor((iMax-iMin)/iStep))+1): result.append( iMin+i*iStep) return result if iMin >= iMax and iStep < 0: if (isinstance(iStep,int) or isinstance(iStep,long)): return range( iMin, iMax-1, iStep) else: result=[] for i in range(int(math.floor((iMin-iMax)/-iStep))+1): result.append( iMin+i*iStep) return result # raise error about bad argument. To be added later. # test print Range(5,-4,-2) # Thanks to Peter Hansen for a correction. Xah xah at xahlee.org ? http://xahlee.org/ From peter at engcorp.com Tue May 10 23:14:06 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 May 2005 23:14:06 -0400 Subject: Need a little parse help In-Reply-To: References: Message-ID: Delaney, Timothy C (Timothy) wrote: > Peter Hansen wrote: >>In my opinion, if the code fits on one screen and just reads stuff >>from one file and, maybe, writes to another, you can safely and with > ^^^^^^ >>clean conscience ignore Mike's advice (but remember it for later!). > > Remember, finalisers are not called when Python exits. So if you don't > explicitly close the file you are *writing* to, it may not be flushed > before being closed (by the OS because the process no longer exists). Ouch... I'd forgotten/never heard that I guess. If that's true and all there is to the matter, I would think we'd all have encountered numerous times when our output files were not properly written. Yet I've never encountered this situation myself, nor heard of anyone else ever having trouble as a result of it. What gives? -Peter From jepler at unpythonic.net Mon May 23 07:45:09 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Mon, 23 May 2005 06:45:09 -0500 Subject: Shift-JIS to UTF-8 conversion In-Reply-To: <1116573375.686710.251250@g49g2000cwa.googlegroups.com> References: <1116536705.864784.163540@o13g2000cwo.googlegroups.com> <1116573375.686710.251250@g49g2000cwa.googlegroups.com> Message-ID: <20050523114506.GE18155@unpythonic.net> On Fri, May 20, 2005 at 12:16:15AM -0700, rbsharp at gmx.de wrote: > Hello, I think the answer is basically correct but shift-jis is not a > standard part of Python 2.3. Ah, I was fooled --- I tested on Python 2.3, but my packager must have included the codecs you went on to mention. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From m at m.com Sun May 1 06:45:16 2005 From: m at m.com (monkey) Date: Sun, 1 May 2005 18:45:16 +0800 Subject: wxPython: ansi or unicode? References: <42749af0$1_3@rain.i-cable.com> Message-ID: <4274b338$1_3@rain.i-cable.com> Many Thanks ( : > > Hi all, which should be install? Really confused @@... > > Unicode. > > > Is that mean unicode version used for programming in language other than > > English? > > No. The Unicode version allows the underlying wxWidgets GUI toolkit to > use Unicode text. You want this. > > On certain platforms, older versions of the unicode version of wxPython > were somewhat unstable. I believe this has been largely resolved, and > the ANSI versions will be going away. > > I may have some details wrong. If you want an authoritative answer, ask > on the wxPython lists. > > -- > Robert Kern > rkern at ucsd.edu > > "In the fields of hell where the grass grows high > Are the graves of dreams allowed to die." > -- Richard Harter > From usenet at terabytemusic.cjb.net Wed May 18 08:38:15 2005 From: usenet at terabytemusic.cjb.net (DJTB) Date: Wed, 18 May 2005 14:38:15 +0200 Subject: processing a Very Large file References: Message-ID: <118mdpnji58bvb6@corp.supernews.com> Robert Brewer wrote: > DJTB wrote: >> I'm trying to manually parse a dataset stored in a file. The >> data should be converted into Python objects. >> > > The first question I would ask is: what are you doing with "result", and > can the consumption of "result" be done iteratively? > > The processed data in result is input data for a real-time simulator. The simulator chooses the data it needs from 'result', this should be done fast, so all data in 'result' should always be accessable in O(1) -- and as fast as possible. That's why everything should be in RAM. In other words: the data in 'result' is not being 'consumed' sequentially and the data is not thrown away after 'consumption' by the simulator process. Furthermore, after loading the file, 'result' is read-only. By the way, 'result' is now a dict: 1. Read raw data from file 2. Process data (convert to Python Object, do some preprocessing) 4. Add mapping hash(path_tuple) --> Object to 'result' dictionary 5. Start simulation process: while True: a. given a hash, retrieve the Object from the dictionary b. use the Object for further calculations Jeffrey Maitland wrote: > > Well 1 thing I would do is use the for loop for the file itself. > Now the thing is that you are reading a file into a list now the more you > add to the list the more memit will take (as you know). What I this is > doing is a line by line read instead of opening the entire file and then > reading it. not sure if it is due to the fact that you are creating sets > in addition to the list. Something else that might help (not 100% sure if > it will is using the del option on the sets after they are put into the > list. That way it is no longer being used by memory then overwritten > instead it frees the memory first. Not sure if any of this will help > exactly but I hope it does. > > from time import time > from sets import Set > from string import split > file_name = 'pathtable_ht.dat' #change the name to avoid confusion > result = [] > start_time = time () > #Note there is no open(file_name,r) needed here. What if the data file is gzipped? (I'm now using gzip to keep the data file small, the added time is neglectable compared to the time needed for the actual processing) > for line in file(file_name): > splitres = line.split() > tuple_size = int(splitres[0])+1 > path_tuple = tuple(splitres[1:tuple_size]) > conflicts = Set(map(int,splitres[tuple_size:-1])) > # do something with 'path_tuple' and 'conflicts' > # ... do some processing ... > result.append(( path_tuple, conflicts)) > del(conflicts) # freeing the mem > del(tuple) # by deleting these 2 objects. > I'm not a Python memory specialist, but does del immediately release/free the memory to the OS? I thought it was impossible to let Python immediately release memory. By the way, does anyone know if there's a profile-like module to keep track of memory usage per object? Thanks in advance, Stan. From brian at zope.com Tue May 10 09:48:15 2005 From: brian at zope.com (Brian Lloyd) Date: Tue, 10 May 2005 09:48:15 -0400 Subject: Announce: Python for .NET 1.0 RC1 released Message-ID: Hi all - I'm happy to announce the release of Python for .NET 1.0 RC1. You can download it from: http://www.zope.org/Members/Brian/PythonNet Highlights of this release: - Implemented a workaround for the fact that exceptions cannot be new-style classes in the CPython interpreter. Managed exceptions can now be raised and caught naturally from Python - Implemented support for invoking methods with out and ref parameters. Because there is no real equivalent to these in Python, methods that have out or ref parameters will return a tuple. The tuple will contain the result of the method as its first item, followed by out parameter values in the order of their declaration in the method signature. - Fixed a refcount problem that caused a crash when CLR was imported in an existing installed Python interpreter. - Added an automatic conversion from Python strings to byte[]. This makes it easier to pass byte[] data to managed methods (or set properties, etc.) as a Python string without having to write explicit conversion code. Also works for sbyte arrays. Note that byte and sbyte arrays returned from managed methods or obtained from properties or fields do *not* get converted to Python strings - they remain instances of Byte[] or SByte[]. - Added conversion of generic Python sequences to object arrays when appropriate (thanks to Mackenzie Straight for the patch). - Added a bit of cautionary documentation for embedders, focused on correct handling of the Python global interpreter lock from managed code for code that calls into Python. - PyObject.FromManagedObject now correctly returns the Python None object if the input is a null reference. Also added a new AsManagedObject method to PyObject, making it easier to convert a Python-wrapped managed object to the real managed object. - Created a simple installer for windows platforms. All known bugs have also been fixed - thanks to all who have sent in issue reports and patches for past releases. At this point, the only thing I plan to do before a 1.0 final is fix any new issues and add to the documentation (probably including a few specific examples of embedding Python for .NET in a .NET application). Enjoy! ;) Brian Lloyd brian at zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com From timothy.williams at nvl.army.mil Wed May 25 09:31:57 2005 From: timothy.williams at nvl.army.mil (timothy.williams at nvl.army.mil) Date: 25 May 2005 06:31:57 -0700 Subject: changing build order for SWIG extensions Message-ID: <1117027917.483536.25940@g49g2000cwa.googlegroups.com> Hi all. How do I tell distutils to run build_ext before build_py when I try to do a 'python setup.py build' ? I have a C extension using SWIG, and when I build with setup.py, build_py runs on the current module.py file before swig creates/recreates it. I got around it by just putting in another call to setup for the py_module, but if I try to create a bdist, the second call to setup over writes the first w/o the _module.so file. (bottom of setup.py) # build extension module setup (name = 'OTB_libs', version='1.0', author="Tim Williams", packages=['OTB_libs'], package_dir={'OTB_libs':''}, ext_modules=[Extension('OTB_libs._OTB_libs', sources=['OTB_libs.i'], include_dirs=INCLDIRS, library_dirs=LIBDIRS, libraries=liblist, extra_compile_args=['-malign-double'], swig_opts=swig_opts ) ] ) #this needs to be built after the extension is since OTB_libs.py is #generated by SWIG setup (name='OTB_libs', version='1.0', author="Tim Williams", py_modules=['OTB_libs.OTB_libs'], package_dir={'OTB_libs':''} ) Am I stuck with just calling running 'python setup.py build' twice? Thanks for any help. From aurora00 at gmail.com Wed May 25 22:11:14 2005 From: aurora00 at gmail.com (aurora) Date: Wed, 25 May 2005 19:11:14 -0700 Subject: Problem redirecting stdin on Windows Message-ID: On Windows (XP) with win32 extension installed, a Python script can be launched from the command line directly since the .py extension is associated with python. However it fails if the stdin is piped or redirected. Assume there is an echo.py that read from stdin and echo the input. Launching from command line directly, this echos input from keyboard: echo.py But it causes an error if the stdin is redirected echo.py References: <1117300484.637674.97430@f14g2000cwb.googlegroups.com> Message-ID: <_OidnR_p3_ZELAXfRVn-sQ@comcast.com> Benji York wrote: > I'll extrapolate from your message that you want to get the values of > the dict in sorted order. If so, here's how: > > >>> d = {'a': 1, 'b': 2, 'c':3} > >>> d > {'a': 1, 'c': 3, 'b': 2} > >>> v = d.values() > >>> v > [1, 3, 2] > >>> v.sort() > >>> v > [1, 2, 3] Or in Python 2.4: py> d = {'a': 1, 'b': 2, 'c':3} py> sorted(d.values()) [1, 2, 3] From ivoras at fer.hr Tue May 3 11:05:45 2005 From: ivoras at fer.hr (Ivan Voras) Date: Tue, 03 May 2005 17:05:45 +0200 Subject: Py2Exe security In-Reply-To: <117f3lk633rbs87@corp.supernews.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> <1115129613.564775.21660@g14g2000cwa.googlegroups.com> <117f3lk633rbs87@corp.supernews.com> Message-ID: Grant Edwards wrote: > On 2005-05-03, mahasamatman wrote: >>password = pasword.decode("base64") > > That will delay the attacker for a few minutes. True, but a script kiddie that only knows about the 'strings' program will be forever baffled :) Though deprecated, I think the enigma cipher (rotor) is still present in python - it could find its use in simple cases like this. From foo at bar.org Tue May 10 05:05:51 2005 From: foo at bar.org (stasz) Date: Tue, 10 May 2005 11:05:51 +0200 Subject: Advice needed on __del__ References: <427ffa0d$1@nntp0.pdx.net> Message-ID: On Mon, 09 May 2005 22:49:06 -0300, Andr? Roberge wrote: > Scott David Daniels wrote: >> Andr? Roberge wrote: >> >>>... Each time I refresh the screen, I could >>>force that call, then check to see if Evil has been >>>destroyed by Python, which would give me the information >>>I need to destroy Evil_twin behind the scene myself - >>>which is what I am really after. Wouldn't it be better if the robots draw themselfs onto the canvas? That way you don't have to worry about deletion, a robot would only draw itself when he's has to. So perhaps it's an idea to delegate the drawing of stuff to the objects themself rather then in the 'visibleworld' class. > However (famous last words follow...) I feel it's not going to bite me > this time. The main reason is that, when Evil is gone, before the > screen gets updated, lots of drawing calls and wxYield() calls are made, > so that __del__ has lots of time to get called. Your relying on something that *will* bite you, the question is rather *when* will it bite you :-) IMHO, the approach to rely on Python to do your dirty work and then checks if it's done seems a bit VB to me :-) Stas Zytkiewicz From mwm at mired.org Sat May 7 23:11:03 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 07 May 2005 22:11:03 -0500 Subject: New Python regex Doc References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113856843.023012.165500@l41g2000cwc.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> <1115423751.016177.250650@o13g2000cwo.googlegroups.com> <1115444726.627426.172260@g14g2000cwa.googlegroups.com> <1115508491.462229.294020@o13g2000cwo.googlegroups.com> Message-ID: <86hdhes988.fsf@guru.mired.org> "Xah Lee" writes: > Let me expose one another fucking incompetent part of Python doc, in > illustration of the Info Tech industry's masturbation and ignorant > nature. What you actually expose is your own ignorance. > Note: ???In other words, the "|" operator is never greedy.??? > > Note the need to inject the high-brow jargon ???greedy??? here as a > latch on sentence. Actually, greedy is a standard term when dealing with regular expression matching. Anyone who's done even a little work with regular expressions - which is pretty much all I've done, as I prefer to avoid them - will know what it means. > ???never greedy???? What is greedy anyway? > > ???Greedy???, when used in the context of computing, describes a > certain characteristics of algorithms. When a algorithm for a > minimizing/maximizing problem is such that, whenever it faced a choice > it simply chose the shortest path, without considering whether that > choice actually results in a optimal solution. Except that's not the *only* meaning for greedy in a computing context. That's what it means when you're talking about a specific kind of problem solving algorithm. Those algorithms have *nothing* to do with regular expressions, so this definition is irrelevant. After doing a google for "regular expression greedy", the second match starts with the text: By default, pattern matching is greedy, which means that the matcher returns the longest match possible. Now, it can be argued that the term ought not to be used, except that it's a standard term with a well-known meaning, and exactly describes the behavior in question. You can argue that it ought to be defined. The problem is, you can't explain things to a rock. You have to assume some basic level of understanding. In particular, documentation on a regular expression package should explain *how to use the package*, not what regular expressions are, and the terminology associated with them. As I've suggested before, what's really needed is a short tutorial on regular expressions in general. That page could include a definition of terms that are unique to regular expressions, and the re package documentation could link the word greedy to that definition. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From cal_2pac at yahoo.com Thu May 19 17:16:45 2005 From: cal_2pac at yahoo.com (cal_2pac at yahoo.com) Date: 19 May 2005 14:16:45 -0700 Subject: How to receive events (eg. user mouse clicks) from IE In-Reply-To: <428cf5a9$1_1@spool9-west.superfeed.net> References: <1116476411.853695.235670@g14g2000cwa.googlegroups.com> <428c3cbe$1_1@spool9-west.superfeed.net> <1116529345.146032.91880@f14g2000cwb.googlegroups.com> <428cf5a9$1_1@spool9-west.superfeed.net> Message-ID: <1116537405.495521.252570@f14g2000cwb.googlegroups.com> Thanks for your prompt responses and the code. However, when I run the code I get com error d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) File "C:\Python23\lib\site-packages\win32com\client\__init__.py", line 199, in __getattr__ return getattr(self._obj_, attr) File "C:\Python23\lib\site-packages\win32com\client\__init__.py", line 455, in __getattr__ return self._ApplyTypes_(*args) File "C:\Python23\lib\site-packages\win32com\client\__init__.py", line 446, in _ApplyTypes_ return self._get_good_object_( com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147467259), None) I am a newbie to python(started coding a few months ago). This appears to be a fairly common error when COM objects are not hooked up properly. Though I have not been able to find a solution or the reason for this. Thanks again for the explanation.All the information that I had acquired now seems to fall into place. I was not aware about doc_mod.HTMLAnchorEvents. Where can I find more documentation about this? Roger Upole wrote: > Here's a few more lines that hook the document's onactivate event. > > import win32com.client > > ie_mod=win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' > ,0, 1, 1) > doc_mod=win32com.client.gencache.EnsureModule('{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}' > ,0 ,4, 0) > class IE_Events(ie_mod.DWebBrowserEvents2): > def OnNavigateComplete2(self, pDisp, URL): > print 'OnNavigateComplete2:', URL > > class Doc_Events(doc_mod.HTMLAnchorEvents): > def Ononactivate(self): > print 'onactivate', self.activeElement.outerHTML > > ie=win32com.client.DispatchWithEvents('InternetExplorer.Application',IE_Events) > ie.Visible=1 > ie.Navigate('http://www.google.com') > > d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) > > Roger > > > wrote in message > news:1116529345.146032.91880 at f14g2000cwb.googlegroups.com... > > Hi > > Thanks for the response and for the code. > > However, I want to trap events like mouse click on the HTML document > > loaded by the web browser control. The code mentioned below provides > > events from the web browser control. I need to find out on which > > particular HTML tag did the user click for example. > > How do I find that out? There should be some way to refer to a document > > from a given web browser control and start receiving events from it > > > > > > Roger Upole wrote: > >> The two you'll need to run makepy for are Microsoft Internet Controls > > and > >> Microsoft HTML object Library. If you run them manually, you should > > be > >> able to look at the generated code to get the guids. > >> Here's a minimal example: > >> > >> import win32com.client > >> > >> > > ie_mod=win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}',0, > > > >> 1, 1) > >> class IE_Events(ie_mod.DWebBrowserEvents2): > >> def OnNavigateComplete2(self, pDisp, URL): > >> print 'OnNavigateComplete2:', URL > >> > >> > > ie=win32com.client.DispatchWithEvents('InternetExplorer.Application',IE_Events) > >> ie.Visible=1 > >> ie.Navigate('http://www.google.com') > >> > >> hth > >> Roger > >> > >> > >> wrote in message > >> news:1116476411.853695.235670 at g14g2000cwa.googlegroups.com... > >> >I am trying to trap events from internet explorer eg. when user > > clicks > >> > on an html link - I need to get notified for that event. > >> > > >> > After looking through the newgroups / internet and reading through > >> > various sections in programming python on win32 - I understand that > >> > this can be done using DispatchWithEvents. > >> > I have also referred to discussions on comp.lang.python > >> > > > http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/a3c502d06412a5f8/0ee3083e71316da7?q=dispatchwithevents&rnum=43#0ee3083e71316da7 > >> > > >> > and > >> > > >> > > > http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1da0668794851296/5bcec1fda216c598?q=dispatchwithevents&rnum=19#5bcec1fda216c598 > >> > > >> > So far - none of the newgroups postings report that IE events were > >> > trapped successfully (at least I could not find any). However, > > there is > >> > enough evidence that it can be done. > >> > My problems at the moment: > >> > a) The examples use early binding. However, I cannot get Python > > makepy > >> > to generate the code to force makepy process at run time - since > > COM > >> > makepy utility that I invoke from python win 32 does not have any > > entry > >> > for internet explorer. > >> > I tried to find the CLSID for IE > > 3050F613-98B5-11CF-BB82-00AA00BDCE0B > >> > but I get an exception > >> > b) Also one of the examples suggest that following code should work > >> > > >> >> mod = EnsureModule(...) > >> > > >> >> class MyEvents(mod.IDocumentEvents): > >> >> # your methods here.... > >> > > >> >> handler = MyEvents(ie.document) > >> > > >> >> # handler should start recieving events. > >> > > >> > however, what CLSID is to be used in EnsureModule... . I tried with > > a > >> > few but I always get the error 'NoneType' object has no attribute > >> > 'IDocumentEvents' > >> > > >> > > >> > An example that 'works' will be very useful > >> > > >> > >> > >> > >> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet > > News==---- > >> http://www.newsfeeds.com The #1 Newsgroup Service in the World! > > 120,000+ Newsgroups > >> ----= East and West-Coast Server Farms - Total Privacy via Encryption > > =---- > > > > > > > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- > http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups > ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From sjmachin at lexicon.net Wed May 11 20:23:44 2005 From: sjmachin at lexicon.net (John Machin) Date: Thu, 12 May 2005 10:23:44 +1000 Subject: Problems with csv module References: <17026.15830.303909.792010@montanaro.dyndns.org> Message-ID: On Wed, 11 May 2005 14:08:08 -0500, Skip Montanaro wrote: > > >> Based on the requests I've seen here and on the csv at mojam.com mailing > >> list, it appears people are certainly generating CSV files which > >> contain Unicode- encoded data. > > Fredrik> in what encodings? > >I've seen hints about iso-8859-1/iso-8859-15 and mention that Excel 2000 >supports utf-8. I have Excel 2002 and have done some experimentation. It "supports" utf-8 only to the extent that most times it doesn't mangle the data (i.e. you can save it again without loss); you just can't make any sense out of what's on the screen. Specifically: open a file with CSV extension: Excel assumes blindly that it's encoded according to your locale (e.g. cp1252). open a file with TXT extension: Excel gives you the option of specifying which one of a large number of *legacy* encodings -- yes, that's correct, utf-* are not on the list! NOTE: the above applies even if you have a utf-8-encoded BOM at the start of the file. This behaviour appears to be Excel-specific; MS Word, Wordpad and even the humble Notepad recognise the utf-8-encoded BOM and display sensibly (with a Unicode font, of course). > Whether Excel can dump csv files in utf-8 or not, I don't >know, though I'd suppose so. Unfortunately, your supposition is incorrect. There is no way of specifying the encoding directly. The nearest available options are: (1) csv : encoded in your locale-specific legacy encoding. "illegal" characters are silently replaced by "?" on Windows and (I deduce) underscore on a Macintosh. (2) text : ditto (3) Unicode text: utf-16 -- it *does* subsequently open these correctly i.e. silently detects the encoding and displays properly. From fraca7 at free.fr Wed May 25 09:34:59 2005 From: fraca7 at free.fr (fraca7) Date: Wed, 25 May 2005 15:34:59 +0200 Subject: Linuz Python Module using PythonC/ API In-Reply-To: References: Message-ID: <42947f02$0$6549$626a14ce@news.free.fr> David a ?crit : > [snip] > CC=g++ So actually your 'initutm' is '_Z7initutmv' for the linker. Try building with gcc instead, or declaring extern "C" PyMODINIT_FUNC initutm(void); or something like that. From fredrik at pythonware.com Thu May 5 13:48:02 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 5 May 2005 19:48:02 +0200 Subject: Does the Python/C interface support Queue objects? References: <1115309235.972498.155650@f14g2000cwb.googlegroups.com> Message-ID: "scott.manton at gmail.com" wrote: > A little background. I made a C dll that sets up a thread for > collecting data from an NI data aquisition card. The thread builds a > list and passes the list to to python via a callback, then python puts > them in the Queue. I would prefer to put the data in the Queue from > the C thread for efficiency, and then monitor the Queue from python. the Queue type is implemented in Python, so you won't gain much by skipping the callback. but if you insist, you can use the abstract API to manipulate the queue object: http://docs.python.org/api/object.html res = PyObject_CallMethod(queue, "put", "O", object); ... check error status ... Py_DECREF(res); From mahs at telcopartners.com Tue May 3 16:12:46 2005 From: mahs at telcopartners.com (Michael Spencer) Date: Tue, 03 May 2005 13:12:46 -0700 Subject: Sequences in list In-Reply-To: <1115146849.029539.85310@o13g2000cwo.googlegroups.com> References: <1115063524.407859.273070@o13g2000cwo.googlegroups.com> <1115146849.029539.85310@o13g2000cwo.googlegroups.com> Message-ID: temp at mclift.fsnet.co.uk wrote: > Hi Michael, > > Thanks for a quick response, I appreciate it. I will have to get back > to you tomorrow, as I can't check what you've given me right now. I > presume the fact that you mention the word note in your code you have > realised that I'm trying to search for musical sequences. Yes, I thought that was the most likely application I tried to > put my problem across in the way I did, not mentioning music, so as not > to confuse the matter. So simply put, I'm checking a list for musical > sequences, without having any idea as to how they might be formed. > What I put together does not yet address the general problem. In particular, it looks only at groups that start at positions that are an integral multiple of their length i.e., 3-tuples starting only at 0,3,6,9... If you really want to look for repetition of any sequence anywhere, then you would need a small modification to the make_groups function: def make_groups(sequence, n, anywhere = False): """return groups of length n from sequence. bool: anywhere False: look only at positions n*i for i = 1,2,3... True: return every (overlapping sequence) of length n Usage: >>> list(make_groups(s1,3)) [['a', 'b', 'c'], ['b', 'c', 'd'], ['c', 'd', 'e']] >>> list(make_groups(s1,3,anywhere = True)) [['a', 'b', 'c'], ['b', 'c', 'b'], ['c', 'b', 'c'], ['b', 'c', 'd'], ['c', 'd', 'c'], ['d', 'c', 'd'], ['c', 'd', 'e']] >>> """ length = len(sequence) if (length % n) and not anywhere: raise ValueError, "Sequence length %s is not multiple of %s"\ % (length, n) for i in xrange(0, length-n+1, anywhere or n): yield sequence[i:i+n] and a corresponding tweak to the compare_forms: def compare_forms(sequence, anywhere = False): """test whether all groups of a sequence have the same form""" for length in (4,3,2): # look for longest match first forms = {} try: for group in make_diffs(make_groups(sequence, length, anywhere)): forms[group] = forms.get(group,0)+1 print forms except ValueError: # raised if the sequence is not a multiple of length pass >>> compare_forms(s1, anywhere = True) {(0, 6, 0, 1): 2, (0, 1, 2, 1): 2, (0, 1, 0, 1): 2} {(0, 1, 2): 3, (0, 1, 0): 2, (0, 6, 0): 2} {(0, 1): 6, (0, 6): 2} >>> Other questions - are your search sequences really limited to 4 notes? How long are the pieces you are searching? Do you not need to care about note lengths, only pitches. Are you really (as I inferred from your examples) looking only at a 7-tone scale etc... etc... Anyway, I'd be happy to discuss this on-list or off. Michael From lambacck at gmail.com Thu May 26 23:58:12 2005 From: lambacck at gmail.com (Chris Lambacher) Date: Thu, 26 May 2005 23:58:12 -0400 Subject: dirrection for simple record keeping app. In-Reply-To: <1117154519.350682.59340@z14g2000cwz.googlegroups.com> References: <1117154519.350682.59340@z14g2000cwz.googlegroups.com> Message-ID: As much as I hate to suggest anything Microsoft, you would probably save yourself a lot of work by using MS Access. That is what it is designed for. That said mySQL is probably a bit of a sledgehammer solution to the problem. If you want a database, you might want to look at SQLite. Is is pretty lightweight has python bindings and runs out of a file. pyGTK is one good option. wxWidgets is another. pyGTK tends to be a bit more unix centric while wxWidgets is more Windows centric. pyGTK is nicer to program in, but wxWidgets will give you more of what you need. Printing in Windows is hard (one of the advantages of MS Access is that it will take care of that for you) but wxWidgets apparently has a printing framework that you could use. Of course if you are already familliar with HTML and javascript, CGI route is a good one. It is easy to get a decent user interface set up pretty quickly with CGI and printing is taken care of by the browser. Multiuser is taken care of almost automatically. The main disadvantage is you need a web server and a connection to the web server whenever you want to use your system. That should get you going, -Chris On 26 May 2005 17:41:59 -0700, nephish wrote: > Hey there, > i have been spending some time learning python. i do enjoy it so. > Heres the deal. i need some dirrection advice. > i have a friend that wants me to set up a customer database for him. > Easy stuff like name, phone number, email address. and current status. > he also wants to be able to print this stuff out. > Heres the deal. He runs windows xp. > how could i write something to help him out ? i thought of glade, since > its gtk and gtk can use a windows runtime.... i also thought of making > something web-based and doing this with cgi scripts. but what would be > easier to learn.... using a database like mysql, or writing text files > and reading them to retrieve the info. The scripting itself could just > be a simple dictionary... so........ > any suggestions? > thanks > > -- > http://mail.python.org/mailman/listinfo/python-list > -- Christopher Lambacher lambacck at computer.org From gigi-s at bigfoot.com Tue May 31 03:46:01 2005 From: gigi-s at bigfoot.com (Gigi) Date: Tue, 31 May 2005 00:46:01 -0700 Subject: __getattribute__ and __getattr__ In-Reply-To: References: Message-ID: <429C1639.9050204@bigfoot.com> Terry Reedy wrote: > "Gigi" wrote in message > news:d7dgd4$29v$1 at sea.gmane.org... > >>Hi, >>In the Python documentation regarding __getattribute__ (more attribute >>access for new style classes) it is mentioned that if __getattribute__ >>is defined __getattr__ will never be called (unless called explicitely). >>Here is the exact citation: > > > Discrepancy reported in > > https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1204734&group_id=5470 > > Guido declared behavior right and doc wrong and in need of correction. > > Terry J. Reedy > > > Thanks for your reply. It definitely clears the issue. I'm writing an article to Dr. Dobbs about the Python object model and I wouldn't want to be inaccurate. I fill a little like Leibnitz :-) . It's a curious coincidence that two separate people notice the same documentation issue that lingere for such a long time in such a short time span. Thanks, Gigi From ville at spammers.com Mon May 16 14:02:04 2005 From: ville at spammers.com (Ville Vainio) Date: 16 May 2005 21:02:04 +0300 Subject: python-dev Summary for 2005-04-16 through 2005-04-30 References: <1116258692.305537.244260@g49g2000cwa.googlegroups.com> Message-ID: >>>>> "Kay" == Kay Schluehr writes: Kay> but PEP 340 is already withdrawn by the BDFL. [1] Kay> There won't be any Ruby-like blocks because they hide control Kay> flow. Bummer. I would have greatly enjoyed seeing the only real reason for choosing Ruby over Python blown away... -- Ville Vainio http://tinyurl.com/2prnb From qwweeeit at yahoo.it Sun May 15 05:11:31 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 15 May 2005 02:11:31 -0700 Subject: Modifying a built-in function for logging purposes In-Reply-To: References: <1116098593.970438.219860@g47g2000cwa.googlegroups.com> <1116108841.429602.257380@o13g2000cwo.googlegroups.com> Message-ID: <1116148291.604227.318090@g44g2000cwa.googlegroups.com> Hi Robert, > Short answer: if you don't know stuff like this, then you probably > shouldn't mess around with the builtins in production code. I begin to be fed up of beeing treated as a child who is only able to make damages... But this time you are right... So let's change point of view: instead of trying to modify built-in functions, it is better to write a small wrapper of the application you want to log. For example: # app_wrapper.py ...insert here the excellent routine of Fredrik Lundh (thank you Fredrik for your contribution!) import app #name of the application to be logged. In the test I carried on the answer was: OPEN ('pippo2',) FROM ? IN /home/qwweeeit/app.py OPEN ('pippo3', 'w') FROM ? IN /home/qwweeeit/app.py OPEN ('pippolong', 'w') FROM ? IN /home/qwweeeit/app.py I have not tested yet if multi-module applications answer in terms of modules. I must thank also Bengt Richter, also if his suggestion is far too complicate for me... Concerning his second replay and the virtualization of file system access (or the usage of an external tool as suggested by Fredrik), I leave the matter to the experts. Bye. From kraus at hagen-partner.de Fri May 27 08:08:23 2005 From: kraus at hagen-partner.de (Wolfram Kraus) Date: Fri, 27 May 2005 14:08:23 +0200 Subject: Strings for a newbie In-Reply-To: References: Message-ID: Malcolm Wooden wrote: > I'm trying to get my head around Python but seem to be failing miserably. I > use RealBasic on a Mac and find it an absolute dream! But Python....UGH! > > I want to put a sentence of words into an array, eg "This is a sentence of > words" > > In RB it would be simple: > > Dim s as string > Dim a(-1) as string > Dim i as integer > > s = "This is a sentence of words" > For i = 1 to CountFields(s," ") > a.append NthField(s," ",i) > next > > That's it an array a() containing the words of the sentence. > > Now can I see how this is done in Python? - nope! > > UGH! > > Malcolm > (a disillusioned Python newbie) > > Use split: >>> s = "This is a sentence of words" >>> s.split() ['This', 'is', 'a', 'sentence', 'of', 'words'] See: http://www.python.org/doc/2.4.1/lib/string-methods.html#l2h-202 HTH, Wolfram From newsgroups at jhrothjr.com Sat May 7 10:13:56 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Sat, 7 May 2005 08:13:56 -0600 Subject: hard memory limits References: Message-ID: <117pj97ffm7ja93@news.supernews.com> "Maurice LING" wrote in message news:d5f9jl$k6d$1 at domitilla.aioe.org... > Hi, > > I think I've hit a system limit in python when I try to construct a list > of 200,000 elements. My error is > > malloc: vm_allocate (size = 2400256) failed...... > > Just wondering is this specific to my system or what? Will adding more RAM > helps in this case? > > Thanks and cheers > Maurice malloc (which is the memory manager Python uses when it runs out of its own heap memory) is trying to get another 2.4 megabyte block of memory from the operating system so it can expand the heap. The operating system is refusing to fill the request. There are a lot of reasons why this might happen, ranging from system limits (too little swap space, too little real memory), to an inability to find a 2.4 meg block in the user part of the address space, etc. I'd check swap space, and then balance redesigning the application to not try to get large blocks of memory with spending money on more hardware memory that might not solve the problem. John Roth From loicderoyand at yahoo.fr Sun May 8 06:29:13 2005 From: loicderoyand at yahoo.fr (LDD) Date: 8 May 2005 03:29:13 -0700 Subject: Newbie : checking semantics In-Reply-To: References: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> Message-ID: <1115548153.565703.314360@z14g2000cwz.googlegroups.com> >To win this point, you need to produce evidence that doesn't exist. I was not trying to win any point when I put my naive question on this forum. I'm just learning Python and trying to know what it is best made for. So far I've learnt that Python is lazy about tyche-checking, it is dynamic by nature and that there are areas which those qualities are well fit for. Still, I'm happy to learn that pychecker exists and helps you find spelling mistakes that otherwise you would have found at execution time From gsakkis at rutgers.edu Mon May 16 21:46:59 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 16 May 2005 18:46:59 -0700 Subject: Parsing text into dates? References: <1116277171.492587.38080@g47g2000cwa.googlegroups.com> <1116291091.292107.196730@g49g2000cwa.googlegroups.com> Message-ID: <1116294419.850290.11740@o13g2000cwo.googlegroups.com> "John Machin" wrote: > On 16 May 2005 17:51:31 -0700, "George Sakkis" > wrote: > > > >#======================================================= > > > >def parseDateTime(string, USA=False, implyCurrentDate=False, > > yearHeuristic=_20thcenturyHeuristic): > > '''Tries to parse a string as a valid date and/or time. > > > > It recognizes most common (and less common) date and time formats. > > Impressive! > > > > > > Examples: > [snip] > > >>> str(parseDateTime('15.6.2001')) > > '2001-06-15' > > >>> str(parseDateTime('6.15.2001')) > > '2001-06-15' > > A dangerous heuristic -- 6.12.2001 (meaning 2001-12-06) can be easily > typoed into 6.13.2001 or 6.15.2001 on the numeric keypad. Sure, but how is this different from a typo of 2001-12-07 instead of 2001-12-06 ? There's no way you can catch all typos anyway by parsing alone. Besides, 6.15.2001 is to be interpreted as 2001-06-15 in US format. Currently the 'USA' flag is used only for ambiguous dates, but that's easy to change to apply to all dates. Essentially you would gain a little extra safety at the expense of a little lost recall over the set of parseable dates. George From garabik-news-2005-05 at kassiopeia.juls.savba.sk Fri May 27 11:21:11 2005 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Fri, 27 May 2005 15:21:11 +0000 (UTC) Subject: cpu usage limit References: <1117206216.695085.282510@g44g2000cwa.googlegroups.com> Message-ID: rbt wrote: > > mf wrote: >> Hi. >> >> My problem: >> How can I make sure that a Python process does not use more that 30% of >> the CPU at any time. I only want that the process never uses more, but >> I don't want the process being killed when it reaches the limit (like >> it can be done with resource module). >> >> Can you help me? >> >> Thanks in advance. >> >> Best regards, >> Markus >> > > Are you looping during a cpu intensive task? If so, make it sleep a bit > like this: > > for x in cpu_task: > time.sleep(0.5) > do(x) or like this (untested!) finished = False while not finished: before = time.time() do(x) # sets finished if all was computed after = time.time() delta = after-before time.sleep(delta*10/3.) now the trick: do(x) can be a single piece of code, with strategically placed yield's all over.... -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From doodle4 at gmail.com Fri May 20 16:01:11 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 20 May 2005 13:01:11 -0700 Subject: buffer_info error Message-ID: <1116619271.294467.51400@g44g2000cwa.googlegroups.com> Hello, buffer_info is giving the following error: AttributeError: 'str' object has not attribute 'buffer_info' Here's the code snippet... dest = 'FFFFFFFFFFFF' src = '0123FFFFFFFF' data = array('B', '\0' * 256) data1 = ''.join([dest, src] print data1 >>FFFFFFFFFFFF0123FFFFFFFF print data.buffer_info()[0]... works print data1.buffer_info()[0]....error This output is a string and hence i believe i get the above error. Any ideas? Thanks, -Ashton From anthra.norell at tiscalinet.ch Tue May 24 04:16:15 2005 From: anthra.norell at tiscalinet.ch (Anthra Norell) Date: Tue, 24 May 2005 10:16:15 +0200 Subject: Encryption with Python? References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com><001301c552db$dd19d3e0$0201a8c0@mcuf7> <6vh881d59bbecnc45fojknt0rohgt27crl@4ax.com> Message-ID: <03c401c56038$db0e26e0$0201a8c0@mcuf7> I wasn't going to pursue this any further. Actually, I am quite disappointed about the belligerent style of some correspondents. It's not necessary. It spoils the fun. It cloggs bandwidth. Why whack someone over the head who tries to develop an idea of his own. Such an approach isn't uncommon to earn extra credit in educational settings. True, I have also been offered good advice and being able to extract it from between insuslts I have expressed my appreciation for it. In return of the favor I offer a little anecdote about the nature of creativeness. The connection between candor and creativeness has always fascinated me. At some point, almost thirty years ago, I came across an article in a hang glider magazine by one Dr. Paul MacCready who had just won the Kremer Prize with his human-powered Gossamer Condor, a prize that had been standing for decades despite innumerable unsuccessful attempts to win it. In that article MacCready explained that it was the advent of hang gliders that gave him the idea to go for the Kremer prize. Namely, he immediately realized that hang gliders dissipated less energy in stable flight than any other aircraft in existence, not because the flew so well--they didn't--but because of their low weight. He calculated that a twenty-kilogram hang glider with a wing span of close to thirty meters would dissipate no more than one third of a horse power or thereabout and that is an amount of energy a competition cyclist generates over the course of a race. After winning the prize, MacCready challenged himself to fly across the English channel and started building an improved second version of his airplane. Passing through Los Angeles I went to see the project in a Long Beach hangar and took the opportunity to pick MacCready's brain for the benefit of our own magazine. Referring to his article I confessed my surprise that a scientist of his caliber would be inspried by such crude aeronautical engineering hacks as hang gliders unquestionably were. His reply was this: "I also consider myself an amateur. I have a PhD in aeronautics, but not in aeronautical engineering. But this just might have been my advantage. All these many previous failed attempts had been made by people with better engineering credentials. If their conception of possible solutions was better defined, it was probably also more constrained by their knowledge of what an airplane is supposed to be." We went on talking about creativeness and MacCready's conclusion still rings in my ears: "Our education system encourages us to be critical. This is a great pity. It reinforces our habit to focus on other people's weaknesses and failures, when we could learn from observing their strengths." Frederic (Robert Kern could have embarrassed me with a plain-text attack, although his bounty wouldn't have been my credit card details. I tought about plain-text attacks and found that in addition to changing the values of bytes I also needed to shuffle them a little. So I added a few lines, encoded my credit card details and here it is, program, credit card details, everything but the key.) 1. The credit card details: string = '\x84ue\x8d\xec\x98\x02\xba 0) * 2 - 1 random.seed (abs (key * sign)) i = 0 s = '' if sign > 0: while i < len (string): chunk = random.randint (0, CHUNK) s_ = preprocess_sequence (list (string [i:i+chunk])) s += ''.join (process_sequence (s_)) i += len (s_) else: while i < len (string): chunk = random.randint (0, CHUNK) s_ = list (string [i:i+chunk]) l = len (s_) l_ = range (l) s__ = l * [None] o = preprocess_sequence (l_) s_ = process_sequence (s_) for ii in l_: s__ [o[ii]] = s_ [ii] s += ''.join (s__) i += l return s ----- Original Message ----- From: "Christos TZOTZIOY Georgiou" Newsgroups: comp.lang.python To: Sent: Friday, May 13, 2005 11:06 AM Subject: Re: Encryption with Python? > On Sat, 7 May 2005 13:51:40 +0200, rumours say that "Anthra Norell" > might have written: > > >Here's the challenge. Prove this breakable > > > >'\x10\x88d\x1d\xba\xa1\xdcK\x05w\x02/s\xa7Q0\xeb8\xb6Gx\xef\xcb\x1e=\xf5\x7 f > >\x9bI\xcb(\x87>\xa5\x04\xc1soF\xfd\xc6\xc6\xd9|\x971\xdb\xcdT\tw#\x86a\xdc\ x > >b8P\xfb=n\xda\x80\x9f\x84m\x12\x98\x98\xca=o\x0b\x8e\x08O\xb7\x0b\x04SC\x96 \ > >xc7\xab*\x0b\x996\x06\x86\x83(\x8dQ\x9eG\x8f$\xb2x)\xa9fv\x0c1B\x9b\r\xde\x f > >fc\x08' > > and given that > > >I rolled my own for relatively short sequences, like passwords. The key is > >an integer. To decrypt use the negative encryption key. I consider the > >encryption unbreakable, as it is indistinguishable from a random sequence. > > can we suppose that the encrypted text above are the details of your > credit card (number, name as written on it, expiry date, billing address > and your first dog's name)? Do you trust the 'unbreakability' of your > algorithm that much? > -- > TZOTZIOY, I speak England very best. > "Be strict when sending and tolerant when receiving." (from RFC1958) > I really should keep that in mind when talking with people, actually... > -- > http://mail.python.org/mailman/listinfo/python-list From matthew_shomphe at countrywide.com Fri May 13 17:59:13 2005 From: matthew_shomphe at countrywide.com (Matt) Date: 13 May 2005 14:59:13 -0700 Subject: How to find the classname of an object? (was Python Documentation) In-Reply-To: <4284f28c.80913136@news.oz.net> References: <4283fda8.18221170@news.oz.net> <1116002227.923231.309150@f14g2000cwb.googlegroups.com> <4284f28c.80913136@news.oz.net> Message-ID: <1116021553.771015.320200@g14g2000cwa.googlegroups.com> Bengt Richter wrote: > On 13 May 2005 09:37:07 -0700, "Matt" wrote: > > > > >Christopher J. Bottaro wrote: > >> Christopher J. Bottaro wrote: > >> > >> > Bengt Richter wrote: > >> > > >> >> >>> type(obj) > >> >> > >> >> >>> type(obj).mro() > >> >> [, , >'__main__.B2'>, > >> >> [, ] > >> >> >>> tuple(x.__name__ for x in type(obj).mro()) > >> >> ('A', 'B1', 'B2', 'C', 'object') > >> > > >> > Wow awesome, thats exactly what I was looking for. > >> > >> Wait a sec...why doesn't the following code work then? > >> > Well, I suspect it actually does work, technically, but I suspect > it hints at the way old-style classes were implemented in the environment > of the new, rather than giving you what you might expect. > > >> class FWException(Exception): pass > >> class FWA(FWException): pass > >> class FWB(FWA): pass > >> class FWC(FWB): pass > >> e = FWC() > >> print [ cl.__name__ for cl in type(e).mro() ] > >> > >> Thanks again. > >> --C > > > > > >Is it because you need to inherit from "object"? > > > >class FWException(Exception, object): pass # note "object" > >class FWA(FWException): pass > >class FWB(FWA): pass > >class FWC(FWB): pass > >e = FWC() > >print [ cl.__name__ for cl in type(e).mro()] > > > >#prints ['FWC', 'FWB', 'FWA', 'FWException', 'Exception', 'object'] > > > I'm afraid inheriting explicitly from object will make the exception unraisable. > Exceptions are still based on "classic" classes for some reason that > I don't know enough about to explain. > > So if you were hoping to use .mro() with old-style classes to see the > old-style inheritance chain, as opposed to new-style inheritance that > underlies access to special entities involved in the implementation of the old, sorry ;-/ > > At least that's the way it looks to me, without digging in that part of the code. > > Regards, > Bengt Richter D'oh! So I tested the .mro() functionality but not the Exception-raisableness (?). It seems unintuitive to me as to why inheriting from "object" would prevent something that also inherited from "Exception" from being raised. Does anyone have insight into why this happens? From Ronald700061 at yahoo.com Mon May 2 14:17:45 2005 From: Ronald700061 at yahoo.com (Ronald700061 at yahoo.com) Date: 2 May 2005 11:17:45 -0700 Subject: =?iso-8859-1?B?SW1wb3J0YW50IHBsZWFzZSByZWFkIHRoaXMgVGhhbmsgeW91IGCwurcuLi63urBgsLq3Li4ut7qwYLC6ty6GLi63urBgsLq3Li4ut7qwYLC6ty4ut7qwYCBgsLq3Li4ut7qwYLC6ty4uLre6sGCwurcuhi4ut7qwYLC6ty4uLre6sGCwurcuLre6sGAgYLC6ty4uLre6sGCwurcuLi63urBgsLq3LoYuLre6sGCwurcuLi63urBgsLq3Li63urBgIGCwurcuLi63urBgsLq3Li4ut7qwYLC6ty6GLi63urBgsLq3Li4ut7qwYLC6ty4ut7qwYCBgsLq3Li4ut7qwYLC6ty4uLre6sGCwurcuhi4ut7qwYLC6ty4uLre6sGCwurcuLre6sGAgYLC6ty4uLre6sGCwurcuLi63urBgsLq3LoYuLre6sGCwurcuLi63urBgsLq3Li63urBgIGCwurcuLi63urBgsLq3Li4ut7qwYLC6ty6GLi63urBgsLq3Li4ut7qwYLC6ty4ut7qwYCBgsLq3Li4ut7qwYLC6ty4uLre6sGCwurcuhi4ut7qwYLC6ty4uLre6sGCwurcuLre6sGAgR09PR0xFt05FV1NHUk9VULdQT1NUtzE1NQ==?= Message-ID: <1115057865.662012.234170@z14g2000cwz.googlegroups.com> This is the most important question of your life. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? The reason some people don't know for sure if they are going to Heaven when they die is because they just don't know. The good news is that you can know for sure that you are going to Heaven. The Holy Bible describes Heaven as a beautiful place with no death, sorrow, sickness or pain. God tells us in the Holy Bible how simple it is to be saved so that we can live forever with Him in Heaven. "For if you confess with your mouth Jesus is Lord and believe in your heart that God raised Him from the dead, you WILL BE SAVED." (Romans 10:9) Over 2000 years ago God came from Heaven to earth in the person of Jesus Christ to shed His blood and die on a cross to pay our sin debt in full. Jesus Christ was born in Israel supernaturally to a virgin Jewish woman named Mary and lived a sinless life for thirty-three years. At the age of thirty-three Jesus was scourged and had a crown of thorns pressed onto His head then Jesus was crucified. Three days after Jesus died on a cross and was placed in a grave Jesus rose from the dead as Jesus said would happen before Jesus died. If someone tells you that they are going to die and then three days later come back to life and it actually happens then this person must be the real deal. Jesus Christ is the only person that ever lived a perfect sinless life. This is why Jesus is able to cover our sins(misdeeds) with His own blood because Jesus is sinless. The Holy Bible says, "In Him(Jesus) we have redemption through His blood, the forgiveness of sins..." (Ephesians 1:7) If you would like God to forgive you of your past, present and future sins just ask Jesus Christ to be your Lord and Saviour. It doesn't matter how old you are or how many bad things that you have done in your life including lying and stealing all the way up to murder. Just pray the prayer below with your mouth and mean it from your heart and God will hear you and save you. Dear Jesus Christ, I want to be saved so that I can have a home in Heaven with You when I die. I agree with You that I am a sinner. I believe that You love me and want to save me. I believe that You bled and died on the cross to pay the penalty for my sins and that You rose from the dead. Please forgive my sins and come into my heart and be my Lord and Saviour. Thanks Lord Jesus Christ for forgiving me and saving me through Your merciful grace. Amen. Welcome to the family of God if you just allowed God to save you. Now you are a real Christian and you can know for sure that you will live in Heaven forever when this life comes to an end. As a child of God we are to avoid sin(wrongdoing), but if you do sin the Holy Bible says, "My dear children, I write this to you so that you will not sin. But if anybody does sin, we have one who speaks to the Father in our defense Jesus Christ, the Righteous One." Those of you that have not yet decided to place your trust in the Lord Jesus Christ may never get another chance to do so because you do not know when you will die. Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever separated from the love of God in a place called Hell. The Holy Bible descibes Hell as a place of eternal torment, suffering, pain and agony for all those who have rejected Jesus Christ. The good news is that you can avoid Hell by allowing Jesus Christ to save you today. Only then will you have true peace in your life knowing that no matter what happens you are on your way to Heaven. Praise the Lord! Servant of the Lord Jesus Christ Ronald L. Grossi * Show this to your family and friends so they can also be saved. * This message may get deleted so you may want to print a copy. * Just press the [Ctrl][P] keys on your keyboard to print this page. `???...???`???...???`???.?..???`???...???`???..???` Got Questions? http://www.gotquestions.org/archive.html Other Languages http://www.godssimpleplan.org/gsps.html Free Movie: To Hell and Back http://www.tbn.org/index.php/8/1.html Animation http://www.gieson.com/Library/projects/animations/walk/index.html The Passion Of The Christ http://www.thepassionofthechrist.com Beware Of Cults http://www.carm.org/cults/cultlist.htm About Hell http://www.equip.org/free/DH198.htm Is Jesus God? http://www.powertochange.com/questions/qna2.html Free Online Bible http://www.biblegateway.com `???...???`???...???`???.?..???`???...???`???..???` From ramen at lackingtalent.com Fri May 6 15:35:11 2005 From: ramen at lackingtalent.com (Dave Benjamin) Date: Fri, 06 May 2005 12:35:11 -0700 Subject: win32: structured storage In-Reply-To: References: Message-ID: Steve Holden wrote: > tlviewer wrote: > > > CHM is supposed to be structured storage (ITSF). If a given CHM > > file is infected it most likely has an embedded EXE file -- mine > > had one called [Open.exe]. > > > Ironic, really, since Microsoft insist that the browser must be > fully-integrated with the operating system I suppose that measn we had > better all start using Linux. Even more ironically, it would seem that in effort to kill Netscape they are killing Windows. From skip at pobox.com Wed May 11 13:16:06 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 May 2005 12:16:06 -0500 Subject: Problems with csv module In-Reply-To: References: Message-ID: <17026.15830.303909.792010@montanaro.dyndns.org> Fredrik> does the CSV format even support Unicode-encoded data streams? Based on the requests I've seen here and on the csv at mojam.com mailing list, it appears people are certainly generating CSV files which contain Unicode-encoded data. Skip From rhall at thiess.com.au Thu May 26 05:40:56 2005 From: rhall at thiess.com.au (Bloke) Date: 26 May 2005 02:40:56 -0700 Subject: SSL (HTTPS) with 2.4 References: <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> <1116524774.606167.98240@f14g2000cwb.googlegroups.com> <1116550788.207740.171780@o13g2000cwo.googlegroups.com> <1116627976.845517.268370@z14g2000cwz.googlegroups.com> <1116808438.811166.49180@g49g2000cwa.googlegroups.com> <1117055802.770863.195480@g14g2000cwa.googlegroups.com> Message-ID: <1117100456.058010.315640@g43g2000cwa.googlegroups.com> OK. I try pyopenssl and can get a secure socket to the server, but am unsure how to use this socket with urllib2 or even httplib. Here's the code I'm using: import sys, socket, string, base64, httplib from OpenSSL import SSL # Connects to the server, through the proxy def run(server, proxy): user='me';passwd='pass' #setup basic authentication if user and passwd: user_pass=base64.encodestring(user+':'+passwd) proxy_authorization='Proxy-authorization: Basic '+user_pass+'\r\n' else: proxy_authorization='' s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(proxy) print 'Socket established' except socket.error, e: print "Unable to connect to %s:%s %s" % (proxy[0], proxy[1], str(e)) sys.exit(-1) # Use the CONNECT method to get a connection to the actual server connectMessage = "CONNECT %s:%s HTTP/1.0\r\n" % (server[0], server[1]) + \ proxy_authorization #+ 'Proxy-Connection: Keep-Alive\r\n' print connectMessage s.send(connectMessage) print '\nConnect sent...' print "Proxy response: %s" % string.strip(s.recv(1024)) ctx = SSL.Context(SSL.SSLv2_METHOD) conn = SSL.Connection(ctx, s) # Go to client mode conn.set_connect_state() # start using HTTP conn.send("HEAD / HTTP/1.0\n\n") print "Server response:" print "-" * 40 while 1: try: buff = conn.recv(4096) except SSL.ZeroReturnError: # we're done break print buff, #initalize httplib and replace with your socket sock = httplib.FakeSocket(s, conn) print 'Fake socket installed' h=httplib.HTTPSConnection(server[0],server[1]) h.sock=sock print 'Sock installed' h.request('GET','/') print 'Request sent.' r=h.getresponse() print r.read() if __name__ == '__main__': server = ('www.anz.com', 443) proxy = ('proxy.company.com, 8008) run(server, proxy) I get the following response at line 59 r=h.getresponse() Socket established CONNECT www.anz.com:443 HTTP/1.0 Proxy-authorization: Basic cmhhbGw6YWxlbW0y Connect sent... Proxy response: HTTP/1.0 200 Connection established conn established conn connect state set Server response: ---------------------------------------- HTTP/1.1 200 OK Server: Microsoft-IIS/4.0 Date: Thu, 26 May 2005 09:33:26 GMT Content-Type: text /html Set-Cookie: ASPSESSIONIDCRADCCBB=JPGLOCLDMMFNKJKCMIBADHOH; path=/ Cache-control: private Fake socket installed Sock installed Request sent. Traceback (most recent call last): File "C:\Documents and Settings\rhall\Desktop\software\python\tunnel\proxy-openssl.py", line 65, in ? run(server, proxy) File "C:\Documents and Settings\rhall\Desktop\software\python\tunnel\proxy-openssl.py", line 59, in run r=h.getresponse() File "C:\Python24\Lib\httplib.py", line 862, in getresponse response.begin() File "C:\Python24\Lib\httplib.py", line 333, in begin version, status, reason = self._read_status() File "C:\Python24\Lib\httplib.py", line 291, in _read_status line = self.fp.readline() File "C:\Python24\Lib\httplib.py", line 981, in readline s = self._read() File "C:\Python24\Lib\httplib.py", line 937, in _read buf = self._ssl.read(self._bufsize) ZeroReturnError I tried enabling 'Proxy-Connection: Keep-Alive' but then it hangs for ages at: conn.send("HEAD / HTTP/1.0\n\n") and eventually returns a 'handshaking' error. Any pointers anyone? Rob From curi42 at gmail.com Thu May 26 20:33:33 2005 From: curi42 at gmail.com (Elliot Temple) Date: 26 May 2005 17:33:33 -0700 Subject: Case Sensitive, Multiline Comments In-Reply-To: <429654DA.9050903@lexicon.net> References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> <8664x5y92g.fsf@guru.mired.org> <429654DA.9050903@lexicon.net> Message-ID: <1117154013.092736.298310@g14g2000cwa.googlegroups.com> Thanks for the link on case sensitivity. I'm curious about the person who found case sensitivity useful though: what is it useful for? The way I find multi-line comments useful is to quickly comment out a block of code while debugging. A good development environment can (mostly) solve that one though. From t-meyer at ihug.co.nz Thu May 26 22:26:57 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Fri, 27 May 2005 14:26:57 +1200 Subject: What are OOP's Jargons and Complexities? In-Reply-To: Message-ID: [Paul Rubin] > Strong typing means there [are] a lot of variables whose names > are in ALL CAPS. +1 QOTW. =Tony.Meyer From thomas at eforms.co.nz Thu May 5 08:15:17 2005 From: thomas at eforms.co.nz (Thomas Thomas) Date: Fri, 6 May 2005 00:15:17 +1200 Subject: UnicodeDecodeError Message-ID: <000801c5516c$19a41a30$bb64a8c0@eformswin> Hi all import httplib, mimetypes import os; def get_content_type(filename): return mimetypes.guess_type(filename)[0] or 'application/octet-stream' filepath= 'c:/Documents and Settings/Administrator/Desktop/tmp/test.pdf'; f = open(filepath, "rb") data = f.read() f.close() (filedir, filename) = os.path.split(filepath) filename=unicode(filename); #file = ('file', filename, data) #This won't work will give a UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 10: ordinal not in range(128) file = ('file', filename, 'data'*100) #this will work fine #file = ('file', 'test.pdf', data) #This also works fine files = [file] CRLF = '\r\n' L = [] for (key, filename, value) in files: L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append(value) body = CRLF.join(L) print "ok" can anyone put some light.. whats going behind.. cheers Thomas -------------- next part -------------- An HTML attachment was scrubbed... URL: From cjbottaro at alumni.cs.utexas.edu Wed May 25 12:48:18 2005 From: cjbottaro at alumni.cs.utexas.edu (Christopher J. Bottaro) Date: Wed, 25 May 2005 11:48:18 -0500 Subject: Python analog of Ruby on Rails? Message-ID: Hello fellow Pythonists, Is there such a thing? My work is thinking of maybe experimenting with Ruby on Rails for some lesser projects. Naturally, I wonder if Python can do as good a job or better... Thanks for the info, -- C From kent37 at tds.net Tue May 31 08:37:11 2005 From: kent37 at tds.net (Kent Johnson) Date: Tue, 31 May 2005 08:37:11 -0400 Subject: scripting browsers from Python In-Reply-To: References: <1117525953.255166.234420@g14g2000cwa.googlegroups.com> Message-ID: <429c5a4e$1_3@newspeer2.tds.net> Simon Brunning wrote: > On 31 May 2005 00:52:33 -0700, Michele Simionato > wrote: > >>I would like to know what is available for scripting browsers from >>Python. > > I don't know of anything cross platform, or even cross browser, but on > Windows, IE can be automated via COM - see > for example Also http://pamie.sourceforge.net/ Kent From grante at visi.com Tue May 17 11:24:37 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 17 May 2005 15:24:37 -0000 Subject: Windows distribution suggestions? References: <7x3bsmfjdg.fsf_-_@ruckus.brouhaha.com> Message-ID: <118k35lnpte8498@corp.supernews.com> On 2005-05-17, Paul Rubin wrote: > As what must be penance for something or other, I'm needing to release > a Python app for use under Windows XP. I'm a Unix guy who occasionally ships a Python app for Win32, and I always recommend py2exe and inno setup: py2exe http://starship.python.net/crew/theller/py2exe/ inno setup http://www.jrsoftware.org/isinfo.php Inno setup is as good as any other installer, and it's free. -- Grant Edwards grante Yow! Did I SELL OUT yet?? at visi.com From f.geiger at vol.at Tue May 17 15:10:11 2005 From: f.geiger at vol.at (F. GEIGER) Date: Tue, 17 May 2005 21:10:11 +0200 Subject: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied. Message-ID: Im on Python 2.3.4, using pysqlite 2.0.0 (final). When I try to execute self._dbc.execute(q, data) where q is 'select count(*) from Difflets ' and date is None I get the following exception: pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 0, and there are -1 supplied. Any ideas? Many thanks in advance and kind regards Franz GEIGER From __peter__ at web.de Thu May 5 15:29:36 2005 From: __peter__ at web.de (Peter Otten) Date: Thu, 05 May 2005 21:29:36 +0200 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> <1115316826.659271.247350@o13g2000cwo.googlegroups.com> <1115320481.000911.111220@z14g2000cwz.googlegroups.com> Message-ID: mrstephengross wrote: > This was all supposed to be on comp.lang.c++, but You may still want to read the following thread on Python-Dev: http://mail.python.org/pipermail/python-dev/2004-March/043703.html A link mentioned by Andrew Koenig may be helpful: http://www.netlib.org/fp/ """ file g_fmt.c by David Gay for ANSI C or C++ source for function g_fmt(char *, double): , with help from dtoa, g_fmt(buf, x) sets buf to the shortest , decimal string that correctly rounds to x and returns buf. """ Peter From http Mon May 2 20:51:09 2005 From: http (Paul Rubin) Date: 02 May 2005 17:51:09 -0700 Subject: cgi "print statement" in multithreaded enviroment? References: <4276c282$0$153$e4fe514c@news.xs4all.nl> Message-ID: <7x1x8pcete.fsf@ruckus.brouhaha.com> vegetax writes: > But i want to use "print" as a commodity feature, print >> > self.response,'html..' is longer to type than > self.response.write('html..') w = self.response.write w('html...') w('more html...') w('still more html') From onurb at xiludom.gro Wed May 18 11:39:26 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 18 May 2005 17:39:26 +0200 Subject: Looking for bored python newbies In-Reply-To: <1116423028.626953.74160@f14g2000cwb.googlegroups.com> References: <1116423028.626953.74160@f14g2000cwb.googlegroups.com> Message-ID: <428b61af$0$23730$626a14ce@news.free.fr> cpu.crazy at gmail.com wrote: > Hey if you're a python newbie, and ur bored cause everything everybody > else is doing hten you're not alone. How'd you like to start a project > of your own or join a simple project? > Plz contact me if you do with the subject line: Bored Newbie > > CPUFreak91 > (cpu.crazy at gmail.com) > (Still quite a newbie myself :-)) > http://www.catb.org/~esr/faqs/smart-questions.html#writewell -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From fredrik at pythonware.com Wed May 11 13:11:35 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 11 May 2005 19:11:35 +0200 Subject: Problem combining python code and html References: <42822b3d$0$653$ba624c82@nntp02.dk.telia.net> Message-ID: Hansan wrote: > I used the same code they use for making the two display functions and the > same template for the html form. I even tried using the form template they > use too, but it still dosnt work. I will now show how the functions and > templates look like. > > The two display functions are: > def Display(Content): > TemplateHandle = open(TemplateFile, "r") > TemplateInput = TemplateHandle.read() > TemplateHandle.close() > BadTemplateException = "There was a problem with the HTML template." > SubResult = re.subn("", > Content,TemplateInput) re.subn takes a regular expression, in which certain characters have special meanings. for example, in "*" is reserved character, which means "repeat preceeding expression". so "***" means repeating a repeated repeat, which makes very little sense, which is why the RE engine complains. changing > SubResult = re.subn("", > Content,TemplateInput) SubResult = TemplateInput.replace( "", Content ) should work better. From f.geiger at vol.at Fri May 20 02:42:54 2005 From: f.geiger at vol.at (F. GEIGER) Date: Fri, 20 May 2005 08:42:54 +0200 Subject: [pysqlite] How do I use pysqlite in a multi-threading env.? Message-ID: In my wxPython-app a part of it gathers data, when a button is pressed, and stores it into a db. The GUI part should display the stuff being stored in the db. When both parts work on the same connection, I get "SQL statements in progress errors". Seems ok to me, you can't do that. So, next step: Both parts get a separate connection. Now I get "Database locked" errors. Hmm, yes, it's GUI stuff after all, being all in the same thread. So, next step: I put the data gathering part into a real thread, that's started, wehn the "Scan" button is pressed. This way the "Database locked"- errors should got away. But now I get "SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 3576 and this is thread id 1040". Hmm, true, I want to display db content, that was stored by an other thread. But that's what multi-threading capabilities are for! I must be missing something here. Anyway, I'm a bit lost now, really. So, how are you doing such stuff with pysqlite? Kind regards Franz GEIGER From Scott.Daniels at Acm.Org Tue May 3 10:35:16 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 03 May 2005 07:35:16 -0700 Subject: cgi "print statement" in multithreaded enviroment? In-Reply-To: References: <20050503013716.GA3367@unpythonic.net> Message-ID: <42778621$1@nntp0.pdx.net> vegetax wrote: > So it would be something like this, right?? > > class ThreadSpecificFile: > def __init__(s): > self.files = [] > def set_stdout(f,thread_id): > self.files[thread_id] = f > def clean_up(thread_id): > del self.files[thread_id] > def write(data): > self.files[thread.get_ident()].write(data) > > sys.stdout = ThreadSpecificFile() import sys, thread class ThreadSpecificFile: def __init__(self, original): self.files = dict() self.original = original def set_stdout(self, f): self.files[thread.get_ident()] = f def close(self): try: this = self.stops().close() except KeyError: pass def stops(self): return self.files.pop(thread.get_ident()) def write(self, data): self.files.get(thread.get_ident(), self.original).write(data) except KeyError: self sys.stdout = ThreadSpecificFile(sys.stdout) --Scott David Daniels Scott.Daniels at Acm.Org From michele.simionato at gmail.com Mon May 2 08:18:57 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 2 May 2005 05:18:57 -0700 Subject: MRO problems with diamond inheritance? In-Reply-To: <1115034897.225080.313990@l41g2000cwc.googlegroups.com> References: <1114987828.055744.250090@z14g2000cwz.googlegroups.com> <1115004565.128735.58670@o13g2000cwo.googlegroups.com> <1115008163.017331.306290@o13g2000cwo.googlegroups.com> <1115024383.848366.64190@z14g2000cwz.googlegroups.com> <1115034897.225080.313990@l41g2000cwc.googlegroups.com> Message-ID: <1115036337.530436.47890@g14g2000cwa.googlegroups.com> Well, writing that book would be a major undertaking that I am not willing to take any soon ;) However, all you are asking for is already in my lectures at ACCU: http://www.reportlab.org/~andy/accu2005/pyuk2005_simionato_wondersofpython.zip >From the README: """ Generally speaking these lectures are unpolished, too concise, with more code than words, and with cutting edge/experimental code. Read them at your risk and peril. Take in account the fact that they were prepared as a last minute replacement for Alex Martelli's tutorial, with a limited amount of time and a very advanced program to follow. My main concern in preparing these notes was to give the readers a few *ideas*, not polished solutions. If you are reading these notes, you will be more than capable to customize these ideas to your own situation and to fix the unavoidable little bugs, imperfections, annoyances. Whereas I recommend the first lecture about iterators and generators to everybody, take in account than the second and especially the third lecture may cause your head to explode. I do not take any responsability in that case. """ Michele Simionato From a-steinhoff at web.de Fri May 13 08:34:45 2005 From: a-steinhoff at web.de (Armin Steinhoff) Date: Fri, 13 May 2005 14:34:45 +0200 Subject: pyvm -- faster python In-Reply-To: References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> <1115791624.856252.247890@z14g2000cwz.googlegroups.com> <7x1x8el18e.fsf@ruckus.brouhaha.com> <1115876410.813839.222080@g43g2000cwa.googlegroups.com> Message-ID: Stelios Xanthakis wrote: > Armin Steinhoff wrote: > >>> >>> pyvm has that. A big part of it is written in "lightweight C++" [1]. >> >> >> >> Realy ? I have downloaded the lwc distribution and checked it out. >> It was a surprise that none of the examples are working. >> I'm using SuSE 9.0 with gcc 3.3.1 ... >> > > :( > >> Is there a working version of lwc ??? >> > > pyvm is written in lwc-2.0 which is not yet released because > nobody's using it. As you mentioned it ... lwc-2.0 is used for pyvm. So it is used :) Do you have an idea when lwc-2.0 will be releast ? Everyone who are interested in pyvm will need it ... -- Armin > > > Stelios From dave.benjamin at gmail.com Thu May 5 12:28:11 2005 From: dave.benjamin at gmail.com (Dave Benjamin) Date: Thu, 05 May 2005 09:28:11 -0700 Subject: annonymous functions -- how to In-Reply-To: References: <1115239458.776800.240080@g14g2000cwa.googlegroups.com> <42795acb.685370470@news.oz.net> <1115264804.625020.203800@f14g2000cwb.googlegroups.com> Message-ID: Peter Hansen wrote: > I doubt there's a valid usecase for a "anonymous" function that has more > than a line or two. Personally, I don't think there's a good usecase > for an anonymous function longer than one line... The case that I keep running into regards event-driven programming. I need to do a series of operations that are tied together asynchronously via callback functions, but I still want the actions to read in-order. With anonymous functions (and I mean the ones that you can use within expressions, Bengt ;) ), I could write something like the following: def add_thingy(): with_next_thingy_id(def(thingy_id): print 'got thingy id:', thingy_id with_next_doodad_id(def(doodad_id): pring 'got doodad id:', doodad_id with_new_thingy_doodad(thingy_id, doodad_id, def(thingy_doodad): print 'thingy doodad created, froobling...' frooble(thingy_doodad) print 'froobling complete' ) ) ) In this case, having to name these callback functions is tiring and awkward, and (IMHO) disrupts the flow of my function: def add_thingy(): def next_thingy_id_func(thingy_id): print 'got thingy id:', thingy_id def next_doodad_id_func(doodad_id): print 'got doodad id:', doodad_id def new_thingy_doodad_func(thingy_doodad): print 'thingy doodad created, froobling...' frooble(thingy_doodad) print 'froobling complete' with_new_thingy_doodad(thingy_id, doodad_id, new_thingy_doodad_func) with_next_doodad_id(next_doodad_id_func) with_next_thingy_id(next_thingy_id_func) There is no reason why these callbacks would necessarily be one-liners or ten-liners. I suppose this problem could be solved by defining all the functions at the top-level (or by using bound methods of an object), but to me this is harder to maintain and doesn't read as well. Not life or death, but there's at least one use case that I would at least consider "valid". Your definition of "valid" may differ, of course. =) Dave From news at andyjeffries.co.uk Wed May 4 10:47:09 2005 From: news at andyjeffries.co.uk (Andy Jeffries) Date: Wed, 04 May 2005 14:47:09 GMT Subject: Python & SQLite In-Reply-To: <1115131256.058058.139980@o13g2000cwo.googlegroups.com> References: <1115131256.058058.139980@o13g2000cwo.googlegroups.com> Message-ID: dcrespo wrote: > Does PySQLite run on Linux? Yes! >From my Gentoo laptop: andyvaio root # emerge -av pysqlite These are the packages that I would merge, in order: Calculating dependencies ...done! [ebuild R ] dev-python/pysqlite-0.5.1 0 kB Total size of downloads: 0 kB Do you want me to merge these packages? [Yes/No] Cheers, Andy From dalke at dalkescientific.com Tue May 31 21:41:34 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Wed, 01 Jun 2005 01:41:34 GMT Subject: pickle alternative References: <1117520276.417970.207680@g14g2000cwa.googlegroups.com> <1117524878.988878.181820@g44g2000cwa.googlegroups.com> <1117527950.319411.193030@g44g2000cwa.googlegroups.com> Message-ID: simonwittber wrote: > marshal can serialize small structures very qucikly, however, using the > below test value: > > value = [r for r in xrange(1000000)] + > [{1:2,3:4,5:6},{"simon":"wittber"}] > > marshal took 7.90 seconds to serialize it into a 5000061 length string. > decode took 0.08 seconds. Strange. Here's what I found: >>> value = [r for r in xrange(1000000)] +[{1:2,3:4,5:6},{"simon":"wittber"}] >>> import time, marshal >>> t1=time.time();s=marshal.dumps(value);t2=time.time() >>> t2-t1 0.22474002838134766 >>> len(s) 5000061 >>> t1=time.time();new_value=marshal.loads(s);t2=time.time() >>> t2-t1 0.3606879711151123 >>> new_value == value True >>> I can't reproduce your large times for marshal.dumps. Could you post your test code? Andrew dalke at dalkescientific.com From exarkun at divmod.com Wed May 11 09:15:07 2005 From: exarkun at divmod.com (Jp Calderone) Date: Wed, 11 May 2005 13:15:07 GMT Subject: Replacing open builtin In-Reply-To: <1115816164.517116.124070@g14g2000cwa.googlegroups.com> Message-ID: <20050511131507.15422.196227562.divmod.quotient.32331@ohm> On 11 May 2005 05:56:04 -0700, rmm at iname.com wrote: >Sorry, should maybe have used __import__ as an example. >Let's say I grab import, store the reference within the Isolate class >and then redirect the builtin import to a function in the Isolate class >which only allows certain modules to be imported -eg not sys. Would >this be secure? > Probably not. For example: >>> (1).__class__.__bases__[0].__subclasses__()[-1]('/dev/null') Security through subtracting features usually ends up leaving some holes around (because there's just that *one* more thing you missed). What the holes are depends on the details of the implementation, but they pretty much always exist. Making a reference-restricted Python interpreter is a large challenge: you either have to spend a huge amount of effort taking things out of CPython (months and months of development time, at least), or write a new interpreter from scratch. Older versions of Python thought they had this licked, see the rexec module for the attempt that is no longer maintained. Jp From km at mrna.tn.nic.in Mon May 2 13:41:54 2005 From: km at mrna.tn.nic.in (km) Date: Mon, 2 May 2005 23:11:54 +0530 Subject: Supercomputer and encryption and compression @ rate of 96% In-Reply-To: References: Message-ID: <20050502174154.GA13603@mrna.tn.nic.in> Hi all, This was posted long ago. I tried to compress a mp3 file but i couldnt get the keycode+".out" file which is of size 1 bit. instead it is printed to STDOUT. i am usng python 2.4 . i understand that the keycode is embedded in the filename itself. Is it a problem with python not able to create a file with such a big filename ? any workarounds ? regards, KM ---------------------------------------------------------------------------- On Thu, Apr 14, 2005 at 01:49:22PM +0200, Fredrik Lundh wrote: > Will McGugan wrote: > > > Please implement this as a Python module. I would like to compress my mp3 collection to single > > bits. > > here's the magic algorithm (somewhat simplified): > > def algorithm(data): > m = 102021 # magic constant > d = [int(c) for c in str(1*2*3*4*5*m+5+4+2+1)] > x = [ord(c) for c in hex(1+2+4+5+m*5*4*3*2*1)] > x[d[0]*d[1]*d[2]] = x[d[-1]] + sum(d) - d[d[-d[-1]-1]] + d[0] > x = __import__("".join(chr(c) for c in x[d[0]*d[1]:])).encodestring > return "".join(x(data).split("\n")).rstrip("="), sum(d)-sum(reversed(d)) > > and here's a driver for your MP3 collection: > > import glob > > def compress(filename): > data = open(filename, "rb").read() > keycode, bit = algorithm(data) > file = open(keycode + ".out", "wb") > file.write(chr(bit)) > file.close() > print "compressed", filename, > print len(data), "=>", 1, round(100.0/len(data), 3), "%" > > for file in glob.glob("*.mp3"): > compress(file) > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > From james at wrong.nu Sun May 8 09:22:33 2005 From: james at wrong.nu (R. C. James Harlow) Date: Sun, 8 May 2005 14:22:33 +0100 Subject: Controlling kwrite by dcop In-Reply-To: <1115556061.120200.268900@z14g2000cwz.googlegroups.com> References: <1115556061.120200.268900@z14g2000cwz.googlegroups.com> Message-ID: <200505081422.38643.james@wrong.nu> On Sunday 08 May 2005 13:41, qwweeeit at yahoo.it wrote: > As you can see you can interact with kwrite from dcop. > Unfortunately I don't have this module in my Python (2.3) nor I have > been able to find it. It's normally installed seperately from the main kde libraries - on gentoo it's a package called dcoppython, that might help you in your search if you're on a different distro. james. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From jjl at pobox.com Fri May 13 16:29:19 2005 From: jjl at pobox.com (John J. Lee) Date: 13 May 2005 20:29:19 +0000 Subject: Parsing HTML with JavaScript References: Message-ID: <874qd6lvj4.fsf@pobox.com> mtfulmer at tacobell.land writes: > I am trying to extract some information from a few web pages, and I was > using the HTMLParser module. It worked fine until it got to the > javascript, at which it gave a parse error. Is there a good way to work > around this or should I just preparse the file to remove the javascript > manually? This is my first python program. sgmllib is very similar to HTMLParser, but doesn't break so easily (but sgmllib has some problems with XHTML -- swings and roundabouts). Or, try BeautifulSoup. John From b.ghose at gmail.com Sun May 1 17:40:20 2005 From: b.ghose at gmail.com (Baishampayan) Date: 1 May 2005 14:40:20 -0700 Subject: BitKeeper for Python? References: Message-ID: <1114983620.737219.291410@z14g2000cwz.googlegroups.com> Hello John, If you just want a repository for one project and you don't want to admin the whole server [which is a job in itself], you can use Sourceforge's CVS server. They'll also let you host the project on their servers. If you want to setup your own SCM, you can try Subversion, GNU Arch, or if you are interested in distributed SCMs, you can try Monotone http://www.venge.net/monotone/ IMO, you'll be better off using Sourceforge's CVS server. Regards, -bg- From vincent at visualtrans.de Thu May 5 10:33:39 2005 From: vincent at visualtrans.de (vincent wehren) Date: Thu, 5 May 2005 16:33:39 +0200 Subject: a cx_Oracle ORA-01036 problem References: <427a2b39_2@x-privat.org> Message-ID: "Damjan" schrieb im Newsbeitrag news:427a2b39_2 at x-privat.org... | I'm using Python 2.4, cx_Oracle-4.1 on Linux with Oracle instant client | 10.1.0.3. This is the sql string: | | SQL = """insert into D.D_NOTIFY values (:CARDREF, :BANKKEY, :OK1, :OK2 \ | :DEBTEUR, :DEBTDEN, to_date(:INVOICE_DATE,'DD.MM.YY'), | to_date(:PAYMENT_DEADLINE,'DD.MM.YY'), :POINTS)""" | | And I'm trying to execute it as: | c = db.cursor() | c.execute(SQL, CARDREF=id, BANKKEY=dc_kluc, OK1=okd, OK2=okc, | DEBTEUR=iznos_eur, DEBTDEN=iznos_mkd, INVOICE_DATE=datum_g, | PAYMENT_DEADLINE=datum_d, POINTS=bodovi) | And I get an ORA-01036 exception. | | I also have tried | args = dict(CARDREF=id, BANKKEY=dc_kluc, OK1=okd, OK2=okc, | DEBTEUR=iznos_eur, DEBTDEN=iznos_mkd, INVOICE_DATE=datum_g, | PAYMENT_DEADLINE=datum_d, POINTS=bodovi) | c = db.cursor() | c.execute(SQL, **args) Shouldn't that be c.execute(SQL, args) (no **-unpacking of the dictionary)? -- Vincent Wehren | Same thing. | | Everything works If I use python string substituion, like this sql: | SQL = """insert into D.D_NOTIFY values (%s,'%s','%s','%s','%s','%s', \ | to_date('%s','DD.MM.YY'),to_date('%s','DD.MM.YY'),'%s')""" % fields | | Any ideas? | | | -- | damjan From jdc at uwo.ca Wed May 18 12:18:43 2005 From: jdc at uwo.ca (Dan Christensen) Date: Wed, 18 May 2005 12:18:43 -0400 Subject: Representing ambiguity in datetime? In-Reply-To: <%vxie.25534$VH2.13093@tornado.tampabay.rr.com> References: <5hvk81prupnpinq4ucspsikdqns5rmcaf0@4ax.com> <%vxie.25534$VH2.13093@tornado.tampabay.rr.com> Message-ID: <87hdh08q3g.fsf@uwo.ca> Ron Adam writes: > So it seems using 0's for the missing day or month may be how to do it. This doesn't allow more specific amounts of ambiguity. I suggest either a pair of dates, which represent the earliest and latest that the event could have been (and are equal if there is no ambiguity), or a date plus a number of days of uncertainty, i.e. 21 June 2005 +- 5 days. Dan From jfine at pytex.org Thu May 26 03:14:53 2005 From: jfine at pytex.org (Jonathan Fine) Date: Thu, 26 May 2005 08:14:53 +0100 Subject: Writing a bytecode interpreter (for TeX dvi files) Message-ID: <4295776D.2070601@pytex.org> I'm writing some routines for handling dvi files. In case you didn't know, these are TeX's typeset output. These are binary files containing opcodes. I wish to write one or more dvi opcode interpreters. Are there any tools or good examples to follow for writing a bytecode interpreter? I am already aware of opcode.py and other modules in Python Language Services, in the Library Reference. Thanks. -- Jonathan http://texd.sourceforge.net From roy at panix.com Mon May 2 20:17:20 2005 From: roy at panix.com (Roy Smith) Date: Mon, 02 May 2005 20:17:20 -0400 Subject: empty lists vs empty generators References: <509534af.0505021514.5e49aa2@posting.google.com> Message-ID: In article <509534af.0505021514.5e49aa2 at posting.google.com>, brian at mirror.org (Brian Roberts) wrote: > I'm using using generators and iterators more and more intead of > passing lists around, and prefer them. However, I'm not clear on the > best way to detect an empty generator (one that will return no items) > when some sort of special case handling is required. The best I can come up with is to depend on the fact that for item in foo: pass only defines item if foo yields any items. Assuming item is not defined before you execute the for loop, you can check to see if it's defined after the loop, and use that to tell if foo was an empty list or generator. Here's a demo. Unfortunately, I'm not sure if it's really any cleaner than your way (but at least it doesn't add any extraneous variables) # Creates an iterator which yields n items. class gen: def __init__(self, n): self.n = n def __iter__(self): for i in range(self.n): yield None def checkEmpty(genOrList): for item in genOrList: pass try: item print "%s had items" % genOrList except NameError: print "%s was empty" % genOrList checkEmpty(gen(0)) checkEmpty(gen(1)) checkEmpty([]) checkEmpty([1]) -------------- Roy-Smiths-Computer:play$ ./gen.py <__main__.gen instance at 0x36c620> was empty <__main__.gen instance at 0x36c620> had items [] was empty [1] had items From fredrik at pythonware.com Tue May 17 10:46:29 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 17 May 2005 16:46:29 +0200 Subject: \r functionality References: <1116325048.303756.222070@z14g2000cwz.googlegroups.com> Message-ID: "Jake" wrote: > in c and c++ there is a useful way to refresh an output line in printf > and cout using \r meta command. that's a control character that's printed to the terminal by printf/cout, not a "C or C++ meta command" to print the same character in Python, use the same character escape: print "\r", count, (note that if this works or not depends on the terminal you're sending the output to. most ordinary terminals handle it just fine, but if you're sending output to an IDE console window, it may not work as expected) From opengeometry at yahoo.ca Wed May 18 15:48:32 2005 From: opengeometry at yahoo.ca (William Park) Date: Wed, 18 May 2005 15:48:32 -0400 Subject: Comparing 2 similar strings? Message-ID: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> How do you compare 2 strings, and determine how much they are "close" to each other? Eg. aqwerty qwertyb are similar to each other, except for first/last char. But, how do I quantify that? I guess you can say for the above 2 strings that - at max, 6 chars out of 7 are same sequence --> 85% max But, for qawerty qwerbty max correlation is - 3 chars out of 7 are the same sequence --> 42% max (Crossposted to 3 of my favourite newsgroup.) -- William Park , Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html From rbt at athop1.ath.vt.edu Wed May 18 17:25:49 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 18 May 2005 17:25:49 -0400 Subject: socket programming and port scans Message-ID: I don't fully understand sockets, I just know enough to be dangerous. The below is not detected by nmap, but is affected by iptables or ipsec. Can anyone explain why that is? s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((ip_param, port_param)) while 1: s.listen(5) I can connect to the socket server and even transmit data so I know it's there. Thanks, rbt From bdesth.quelquechose at free.quelquepart.fr Wed May 11 17:40:02 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Wed, 11 May 2005 23:40:02 +0200 Subject: Python Documentation (should be better?) In-Reply-To: References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> Message-ID: <428276e8$0$318$626a14ce@news.free.fr> Ivan Van Laningham a ?crit : > Hi All-- > The Python docs are not ideal. I can never remember, for instance, > where to find string methods (not methods in the string module, but > methods with ''), >>> dir('') ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] HTH From R.Brodie at rl.ac.uk Fri May 27 07:10:08 2005 From: R.Brodie at rl.ac.uk (Richard Brodie) Date: Fri, 27 May 2005 12:10:08 +0100 Subject: struct unpack newline References: <1117189007.980813.182830@g14g2000cwa.googlegroups.com> Message-ID: wrote in message news:1117189007.980813.182830 at g14g2000cwa.googlegroups.com... > except when line[86:90] contains "carriage-return" "linefeed" > which are valid binary packed values. You probably don't want to be reading binary data a line at a time, if that's what you're doing. From exarkun at divmod.com Thu May 26 15:43:25 2005 From: exarkun at divmod.com (Jp Calderone) Date: Thu, 26 May 2005 19:43:25 GMT Subject: os independent way of seeing if an executable is on the path? In-Reply-To: <429564a4@usenet01.boi.hp.com> Message-ID: <20050526194325.559.1978971544.divmod.quotient.10482@ohm> On Thu, 26 May 2005 11:53:04 -0700, Don wrote: >Steven Bethard wrote: > >> This has probably been answered before, but my Google skills have failed >> me so far... >> >> Is there an os independent way of checking to see if a particular >> executable is on the path? Basically what I want to do is run code like: >> i, o, e = os.popen3(executable_name) >> but I'd like to give an informative error if 'executable_name' doesn't >> refer to an executable on the path. >> >> [snip] >> >> Thanks for the help, >> >> STeVe > >I wrote this 'which' function for Linux, but I think if you changed the ':' >character, it would work on Windows (I think its a ';' on Windows, but I >can't remember): > >def which( command ): > path = os.getenv( 'PATH' ).split( ':' ) > found_path = '' > for p in path: > try: > files = os.listdir( p ) > except: > continue > else: > if command in files: > found_path = p > break > > return found_path > Here's the version that comes with Twisted: import os, sys, imp def which(name, flags=os.X_OK): """Search PATH for executable files with the given name. @type name: C{str} @param name: The name for which to search. @type flags: C{int} @param flags: Arguments to L{os.access}. @rtype: C{list} @param: A list of the full paths to files found, in the order in which they were found. """ result = [] exts = filter(None, os.environ.get('PATHEXT', '').split(os.pathsep)) for p in os.environ['PATH'].split(os.pathsep): p = os.path.join(p, name) if os.access(p, flags): result.append(p) for e in exts: pext = p + e if os.access(pext, flags): result.append(pext) return result Jp From rkern at ucsd.edu Sat May 7 09:18:56 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 07 May 2005 06:18:56 -0700 Subject: Encryption with Python? In-Reply-To: <009901c552fb$220132e0$0201a8c0@mcuf7> References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com><001301c552db$dd19d3e0$0201a8c0@mcuf7> <009901c552fb$220132e0$0201a8c0@mcuf7> Message-ID: Anthra Norell wrote: > Thanks a lot for the feedback. This is certainly a great learning > experience. It's a fascinating topic too. Without wishing to annoy, I'd be > interested in knowing more. I insert questions below. > > ----- Original Message ----- > From: "Robert Kern" > To: > Sent: Saturday, May 07, 2005 11:11 AM > Subject: Re: Encryption with Python? > > > >>Anthra Norell wrote: >> >>>I rolled my own for relatively short sequences, like passwords. The key > > is > >>>an integer. To decrypt use the negative encryption key. I consider the >>>encryption unbreakable, as it is indistinguishable from a random > > sequence. > >>>Frederic >>> >>>### >>> >>>def crypt (sequence, key): >>> import random >>> sign = (key > 0) * 2 - 1 >>> random.seed (abs (key * sign)) >>> s = '' >>> for i in xrange (len (sequence)): >>> r = random.randint (0, 255) >>> s += chr ((ord (sequence [i]) + r * sign) % 256) >>> return s >> >>The mind boggles. >> >>You do realize that if I have two ciphertexts encrypted with the same >>key, I can subtract them? Then I have a sequence, that while not >>immediately readable, is just a straightforward combination of the two >>plaintexts without any encryption. > > How do you know the same key was used? I don't necessarily, but if the same key *is* used, I'll know. The differences of the ciphertexts will have distinctly non-random characteristics (well, assuming the plaintexts aren't one-time pads themselves). > What if the messages aren't the same length? Then I just look at the common portion. > How does one reconstruct either or both of two messages from their > difference? Analyzing patterns, frequencies, and also using prior knowledge I may know or guess about the contents. This is only slightly worse (for the attacker) than tackling a straight substitution cipher. >>This function is also vulnerable to a chosen-plaintext attack. The >>underlying PRNG is definitely not suitable for cryptographic >>applications. The documentation even says so! > > What is a plain-text attack? "Chosen-plaintext," please. > Is it you give me a plain text. I encrypt it > using the same keys and hand you the result? More or less. > Would I comply with the > request? Depending on how your cryptosystem is deployed, you may not have a choice. A cryptosystem ought to be resistent to chosen-plaintext attacks regardless of how you intend to deploy it. >>http://docs.python.org/lib/module-random.html >>"However, being completely deterministic, it is not suitable for all >>purposes, and is completely unsuitable for cryptographic purposes." > > The logic escapes me if it is understood to mean that cryptography, in order > to be usable, has to be indeterministic. The two characteristics "completely deterministic" and "unsuitable for cryptographic purposes" are only mildly related. One *definitely* wouldn't use any PRNG to generate keying material. You should rely on physical sources of randomness. Most modern OSes have some way to access reliable entropy from your machine. Unices usually have this as /dev/random. But that's a separate issue. Additionally, one should not use the Mersenne Twister PRNG, which is what Python uses, as the PRNG for the stream cipher. Given a particular value or series of values, it is possible to determine one's position in the PRNG sequence and can, in essence derive the key. Some techniques can be used to hide actual current state of the PRNG like applying a cryptographic hash to the value from the PRNG. However, it's easier and far better to just use a cryptographically strong PRNG from the start. > If, however, it is meant to suggest > that it is the reversible, direct one-on-one relation between all the > characters of a plain text and its encryption that falls short of > state-of-the-art technology, I'd have no problem with that. That doesn't > mean, however, that an exercise is required to measure up to > state-of-the-art standards in order to be taken seriously. I do invent my > own solutions for simple problems. This is not a simple problem. But fortunately, there *is* a relatively simple answer. Besides Paul Rubin's p3.py (which to my limited ability to determine is probably "best-of-breed" for the limits imposed upon it), there is a very simply-coded stream cipher that *is* cryptographically strong if the appropriate details are observed. It's called RC4 (or ARCFOUR). A reasonably good cryptosystem built around that cipher is called Ciphersaber-2. http://ciphersaber.gurus.com/cryptanalysis.html There are dozens of implementations floating around, but it's ridiculously easy to code up by yourself. > I find it more challenging than stalking > other people's solutions how ever superior and typically it also saves me > time. It is not my ambition to excel in any field, nor to flaunt my > erudition. It is my ambition to satisfy the requirements of a given task. > And this, I think, my solution does. I can be wrong and if so, I'd > appreciate being proven wrong. I have now received well-meaning advice for > which I am grateful. But I haven't been proven wrong. You haven't proved your claim that your cipher is "unbreakable." Your notion of "unbreakable" is also flawed; "indistinguishable from 'random' sequences" is only one part of cryptosystem security. For that matter, you haven't proven that the ciphertexts produced are "indistinguishable from random sequences." Note the plural. It's important. You have a positive obligation to back your claim. I've pointed you to two obvious attacks that can be made against your system and also to resources that you can read to improve your knowledge of the issues. I *don't* have an obligation to spend more of my time meeting your arbitrary challenge. My reluctance to do so is not support for your claim. > I claim that my > solution satisfies the requirements of the task at hand and challenge anyone > to prove the contrary. You can meet the challenge by deciphering the > following tiny message, knowing now the encryption method, which in practice > would not be known Bull. And irrelevant. Kerckhoffs' Principle "A cryptosystem should be secure even if everything about the system, except the key, is public knowledge." http://en.wikipedia.org/wiki/Kerckhoffs'_principle > and, as it seems, would hardly be suspected by > deciphering experts for its amateurishness. This is not something to rely upon. >>Do yourself a favor and don't try to roll your own cryptographic >>functions. Do everyone else a favor and don't call something >>"unbreakable" unless you actually have the domain expertise to make that >>determination. > > Here's the challenge. Prove this breakable > > '\x10\x88d\x1d\xba\xa1\xdcK\x05w\x02/s\xa7Q0\xeb8\xb6Gx\xef\xcb\x1e=\xf5\x7f > \x9bI\xcb(\x87>\xa5\x04\xc1soF\xfd\xc6\xc6\xd9|\x971\xdb\xcdT\tw#\x86a\xdc\x > b8P\xfb=n\xda\x80\x9f\x84m\x12\x98\x98\xca=o\x0b\x8e\x08O\xb7\x0b\x04SC\x96\ > xc7\xab*\x0b\x996\x06\x86\x83(\x8dQ\x9eG\x8f$\xb2x)\xa9fv\x0c1B\x9b\r\xde\xf > fc\x08' > > When you give up we may try a plain-text attack. Okay? I have better things to do with my time. It's not me that needs to prove anything. You came here and made a claim. I am asking you to back it up. Until you do so, you don't have much right to challenge me to prove anything. >>And do read _Practical Cryptography_. > > I certainly will. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From mensanator at aol.com Sun May 1 13:21:42 2005 From: mensanator at aol.com (mensanator at aol.com) Date: 1 May 2005 10:21:42 -0700 Subject: My personal candidate for QOTW (was: Python interpreter in Basic or a Python-2-Basic translator.) In-Reply-To: References: <1114953507.031865.244920@g14g2000cwa.googlegroups.com> Message-ID: <1114968102.673519.215780@o13g2000cwo.googlegroups.com> Cameron Laird wrote: > In article <1114953507.031865.244920 at g14g2000cwa.googlegroups.com>, > Engineer wrote: > . > . > . > >The security 'droids have decided that since the MS Office Suite is a > >"standard" application then software written in MS Office VBA must be > >"safe." Any other development environments (such as Java, Perl, > . > . > . Obviously, this is a new usage of "safe" with which I have prviously been unaware. From qwweeeit at yahoo.it Sun May 15 11:59:02 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 15 May 2005 08:59:02 -0700 Subject: Mandrake 10.1 and Python 2.3.4 In-Reply-To: References: Message-ID: <1116172742.477298.116930@g14g2000cwa.googlegroups.com> Hi Joal, I can only tell you that in my Linux Mandrake 10.1 (Community Edition), all is ok: Python 2.3.4 (#2, Aug 19 2004, 15:49:40) [GCC 3.4.1 (Mandrakelinux (Alpha 3.4.1-3mdk)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import site >>> dir (site) ['_Helper', '_Printer', '__builtin__', '__builtins__', '__doc__', '__file__', '__name__', '_dirs_in_sys_path', '_init_pathinfo', '_test', 'addpackage', 'addsitedir', 'encoding', 'here', 'makepath', 'os', 'prefixes', 'sitedirs', 'sys'] >>> This can't exclude that the error is in Mandrake's site (if you have the Official Edition), but I can't help you further because I am not an expert. Bye. From max2 at fisso.casa Thu May 5 13:04:07 2005 From: max2 at fisso.casa (max(01)*) Date: Thu, 05 May 2005 17:04:07 GMT Subject: python and glut In-Reply-To: <1115236689.318521.111420@z14g2000cwz.googlegroups.com> References: <1115236689.318521.111420@z14g2000cwz.googlegroups.com> Message-ID: Lonnie Princehouse wrote: > See if you can run `glxgears`, and read the output of `glxinfo`. If > neither of those work, you will probably have better luck on a debian > or XFree86/xorg forum than on c.l.py > your hints were helpful anyway. thanks! ok, i uncommented the line: Load "glx" in my /etc/X11/XF86Config file. now glxgears seems to work... except for the following message: Xlib: extension "XFree86-DRI" missing on display ":0.0". can you give some more help? (sorry again for being offtopic) max From Sebastien.Boisgerault at gmail.com Mon May 2 07:51:28 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 2 May 2005 04:51:28 -0700 Subject: doctest's ELLIPSIS References: <1114789524.038880.312510@g14g2000cwa.googlegroups.com> <1114790657.829547.59680@g14g2000cwa.googlegroups.com> <1114792468.495670.98150@z14g2000cwz.googlegroups.com> <1114793929.180986.195870@o13g2000cwo.googlegroups.com> Message-ID: <1115034688.315872.31320@z14g2000cwz.googlegroups.com> (Forwarded from Python bug tracker) [ 1192554 ] doctest's ELLIPSIS and multiline statements Tim Peters: [...] doctest has few syntax requirements, but the inability to start an expected output block with "..." has always been one of them, and is independent of the ELLIPSIS gimmick. I doubt this will change, in part because the complications needed to "do something about it" are probably pig ugly, in part because it's so rare a desire, and in part because there are easy ways to work around it (like arranging for the expected output to start with something other than '...'). From peter at engcorp.com Wed May 11 09:46:26 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 11 May 2005 09:46:26 -0400 Subject: Pipes of binaries - IPC::Run In-Reply-To: References: Message-ID: Swaroop C H wrote: > Is there a Python equivalent of Perl's IPC::Run module [ > http://search.cpan.org/dist/IPC-Run/lib/IPC/Run.pm ] ? I don't know Perl, and don't plan to read all of that page you referenced, but judging from the subject line and the half-sentence description near the top of that page, you are looking for: os.system os.popen popen2 (module) subprocess (module, in 2.4) Read about each and, preferring subprocess (as the most recent), try them out for yourself. -Peter From mwm at mired.org Sat May 21 12:46:32 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 21 May 2005 11:46:32 -0500 Subject: first release of PyPy References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116644536.741250.249860@g44g2000cwa.googlegroups.com> <1116653460.808204.74460@g43g2000cwa.googlegroups.com> <87mzqpytep.fsf@wilson.rwth-aachen.de> Message-ID: <86fywgy1av.fsf@guru.mired.org> Shane Hathaway writes: > Torsten Bronger wrote: > Even if things don't turn out that way, note that each generation of > programming languages builds on its predecessors, and PyPy could help > bootstrap the next generation. Assemblers first had to be written in > machine code; when it was possible to write assemblers in assembly, > people started writing complex grammars and came up with C. C compilers > first had to be written in assembly; when it was possible to write C > compilers in C, people started inventing high level languages. Now > people are experimenting with high level compilers written in high level > languages. Where will this pattern lead? Who knows. :-) Your history of programming languages skips so many steps that it's misleading. For instance, C didn't arrive ab initio. It was preceeded by B, which was a derivative of BCPL. From the history at , it seems that B slowly evolved into C. B started life as an interpreted language, with a compiler that generated pseudo-code. The first B compiler was written in TMG, which was a high-level language designed for creating compilers - well, sorta. Based in that history, it seems likely that the first program that compiled a language called C was written in B. I'm used to seeing the term "high level languages" used for languages a lot like C, to distinguish them from assembler. See for one definition. "Very high level languages" used to be popular, but I haven't seen it used much. At least one person classifies Python as such . In any case, powerful dynamic languages - of which python is an example - date back to LISP. The first LISP compiler in LISP almost certainly predates C. Basically, there's a *lot* of history in programming languages. I'd hate to see someone think that we went straight from assembler to C, or that people didn't understand the value of dynamic languages very early. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From lucrodsilva at gmail.com Thu May 5 17:17:38 2005 From: lucrodsilva at gmail.com (Luciano Rodrigues da Silva) Date: 5 May 2005 14:17:38 -0700 Subject: Py2Exe security In-Reply-To: <1115249595.645525.233470@z14g2000cwz.googlegroups.com> References: <1115121780.404491.84240@f14g2000cwb.googlegroups.com> <1115129613.564775.21660@g14g2000cwa.googlegroups.com> <117f3lk633rbs87@corp.supernews.com> <1115249595.645525.233470@z14g2000cwz.googlegroups.com> Message-ID: <1115327858.725472.243630@f14g2000cwb.googlegroups.com> I think that encrypt with public/private key will be a solution in your case. I don't know if python has a module to do this kind of encrypt. From vincent at visualtrans.de Tue May 3 13:52:52 2005 From: vincent at visualtrans.de (vincent wehren) Date: Tue, 3 May 2005 19:52:52 +0200 Subject: trouble with lists References: <1115142163.472256.205930@o13g2000cwo.googlegroups.com> Message-ID: schrieb im Newsbeitrag news:1115142163.472256.205930 at o13g2000cwo.googlegroups.com... | I'm new to python. I tried doing this | | >>> x = [[]] * 3 | >>> print x | [ [] [] [] ] | >>> x[0].append( 2 ) | [ [2] [2] [2] ] | | I confused with the last line output. I actually expected something | like | | [ [2] [] [] ] | | Can anyone give me an explanation. help!! The library reference can! See http://docs.python.org/lib/typesseq.html Look at the section "notes (2)": """Values of n less than 0 are treated as 0 (which yields an empty sequence of the same type as s). Note also that the copies are shallow; nested structures are not copied. This often haunts new Python programmers; consider: >>> lists = [[]] * 3 >>> lists [[], [], []] >>> lists[0].append(3) >>> lists [[3], [3], [3]]"""etc. -- Vincent Wehren From enderkanchou at gmail.com Wed May 18 00:23:28 2005 From: enderkanchou at gmail.com (Anthony) Date: 17 May 2005 21:23:28 -0700 Subject: python and os.system() failure References: <1115075139.022119.321880@l41g2000cwc.googlegroups.com> Message-ID: <1116390208.730020.146480@g14g2000cwa.googlegroups.com> Michael Hoffman wrote: > > Why aren't you using NamedTemporaryFile instead? Using mkstemp adds a > lot of complications that are usually unnecessary. I believe I originally used mktemp(), but forgot how I learned that I should use mkstemp() instead. I originally wrote the script over 1.5 years ago. =) I may have been afraid of the "deleted when closed" at the time, but now that really isn't an issue. > > I will try to explicitly call a close() or whatever the syntax is to > > finalize the object to deletion by garbage collection. > > Files created with mkstemp are neither closed nor deleted when they are > finalized. I don't see how GC comes into it either. Ah, that may explain it. Python.org did not say that mkstemp() is outside of close or gc. I tried to both close and call gc at various intervals, but, obviously, neither affected the running of the script. Thanks alot, I think this will help. -- Anthony From tnaran at no-more-virii-please.direct.ca Tue May 24 22:37:44 2005 From: tnaran at no-more-virii-please.direct.ca (Travers Naran) Date: Wed, 25 May 2005 02:37:44 GMT Subject: Counting occurences of words in a list of strings Message-ID: Here's the basic idea. I have a dictionary of substrings (the substrings stored as keys). I have a list of strings. I want to find out, for each word in the dictionary, how many times the substring occurs non-overlapping occurrences there are in the list of strings. This is the best I could come up with: for j in self.dict.keys(): c = 0 for i in tc.strings: c += i.count(j) self.dict[j]['count'] += c I tried Boyer-Moore-Horspool as someone else suggested in the group, but it was even slower (probably because of the time spent setting up the pattern). Even when I split the algorithm in two, doing the set-up before the inner loop and only testing the pattern in the inner loop, it was still slow. So, am I doing this the optimal way or am I overlooking something _really_ simple to do? Statistics on the data: The dictionary has 3000+ entries in it. There are several thousand strings. The strings average 10-26 characters in length. From vmlinuz at abisen.com Tue May 3 12:10:23 2005 From: vmlinuz at abisen.com (Anand S Bisen) Date: Tue, 03 May 2005 11:10:23 -0500 Subject: distributing scripts Message-ID: <4277A26F.50303@abisen.com> Hello, What is a good way to distributing python scripts as a package. Since lately i am facing lots of issues with my python scripts not being able to run properly due to either (old python 2.2 at the client machine) or missing module. Is there a way by which i can solve these issues revolving around my scripts ??? thanks Anand From roccomoretti at hotpop.com Mon May 30 11:42:24 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Mon, 30 May 2005 10:42:24 -0500 Subject: first release of PyPy In-Reply-To: <1117300983.547630.252310@g44g2000cwa.googlegroups.com> References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116880764.260884.286720@g49g2000cwa.googlegroups.com> <42934634.5060105@gmx.de> <1117116529.063166.286590@g43g2000cwa.googlegroups.com> <1117300983.547630.252310@g44g2000cwa.googlegroups.com> Message-ID: Kay Schluehr wrote: > Anton Vredegoor wrote: > > >>I'm not involved in PyPy myself but this would seem a logical >>possibility. To go a step further, if the compiler somehow would know >>about the shortest machine code sequence which would produce the >>desired effect then there would be no reason to limit onself to only >>those relatively inefficent standard code sequences that are inside >>system dll's. > > > Are You shure that this problem is effectively solvable in any > language? Since You did not precise Your idea I'm not shure whether You > want to solve the halting-problem in PyPy or not ;) I'm always amazed at how many people take the intractableness of the halting problem as a reason to not even try. Sure, you can't tell if an *arbitrary* program halts or not, but there are many where you can. (Assuming a perfect Python Interpreter): c = 5 + 6 halts. c = 5 while 1: c = c + 6 doesn't. A trip through the Zope internals may be a little harder to decide. But one might argue that code that does not give a clear "yes, it halts" is poorly written, and should be rewritten to be better behaved. At any rate, Anton isn't talking about solving the halting problem, but is hinting more along the lines of introspecting the code and, for example, substituting a bubble sort for a quick sort when the specific circumstances determine that it would be quicker. Granted, giving the "best" code sequence would be tough to impossible to determine, but a "better" code sequence would still make people happy. From frederik_BCOL at vanrenterghem.biz Wed May 4 16:36:40 2005 From: frederik_BCOL at vanrenterghem.biz (Frederik Vanrenterghem) Date: Wed, 04 May 2005 22:36:40 +0200 Subject: ssl-enabled python for arm linux Message-ID: Hi, I'm trying to get libgmail to run on my iPAQ running Familiar Linux. I've installed the arm-linux Python distribution from http://www.vanille.de/projects/python.spy As it doesn't appear to have been compiled with OpenSSL, I have copied _ssl.so from the Debian ARM repository, but now I'm encountering errors in the application I try to run - errors I'm not seeing when running the app on my Debian box. My question is: was it ok to take _ssl from the Debian arm archive, and if it was, should I take anything else as well to get a Python able to access https pages? Thx, -- Frederik Vanrenterghem This sentence no verb. http://vanrenterghem.biz GPG Fingerprint: 966B 0E4B 25C1 CC04 E2CB 8D4C 117F 6469 8925 BDE0 From dformosa at dformosa.zeta.org.au Sun May 15 22:33:49 2005 From: dformosa at dformosa.zeta.org.au (David Formosa (aka ? the Platypus)) Date: Mon, 16 May 2005 02:33:49 GMT Subject: 20050111: list basics References: <1105512773.543336.29930@c13g2000cwb.googlegroups.com> Message-ID: On 12 Jan 2005 08:22:04 GMT, Abigail wrote: [...] > Wrong. Perl functions don't take memory addresses. Perl doesn't allow > the programmer to do direct memory access. Perl's pack function will allow you to do direct memory access if you ask it to via the "p" and "P" templates. -- Please excuse my spelling as I suffer from agraphia. See http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more. Free the Memes. From pinard at iro.umontreal.ca Thu May 12 11:53:16 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Thu, 12 May 2005 11:53:16 -0400 Subject: How "return" no return ? In-Reply-To: <3ehaurF34ak0U1@individual.net> References: <3ehaurF34ak0U1@individual.net> Message-ID: <20050512155316.GA10734@phenix.progiciels-bpi.ca> [Ximo] > I want that the return sentence don't return anything, how can I do > it? `return' always return something (if we except the case of generators). Used without arguments, it returns None, as you discovered already. If a function "falls through" its end, None is implicitely returned. A function always have a value. I do not understand the need of "not returning anything". What do you mean? What is the real need? > [...] pass don't run too. `pass' surely runs. However, `pass' is not a `return' statement. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From steven.bethard at gmail.com Sun May 22 23:45:19 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 22 May 2005 21:45:19 -0600 Subject: How come print cannot be assigned to a variable? In-Reply-To: References: <1116600042.622872.49850@g14g2000cwa.googlegroups.com> Message-ID: John Doe wrote: > If you need a function that prints stuff, consider these two examples: > [snip] > PrintFunc = lambda x: print x py> printfunc = lambda x: print x Traceback ( File "", line 1 printfunc = lambda x: print x ^ SyntaxError: invalid syntax See Inappropriate use of Lambda on the Python Wiki[1]. This is also a horrible idea as it means you can only print a single item: py> print 1, 2, 3 1 2 3 py> def write(x): ... print x ... py> write(1, 2, 3) Traceback (most recent call last): File "", line 1, in ? TypeError: write() takes exactly 1 argument (3 given) py> def write(*args): ... print args ... py> write(1, 2, 3) (1, 2, 3) The print statement has special spacing behavior. You could perhaps approximate it with something like: py> def write(*args): ... for arg in args: ... print arg, ... print ... py> write(1, 2, 3) 1 2 3 But why go to all this effort? STeVe [1] http://wiki.python.org/moin/DubiousPython From qwweeeit at yahoo.it Sat May 21 14:23:02 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 21 May 2005 11:23:02 -0700 Subject: ANN: Veusz 0.6 - a scientific plotting package In-Reply-To: References: Message-ID: <1116699782.367084.242100@g47g2000cwa.googlegroups.com> Hi Jeremy, I am interested in collaborating to your project, but first of all I must install Veusz and see what is the feeling I get. I'm almost a newbie in Python but I'm an old programmer and have quite a lot of experience in designing scientific software. For example I know very well contour plots also if the alghorithm I used can now be a little out-dated (some year ago it was a flash in C...). Another reason to be tempted in this adventure is the fact that your choice is exactly mine: Python and Qt (and besides that I can learn to use OO ... at last!) Bye. From dave at pythonapocrypha.com Sat May 21 11:32:38 2005 From: dave at pythonapocrypha.com (Dave Brueck) Date: Sat, 21 May 2005 09:32:38 -0600 Subject: Is Python suitable for a huge, enterprise size app? In-Reply-To: <7xacmpgxn1.fsf@ruckus.brouhaha.com> References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116443474.565264.176640@g44g2000cwa.googlegroups.com> <7xd5rn93zi.fsf@ruckus.brouhaha.com> <7x1x81d5bx.fsf@ruckus.brouhaha.com> <7xacmpgxn1.fsf@ruckus.brouhaha.com> Message-ID: <428F5496.7050704@pythonapocrypha.com> Paul Rubin wrote: > Dave Brueck writes: > >>>What do you use for HTTPS? >> >>m2crypto (plus some patches to make asynchronous SSL do what we needed). > > > That seems to be a nice piece of code, but it's still at version 0.13; Version numbers are fairly relative, though. In another project we're using some proprietary, closed source libraries (unrelated to crypto) that are version 3 and they seem buggier and less stable than m2crypto. And don't get me started on Microsoft products (we've been using DirectShow *9* in some stuff, and due to bugs in DirectShow we were completely and utterly screwed despite what the documentation said; things just didn't work as they should, and Microsoft has confirmed that it's a bug that will be fixed in some future release - so we had to backtrack, ripping out code that should work just fine, and take another stab at getting DirectShow to cooperate). Version NINE (supposedly). > if something goes wrong, are you sure you want to explain that you > were using beta-test software to protect your customers' production > financial transactions? lol - what? We're not doing any financial transactions with it (IOW - we evaluated m2crypto for what we needed to do, and it's a good fit - that we didn't evaluate it in terms of what we don't need it to do doesn't bother me). Having said that - I think we probably *would* use it for production financial transactions - but that's more a matter of closed vs. open source than Python vs not. Besides, do you really think that, if something went wrong, you'd in the end have some meeting where you explain to your customer that you were using beta software? Of course not - it just doesn't work that way. Either they won't care and will drop you because of the problem (regardless of the source) or they want some broad details. > There's also been some traffic on the > python-crypto list about Zope encountering memory leaks with it. Ok... so? I mean, if there's a memory leak, and it's hurting us, we have options: we can go look in the source code, we can make Zope reboot itself often, we can hire somebody to fix it, we can see if the author wants to give us a support contract, etc. Memory leaks aren't exactly unique to Python - according to bugs.sun.com, there are currently 382 *open* bugs related to memory leaks in the JDK alone. If you're using Java in your "huge, enterprise size app" and get bit by one of those bugs, and if you're not a big enough company to get some ridiculously-priced support contract from Sun, what are your options? Again, this seems more like an open-vs-closed source issue, but to me it's another reason why I'd feel uncomfortable using Java in mission critical work. -Dave From roy at panix.com Thu May 19 08:58:16 2005 From: roy at panix.com (Roy Smith) Date: Thu, 19 May 2005 08:58:16 -0400 Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116442276.918194.194110@g44g2000cwa.googlegroups.com> <1116450537.626601.251990@g49g2000cwa.googlegroups.com> Message-ID: "George Sakkis" wrote: > Another issue that hasn't been mentioned so far is staffing. You can > find java programmers and software engineers a dime dozen, but for > python it will be harder. Yes, there are a lot more people out there who put Java on their resume than put Python on their resume. Most of those so-called Java programmers write total crap. Of course, there's a lot of crap written in Python too. But since there're a lot more Java programmers out there, it stands to reason that there's a lot more crappy Java programmers too. It's a lot easier to teach a good programmer Python than it is to teach a crappy programmer good software engineering skills. From fredrik at pythonware.com Fri May 6 06:13:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 6 May 2005 12:13:27 +0200 Subject: RFC 2822 format date printing function in python References: <20050506081914.42197.qmail@web8408.mail.in.yahoo.com> Message-ID: "praba kar" wrote: > In Php we can print RFC 2822 formatted date by > date('r') with parameter r. Then it will print the > below format date. > "Thu, 7 Apr 2005 01:46:36 -0300". > I want to print same RFC 2822 format in python. Is it > possible in python? . If possible kindly mention the > function related to print RFC format date here's what I replied the last time you asked about RFC 2822 dates: the timestamp format you're using is also known as the RFC(2)822 format. the "email" package contains several functions to deal with this format: >>> x = 1112962934 >>> from email.Utils import formatdate >>> formatdate(x) # default is utc 'Fri, 08 Apr 2005 12:22:14 -0000' >>> formatdate(x, localtime=1) 'Fri, 08 Apr 2005 14:22:14 +0200' >>> from email.Utils import parsedate_tz >>> parsedate_tz(formatdate(x, localtime=1)) (2005, 4, 8, 14, 22, 14, 0, 1, 0, 7200) for the full story, see: http://docs.python.org/lib/module-email.Utils.html you may want to save copies of questions you've already asked, and the replies you got, so you can avoid asking the same questions over and over again. (yes, this also applies if you're a bot). From michele.simionato at gmail.com Sun May 1 12:43:11 2005 From: michele.simionato at gmail.com (Michele Simionato) Date: 1 May 2005 09:43:11 -0700 Subject: Reusing object methods? In-Reply-To: References: Message-ID: <1114965791.266499.116690@f14g2000cwb.googlegroups.com> If you need just a single method once, don't use a mixin; just do B.meth = A.meth.im_func. Do not underestimate the burden of mixins on people reading your code (at least, for me it is burden, since I have to draw the inheritance tree in my mind, look at which methods are involved, wonder about the resolution order etc.) Michele Simionato From andy2O at hotmail.com Wed May 11 11:33:25 2005 From: andy2O at hotmail.com (andy2O at hotmail.com) Date: 11 May 2005 08:33:25 -0700 Subject: OO design question / Transform object in place? Message-ID: <1115825605.654601.137580@f14g2000cwb.googlegroups.com> Hello comp.lang.py, Can you help me with ideas for the following (somewhat newbie) OO design question in Python? Note, I'm using psuedo-code, not actual Python for the examples! Background: ----------- I need to represent a small variety of mathematical constructs symbolically using Python classes. 1) I have classes, representing numbers, symbolic variables etc. 2) I have classes for groups of these objects, such as a symbolic Sums. 3) To simplify the mathematical constructs, I've provided each of the classes with a simplify(self) method. The following psuedo-code gives an example a = Variable('a') b = Variable('b') two = Number(2) #Yes there are good reason not #to just use Python's int object! :-) expression1 = Sum([a,b,a,a,two]) #This represents a+b+a+a+2 then calling "expression1.simplify()" would invoke Sum.simplify() and reduce expression1 to 3*a+b+2 Question: --------- Now suppose I set "expression2 = Sum([a,-a])" and Sum.simplify() recognises that the two terms cancel and the Sum has value 0. Can I make "expression2.simplify()" transform expression2 from an instance of Sum to an instance of Number(0) **in place**? Is that possibe, or do I really have to write expression2 = SimplifyFunction(expression2) and use the function return to set expression2 to be a Number(0) object, which is annoying for a variety of reasons! Have I made a mistake in the design? Many thanks, andy. From steven.bethard at gmail.com Sun May 29 11:20:37 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 29 May 2005 09:20:37 -0600 Subject: How do i read just the last line of a text file? In-Reply-To: References: <1117341766.166081.132240@o13g2000cwo.googlegroups.com> <9v0om2-5fl.ln1@rogers.com> <429959E6.9040208@lexicon.net> <998om2-5fl.ln1@rogers.com> Message-ID: Andy Leszczynski wrote: > Chris F.A. Johnson wrote: >> And to answer the question in the subject line: >> >> last_line = file(argv[1]).readlines()[-1] >> >> Both of which assume "from sys import argv". > > What if a file is long enough? Huh? You mean what if it's too big to fit in memory? Then try this: for last_line in file(argv[1]): pass At the end of the for loop, last_line should be bound to the last line in the file. (If there's a chance your file might not have any lines, you'll want to do some error checking...) STeVe From peter at engcorp.com Mon May 2 17:05:57 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 02 May 2005 17:05:57 -0400 Subject: Running script in background. In-Reply-To: <4274DB6A.5020906@syscononline.com> References: <1114930327.902938.204630@z14g2000cwz.googlegroups.com> <4274DB6A.5020906@syscononline.com> Message-ID: Larry Bates wrote: > You have two choices: > > 1) You can use Windows Scheduler to run the script in the > background. I have lots of scripts that I do this with. > > 2) You can convert the script into a Windows Service, which > will run in the background continuously. > > I know of no way to manually start something in the foreground > and have it execute in the background (unlike on Linux). Depending on your definition of "background", the "START" command in Windows is one way of doing precisely that. START /? for help... -Peter From news at NOwillmcguganSPAM.com Tue May 31 05:32:57 2005 From: news at NOwillmcguganSPAM.com (Will McGugan) Date: Tue, 31 May 2005 10:32:57 +0100 Subject: How to run functions in the background? In-Reply-To: References: <429B3A9E.9060201@mailshack.com> Message-ID: <429c2f4b$0$24082$db0fefd9@news.zen.co.uk> Ognjen Bezanov wrote: > > I had a look into this, but have decided on pymedia, which was more > focused on well... media. > > Either way thanks all of you, I have written my first threaded program, > and it does what I need it to perfectly. > > The only thing i have a problem with now is how to communicate with the > thread, I need to send commands such as "play","pause" and the like to > it. someone here mentioned queues, but searching the python > documentation only have me a description of the queue object. > > Is there anywhere where I can find out about queues, for people who know > python but have not had a lot of experience with threaded programs? Cheers Queues take most of the hassle out of thread programming. You need to come up with an object that encapsulates all the commands you may need. In your case, it sounds like a string is all you'll need. The thread with the player periodically monitors the queue for commands with Queue.get, and your other thread occasionaly sends commands by putting them on the queue with Queue.put. If the queue is the only point of contact between your threads (ie they dont share data), then you should find it a breeze to set up. Will -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") From jabel at plus.net Fri May 27 04:14:11 2005 From: jabel at plus.net (John Abel) Date: Fri, 27 May 2005 09:14:11 +0100 Subject: Running a python program during idle time only In-Reply-To: <4296D550.7090304@plus.net> References: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> <1116869538.611233.264960@g14g2000cwa.googlegroups.com> <5j64x9gz09.fsf@idiom.com> <4296D2E3.8060605@hathawaymix.org> <4296D550.7090304@plus.net> Message-ID: <4296D6D3.6080502@plus.net> John Abel wrote: >Shane Hathaway wrote: > > > >>Mike Meyer wrote: >> >> >> >> >>>On a completely different topic, this looks like the wrong way to solve >>>the problem. You want to update a search engine based on changes to the >>>underlying file system. The right way to do this isn't to just keep >>>rescanning the file system, it's to arrange things so that your scanner >>>gets notified of any changes made to the file system. I did something like >>>this for my web site search engine, but that's hooked into the SCM that's >>>used for propogating changes to the web site. I know someone is working >>>on patches to the FreeBSD kernel to make this kind of thing work. It would >>>seem that some of the "backup" facilities that worked by keeping a mirror >>>of the disk on separate media would have to have used such hooks, but maybe >>>not. >>> >>> >>> >>> >>I think you're right that filesystem change notification is what Carlos >>needs. >> >>If you're interested in using Linux, Carlos, "inotify" is a new kernel >>module that can notify your program of filesystem changes. It's not >>folded into the mainline kernel yet, but it's a clean patch. >> >>http://www.edoceo.com/creo/inotify/ >> >>I don't know if Windows has anything like it. I'd be interested to hear >>if it does. >> >>Shane >> >> >> >> >Using the PyWin32 extensions, you can register an event with the kernel, >and then have the script sleep. If I can remember how, I'll post some >code. It's been a while since I coded specific Win32 stuff. > >J > > Couldn't find my code, but this page has various ways of doing it on Win32. http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html HTH J From pgmoscatt at optushome.com.au Wed May 11 05:15:04 2005 From: pgmoscatt at optushome.com.au (Peter Moscatt) Date: Wed, 11 May 2005 19:15:04 +1000 Subject: Using TCL files in Python ? Message-ID: I am reasonably new to programming in Python. [Using LINUX] Up until now I have been using GUI widgets supplied by 'Tkinter' but starting to realise that Tkinter have limited widgets. I have been given the lead that I should look at other sources for GUI widgets - namely TCL. I have just done a search for 'tcl' files on my 'Fedora 3' installation and find I have available: Tix8.1 Tcl8.4 Tk8.4 I have never used TCL code under Python so I assume I can use widgets from any of these providers ? Where is a good resource I can use to help understand how to use TCL files in Python ? Thanks for your help. Pete From reder at jpl.nasa.gov Tue May 31 14:36:02 2005 From: reder at jpl.nasa.gov (Leonard J. Reder) Date: Tue, 31 May 2005 11:36:02 -0700 Subject: plotting with Python In-Reply-To: References: <429aeac6$1@news.fhg.de> Message-ID: Hi Philippe, You may want to look at HippoDraw application. The web site is http://www.slac.stanford.edu/grp/ek/hippodraw/. I have used both the C++ api and python bindings. They have a layer of python called hippoplotter.py to make it easy to instance the basic plotting canvase and place multiple plots on it. This tool is built on Qt and it was very easy for me to get going with it. Maybe worth looking at. Len Philippe C. Martin wrote: > Look at wxPython > > Regards, > > Philippe > > > > Rolf Wester wrote: > > >>Hi, >> >>I have a Python console application that is intended to be used >>interactively and I have to add plotting capabilities (multiple XY plots >>and if possible 2D-surface plots). I'm loocking for a reasonably fast >>plotting library (not GPL'ed, needs not be for free) that can be used >>under Windows. An alternative would also be a standalone application >>that can be controlled via TCP/IP from my Python application. I tried >>matplotlib but this is not fast enough (especially under Windows). I >>considered PyQwt but this is GPL'ed. So I would be very appreciative for >>any help. >> >>With kind regards >> >>Rolf Wester > > -- ____________________________________________________ Leonard J. Reder Jet Propulsion Laboratory Interferometry Systems and Technology Section 383 Email: reder at huey.jpl.nasa.gov Phone (Voice): 818-354-3639 Phone (FAX): 818-354-4357 Mail Address: Mail Stop: 171-113 4800 Oak Grove Dr. Pasadena, CA. 91109 --------------------------------------------------- From pod at internode.on.net Fri May 13 08:10:09 2005 From: pod at internode.on.net (PoD) Date: Fri, 13 May 2005 21:10:09 +0900 Subject: function with variable arguments References: <1115977954.266898.141150@g49g2000cwa.googlegroups.com> Message-ID: On Fri, 13 May 2005 02:52:34 -0700, Xah Lee wrote: > i wanted to define a function where the number of argument matters. > Example: > > def Range(n): > return range(n+1) > > def Range(n,m): > return range(n,m+1) > > def Range(n,m,step): > return range(n,m+1,step) > > this obvious doesn't work. The default argument like > Range(n=1,m,step=1) obviously isn't a solution. > > can this be done in Python? > > or, must the args be changed to a list? > def Range(n,m=None,step=1): if m is None: n,m = 0,n+1 else: n,m = n,m+1 return range(n,m,step) From Sebastien.Boisgerault at gmail.com Mon May 9 14:02:27 2005 From: Sebastien.Boisgerault at gmail.com (=?iso-8859-1?q?S=E9bastien_Boisg=E9rault?=) Date: 9 May 2005 11:02:27 -0700 Subject: Does anybody know the status of PyCon recordings? In-Reply-To: References: Message-ID: <1115661747.440960.44200@z14g2000cwz.googlegroups.com> http://www.pycon.org/talks/ Cheers, SB From flamesrock at gmail.com Wed May 4 13:48:41 2005 From: flamesrock at gmail.com (flamesrock) Date: 4 May 2005 10:48:41 -0700 Subject: Bandwith Shaping Message-ID: <1115228921.520113.245920@z14g2000cwz.googlegroups.com> Just curious - is there an easy way to shape bandwith in python. If I wanted to have a max download speed for instance -thanks From wolfgang.keller.nospam at gmx.de Fri May 6 10:19:09 2005 From: wolfgang.keller.nospam at gmx.de (Wolfgang Keller) Date: 6 May 2005 14:19:09 GMT Subject: ERP & CRM in Python References: <1114942643.046728.238980@g14g2000cwa.googlegroups.com> <1115300855.892100.261280@f14g2000cwb.googlegroups.com> Message-ID: Hello, and thanks for your reply. > We are writing a script to render a PDF from our doc. (using > openreport.org) Good to read. > > Why not mailing lists instead of online-"forums". > There is some mailing lists; > http://tinyerp.org/lists.php > ... but nobody uses it. > > > The former was made for efficient human-to-human communication, the > > latter not. > I agree. Then why not create a gateway (<->) for the forums into mailinglists 1:1? Best regards Wolfgang Keller From pyguy2 at gmail.com Thu May 19 13:46:14 2005 From: pyguy2 at gmail.com (pyguy2 at gmail.com) Date: 19 May 2005 10:46:14 -0700 Subject: SSL (HTTPS) with 2.4 In-Reply-To: References: <1116392416.139727.84630@g49g2000cwa.googlegroups.com> <428AD4D1.8030405@v.loewis.de> <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> Message-ID: <1116524774.606167.98240@f14g2000cwb.googlegroups.com> If you need some help, send me an email and if we figure this out we can post a resolution. I have used both approaches (having authored them). Or at least let me know what site you are going to and I will try them on a windows box and see if I can debug that the !@#@ is going on. john From rbt at athop1.ath.vt.edu Thu May 26 11:45:08 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Thu, 26 May 2005 11:45:08 -0400 Subject: Automatically populate and submit HTML Forms In-Reply-To: <119bq0i5r14li9d@corp.supernews.com> References: <119bq0i5r14li9d@corp.supernews.com> Message-ID: Grant Edwards wrote: > On 2005-05-25, rbt wrote: > >>How can I make a python client script connect to a Web server and >>automatically populate form fields and then submit the form? >> >>For example, say I wanted to check and see if 1924 was a leap year... >>how would I populate the 'year' field and then submit it for processing? >>I have no control of the server... just the client script. >> >>
>>

Enter a year and find out if it's a leap year: >> >> >> >>

> > > Just use urllib() and pass the form data to the urlopen() > method. If given data, it will generate a "POST" request > instead of a "GET". Here's a snippet of code from an app of > mine that "fills in a form" and submits it: > > postData = urllib.urlencode({'submit':'Remove','disp':'M','action':'change_Msgs'}) > > for msgid in msgIDs: > postData += "&msgid="+msgid > > req2 = urllib2.Request("http://mc-s6.postini.com/exec/MsgCtr",postData) > rsp2 = ClientCookie.urlopen(req2) > > In this code I've eyeballed the form and the field names are > hard-wired into the code. If your form doesn't change from one > usage to the next, that's the simplest way to do it. > > In my example I'm using ClientCookie and urllib2 to create/open > the reqeust in two steps because the request seen above won't > work without some cookie values previsouly established in code > that I've snipped. Otherwise all you'd need to do is something > like this: > > urllib.urlopen('http://whatever', > urllib.urlencode({'field1Name':'value1','field2Name':'value2'})) > Thanks Grant... I found ClientCookie and ClientForm here: http://wwwsearch.sourceforge.net/ Two great Python modules that really simplify this!!! From tjreedy at udel.edu Sun May 29 11:30:07 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 May 2005 11:30:07 -0400 Subject: How do i read just the last line of a text file? References: <1117341766.166081.132240@o13g2000cwo.googlegroups.com><9v0om2-5fl.ln1@rogers.com> <429959E6.9040208@lexicon.net><998om2-5fl.ln1@rogers.com> Message-ID: "Andy Leszczynski" > What if a file is long enough? I believe you meant "What if a file is too long to read all into memory at once?" If the file is randomly accessible (with file.seek() backwards from the end) then you can read a chunk at the end that you expect to be large enough to contain the last line and search backwards for \n (ignoring a terminating \n) to find the end of the next-to-last line. Even if the file will fit in memory, this may be faster. Terry J. Reedy From elie at flashmail.com Mon May 9 12:03:13 2005 From: elie at flashmail.com (Eli) Date: 9 May 2005 09:03:13 -0700 Subject: Question about extending the interperter Message-ID: <1115654593.479760.52610@o13g2000cwo.googlegroups.com> Hi, I've followed the Python docs about extending the Python interperter and created an extension library. I've added my functions like this: static PyMethodDef pmylib_methods[] = { {"foo", pmylib_foo, METH_VARARGS, "foo() doc string"}, ... } static PyObject *pmylib_foo(PyObject *self, PyObject *args) { ... char *p; if (!PyArg_ParseTuple(args, "s", &p)) ... } And that's works fine. The problem for me is that the pointer "p" in the last function points to the arguments: If a user caller foo("123") - p points to '123'. What I need is to point it to the whole string received - 'foo ("123")'. Is there a way I can do this? Thanks in advance, Eli From rtr at yahoo.com Mon May 16 17:10:16 2005 From: rtr at yahoo.com (rotary) Date: Tue, 17 May 2005 00:10:16 +0300 Subject: Null String Variable Message-ID: I have a variable that store a string (i.e. a variable name msg).I want to say something like that: if msg is empty ...then do something.So how can i figure that msg is empty string (no character, msg = '').Maybe a silly question but i have no programming experiense.Thanks, Leonidas From edvard+news at majakari.net Mon May 2 04:02:44 2005 From: edvard+news at majakari.net (Edvard Majakari) Date: Mon, 02 May 2005 11:02:44 +0300 Subject: Design advice for unit test asserters References: <1114085180.425079.302580@z14g2000cwz.googlegroups.com> <874qdzpdrr.fsf@titan.staselog.com> <1114629540.972450.121850@g14g2000cwa.googlegroups.com> Message-ID: <87r7gqys0r.fsf@titan.staselog.com> "Gary" writes: Hi again, > First, thanks to both Kent and Edvard for useful comments. > I certainly need to consider whether it make sense to switch to py.test at > this time; its simplicity is attractive. For what it's worth, I've also coded a simple py.test skeleton generator, which does have some funky features like creating working tests using existing doctest strings in the module. For simple cases, tests work out of the box, but mostly I use it to save typing. Of course, you'd be better off using TDD, but the program can help you there too; it is able to create a module skeleton out of py.test suite, though it is not very mature yet. You can grab it from http://majakari.net/dl/pytestgen/ if you wish to try it. -- # Edvard Majakari Software Engineer # PGP PUBLIC KEY available Soli Deo Gloria! One day, when he was naughty, Mr Bunnsy looked over the hedge into Farmer Fred's field and it was full of fresh green lettuces. Mr Bunnsy, however, was not full of lettuces. This did not seem fair. --Mr Bunnsy has an adventure From kay.schluehr at gmx.net Mon May 23 17:15:37 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 23 May 2005 14:15:37 -0700 Subject: What are OOP's Jargons and Complexities? In-Reply-To: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> Message-ID: <1116882937.938387.150210@z14g2000cwz.googlegroups.com> Xah Lee wrote: > As part of this new syntax and purity, where everything in a program is > of Classes and Objects and Methods, many complex issues and concept > have arisen in OOP. Yes and it is easy to communicate a class which represents some thing determined by object oriented analysis and can be graphed as an element of an UML diagram in your development team. This is simply the state of the art in the IT industry and if FP-people or followers of any other alternative programming style can communicate their concepts and design patterns via type-classes or parentheses as well or better than they will going to lead the dicourse and OO will fall apart. I'm just sceptical that this is going to happen. Kay From mirnazim at gmail.com Tue May 31 01:56:27 2005 From: mirnazim at gmail.com (Mir Nazim) Date: 30 May 2005 22:56:27 -0700 Subject: Report generator for object databases. Message-ID: <1117518987.193897.226100@g43g2000cwa.googlegroups.com> Hi, I m planning to use ZODB for an applicaton. Is any one aware of report generators like Data Vision, Crystal Reports, fo python object databases. Some of you may have faced/solved similar problem some where. Help appreciated. Thanks From jstroud at mbi.ucla.edu Thu May 5 13:51:29 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 5 May 2005 10:51:29 -0700 Subject: How to detect a double's significant digits In-Reply-To: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: <200505051051.29818.jstroud@mbi.ucla.edu> Significant digits are an accounting concept. As such, it is up to the accountant to keep track of these as only she knows the precision of her measurements. Koan for the day: What are the significant digits of 0.1? Hint: >>> `0.1` James On Thursday 05 May 2005 10:37 am, so sayeth mrstephengross: > Hi all... How can I find out the number of significant digits (to the > right of the decimal place, that is) in a double? At least, I *think* > that's what I'm asking for. For instance: > > 0.103 --> 3 > 0.0103 --> 4 > 0.00103 --> 5 > 0.000103 --> 6 > 0.0000103 --> 7 > > Thanks in advance! > --Steve (mrstephengross at hotmail.com) -- James Stroud, Ph.D. UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From roy at panix.com Sat May 14 07:36:07 2005 From: roy at panix.com (Roy Smith) Date: Sat, 14 May 2005 07:36:07 -0400 Subject: Returning Date As String ? References: Message-ID: Peter Moscatt wrote: > I am wanting to return the system date using the following: > > date.today() > > How would I then convert this to a string ? > > Pete datetime.data objects have a __str__() method. To convert one to a string, you just have to cause its __str__() to be invoked. The most common ways of doing that are str(), %s, or print: >>> import datetime >>> d = datetime.date.today() >>> d datetime.date(2005, 5, 14) # this is the repr() of the object >>> print d 2005-05-14 >>> str(d) '2005-05-14' >>> '%s' % d '2005-05-14' From mefjr75 at hotmail.com Mon May 2 19:32:53 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 2 May 2005 16:32:53 -0700 Subject: Mouseclick In-Reply-To: <1115074248.832660.262510@f14g2000cwb.googlegroups.com> References: <1e140f34.0505021030.9f615dc@posting.google.com> <1115065280.936189.67050@o13g2000cwo.googlegroups.com> <1115074248.832660.262510@f14g2000cwb.googlegroups.com> Message-ID: <1115076773.702183.172980@z14g2000cwz.googlegroups.com> This could be fun! # random clicks # play with values to maximize annoyance if __name__ == "__main__": import random for i in range(1000): x = random.randint(0,800) y = random.randint(0,600) Click(x,y) time.sleep(random.randint(0,20)) From fuzzyman at gmail.com Mon May 9 06:44:40 2005 From: fuzzyman at gmail.com (Fuzzyman) Date: 9 May 2005 03:44:40 -0700 Subject: ANN: rest2web 0.1.0 Message-ID: Finally, the long awaited (*ahem*) release of **rest2web**. It's an early release - lot's more features still to be added - but it all works. *Hurrah* rest2web is a tool for autogenerating websites. It allows you to store your contents in reST format, and generate pages and indexes from templates. It uses a simple but flexible templating system and generates index pages and navigation links. This means that adding new pages is as easy as dropping a text file into the right folder. rest2web will handle adding the link to the index page and creating the new page from a template and the contents. Removing a page is as easy as deleting a single file, and have rest2web automatically rebuild the indexes. The download includes the rest2web code, and docs, and a test site. The test site serves as a simple illustration of how rest2web builds pages and indexes. For full details see any of the following pages : * `rest2web Docs` - http://www.voidspace.org.uk/python/rest2web * `Example Site` - http://www.voidspace.org.uk/python/rest2web/test_site * `Quick Download (608k)` - http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=rest2web.zip The next features to add will be auto sitemap generation and a bigger change (under the hood) to make the index data available to every page in a section. This will allow pages to have sidebars with links, rather than just a single index page per section. I'm already building part of the Voidspace website with rest2web, over the next few months it will take over.... Lots of other features, tested on Linux and Windoze. Fuzzyman http://www.voidspace.org.uk/python From ahaas at airmail.net Thu May 26 15:05:56 2005 From: ahaas at airmail.net (Art Haas) Date: Thu, 26 May 2005 14:05:56 -0500 Subject: [ANNOUNCE] Twenty-fifth release of PythonCAD now available Message-ID: <20050526190556.GJ9543@artsapartment.org> I'm pleased to announce the twenty-fifth development release of PythonCAD, a CAD package for open-source software users. As the name implies, PythonCAD is written entirely in Python. The goal of this project is to create a fully scriptable drafting program that will match and eventually exceed features found in commercial CAD software. PythonCAD is released under the GNU Public License (GPL). PythonCAD requires Python 2.2 or newer. The interface is GTK 2.0 based, and uses the PyGTK module for interfacing to GTK. The design of PythonCAD is built around the idea of separating the interface from the back end as much as possible. By doing this, it is hoped that both GNOME and KDE interfaces can be added to PythonCAD through usage of the appropriate Python module. Addition of other PythonCAD interfaces will depend on the availability of a Python module for that particular interface and developer interest and action. The twenty-fifth release consists primarily of bug fixes. The compatibility code for the GTK Action and ActionGroup classes introduced in the previous release had a number of bugs which have been fixed. People running PythonCAD on PyGTK releases prior to 2.4 should find this latest release working correctly due to these fixes. Thanks go to Wilbert Knol for helping identify and test the proposed fixes for this problem. A number of changes to the event handling code also are include in this release. Previously various event handling routines either returned an incorrect value, or returned a value when not needed. This release cleans up many of these issues, making the event handling code easier to follow as well as better conforming to GTK/PyGTK requirements. Various other bug fixes and code enhancements are present in this release as well. A mailing list for the development and use of PythonCAD is available. Visit the following page for information about subscribing and viewing the mailing list archive: http://mail.python.org/mailman/listinfo/pythoncad Visit the PythonCAD web site for more information about what PythonCAD does and aims to be: http://www.pythoncad.org/ Come and join me in developing PythonCAD into a world class drafting program! Art Haas -- Man once surrendering his reason, has no remaining guard against absurdities the most monstrous, and like a ship without rudder, is the sport of every wind. -Thomas Jefferson to James Smith, 1822 From gsakkis at rutgers.edu Mon May 16 18:39:04 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 16 May 2005 15:39:04 -0700 Subject: Markov chain with extras? References: <1116278880.976106.191780@o13g2000cwo.googlegroups.com> Message-ID: <1116283144.051195.193370@g44g2000cwa.googlegroups.com> > Hi All, > > Could someone show me how to do this? > > I want to generate a list using a Markov chain, however, as well as > using the previous two items in the list to decide the current choice I > want the decision to be also dependant on an item at the current > position in another list. > > I hope this explains thing clearly enough. > > Thanks, > > Malcolm What's wrong with keeping explicitly the index of the current position, say j ? Then you can index the previous two items as chain[j-1], chain[j-2] and the item in the other list as otherchain[j]. If you're talking about something else, you need to clarify the problem more. George From bill.mill at gmail.com Thu May 12 14:31:17 2005 From: bill.mill at gmail.com (Bill Mill) Date: Thu, 12 May 2005 14:31:17 -0400 Subject: How "return" no return ? In-Reply-To: <3ehkh2F366o4U1@individual.net> References: <3ehaurF34ak0U1@individual.net> <3ehc5tF35eo3U1@individual.net> <3ehkh2F366o4U1@individual.net> Message-ID: <797fe3d405051211317d6f7401@mail.gmail.com> On 5/12/05, Ximo wrote: > I am doing my own interpreter with the Python languaje. > > Do you understand me? Well, to be frank, no. However, Frederik's point still stands; in the python langage, "int a" is syntactically invalid. If you're writing your own interpreter, it should still be syntactically invalid. Could you perhaps repeat your question with an example of what behavior is surprising you? Peace Bill Mill bill.mill at gmail.com > > "Fredrik Lundh" escribi? en el mensaje > news:mailman.484.1115919541.29826.python-list at python.org... > > "Ximo" wrote: > > > >> I am doing a interpret of lines and it show me a prompt, and I want if I > >> write a declaration as "int a" my progrtam return de prompt and nothing > >> more, for exemple: > >> > >> >>> 2+2 > >> 4 > >> >>> int a > >> >>> > >> > >> Then I'm finding that de function which execute "int a" return me > >> nothing, > >> and no > >> > >> >>> int a > >> None > >> >>> > > > > what Python version are you using? here's what a normal Python > > interpreter is supposed to do with your example: > > > >>>> 2+2 > > 4 > >>>> int a > > File "", line 1 > > int a > > ^ > > SyntaxError: invalid syntax > >>>> > > > > > > > > > > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > From kay.schluehr at gmx.net Wed May 18 15:55:57 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 18 May 2005 12:55:57 -0700 Subject: EpyDoc problem In-Reply-To: References: <428A5CAA.906@geochemsource.com> <428A66A8.9090000@geochemsource.com> Message-ID: <1116446157.756809.97320@g49g2000cwa.googlegroups.com> Laszlo Zsolt Nagy wrote: > I had to patch EpyDoc. The author was not responding and there is no mailing > list for EpyDoc. Is it still a live project? EpyDoc is hosted in Sourceforge. This alone may answer your question about a bug-tracker: http://sourceforge.net/tracker/?atid=405618&group_id=32455&func=browse Ciao, Kay From kenneth.m.mcdonald at gmail.com Tue May 31 02:10:48 2005 From: kenneth.m.mcdonald at gmail.com (Kenneth McDonald) Date: Tue, 31 May 2005 01:10:48 -0500 Subject: Questions on using Qt or wxWindows with Python and OS X Message-ID: If this is not an appropriate newsgroup for this type of posting, please let me know and (if possible) suggest an alternative. I've done a fair bit of research on the net, but information is scattered all over the place and I haven't been able to find mailing lists relating specifically to python and UIs. I'd like to start using Python for some GUI programming again. I'd like to use Tk, but it seems to be dying a slow death, so it's probably time to look at wxPython and PythonQt. I'd appreciate any comments on the relevant merits of these two libraries, both with respect to Python and more generally. I know about the differences in licensing, that's not an issue. My most specific concerns are ease of use (which includes how much in the way of documentation or examples for using through Python are available, and how easy the Python libs are to use in each case); availability of a generally capable styled text widget, as one of the things I need to build is an editor, which needs to be able to handle different fonts, styles, tabs, and so forth; and ease of installation on a Macintosh, since that is my preferred dev platform, and installing things made for other UNIX variants can be a little wonky at times. I'm also curious as to the quality of documentation available for wxPython and wxWindows, and any differences between the wxWindows text widget (which is generally Scintilla I believe), and the Qt text widget classes. I've had a hard time finding good docs for wxWindows or wxPython, and the bit of documentation on Scintilla I've found and read seems to indicate that it has some restrictions, such as needing to use the same line height for all lines regardless of content. Many thanks for any feedback you can give. Cheers, Ken From gnb at itga.com.au Thu May 19 02:58:44 2005 From: gnb at itga.com.au (Gregory Bond) Date: Thu, 19 May 2005 16:58:44 +1000 Subject: processing a Very Large file In-Reply-To: <86wtpv3esw.fsf@guru.mired.org> References: <118mdpnji58bvb6@corp.supernews.com> <86wtpv3esw.fsf@guru.mired.org> Message-ID: <5fdh6d.nn6.ln@lightning.itga.com.au> Mike Meyer wrote: > > Unknown. Python relies on the C alloc/free routines for handling > memory. del may immediately free() the memory (I don't know), but that > doesn't mean it gets released to the OS. None of the implementations > of alloc/free I'm aware of ever give the memory back to the OS. They > store it in a data structure for internal reuse. > ... and in any serious OS, if memory is not reused it will eventually page out anyway, so the total cost of not releasing the memory back to the OS is miniscule (an entry or two in a page table) and the benefit of releasing it basically nil[*], while the effort of working out whether memory can be released or not is possibly quite significant. [* Excepting possible swap-space exhaustion, I suppose.] From fredrik at pythonware.com Sun May 15 01:44:19 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 15 May 2005 07:44:19 +0200 Subject: Faster GUI text control References: Message-ID: "none <"@bag.python.org> wrote: > > no, it would mean writing some python code. if all you need is a scrolling > > text list, you can simply use the code on this page: > > > > http://effbot.org/zone/wck-4.htm > > > > (see "A scrollable list view, with scrollbar support" and, optionally, > > the virtual data modifications under "Displaying Huge Data Sets") > > > > the resulting widget will update at constant speed, independent of the > > data size. > > > > > > Thanks for the suggestion. I looked at that, but I need to be able to > selectively change colors on parts of the text and I didn't think I > could do that with a list box. Am I misunderstanding that? yes. the list view isn't a listbox, it's a new widget. with the list view, you control the drawing yourself, and can draw things in whatever way you want. (the section "Non-Standard Rendering" talks about this; reading http://effbot.org/zone/wck-3.htm also helps). From roy at panix.com Mon May 16 19:37:12 2005 From: roy at panix.com (Roy Smith) Date: Mon, 16 May 2005 19:37:12 -0400 Subject: Python on a public library computer References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> Message-ID: Timothy Smith wrote: > there's a few (brave) public access unix shell providers out there. if > you could run telnet you could use them If you want to go that route, I highly suggest panix.com. They've been in business forever, are geek friendly, and have a technical support staff (and attitude) that just can't be beat. I get a unix shell account from them, mostly for mail and news access (but, on occasion, it's nice to have a unix box I can ssh into from anywhere). They're currently running Python-2.4. A couple of the active pythonistas that hang out here have panix accounts. From borges2003xx at yahoo.it Tue May 31 04:19:22 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 31 May 2005 01:19:22 -0700 Subject: regular expression problem Message-ID: <1117527562.055872.93830@o13g2000cwo.googlegroups.com> hi everyone there is a way, using re, to test (for es) in a=[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14] if a list b is composed by three "sublists" of a separated or not by elements. if b=[a2,a3,a4,a7,a8,a12,a13] gives true because in a we have [....,a2,a3,a3,...,a7,a8,...,a12,a13,...] or b=[a1,a2,a5,a14] gives true because in a we have [a1,a2,....,a5,...,a14] and so on... thank in advance. giorgio borghi From nospam at here.com Mon May 16 09:29:19 2005 From: nospam at here.com (Matt Feinstein) Date: Mon, 16 May 2005 09:29:19 -0400 Subject: Applying a function to a 2-D numarray Message-ID: Is there an optimal way to apply a function to the elements of a two-d array? What I'd like to do is define some function: def plone(x): return x+1 and then apply it elementwise to a 2-D numarray. I intend to treat the function as a variable, so ufuncs are probably not appropriate-- I realize that what I'm looking for won't be terrifically efficient, but I'd like to avoid doing it in the -worst- possible way. Some things I've looked at include things like def applyfun(m,f): elist = [f(e) for e in m] return reshape(elist,m.shape) however, I can see that this looks neat but probably generates several copies of the array, which is not so neat. Is there a better way? Matt Feinstein -- There is no virtue in believing something that can be proved to be true. From flupke at nonexistingdomain.com Mon May 2 05:54:38 2005 From: flupke at nonexistingdomain.com (flupke) Date: Mon, 02 May 2005 09:54:38 GMT Subject: __del__ and logging In-Reply-To: References: <5Clce.76603$Io7.4986997@phobos.telenet-ops.be> Message-ID: Vinay Sajip wrote: > flupke nonexistingdomain.com> writes: > > >>Hi, >> >>i have a class and a class attribute log which is a logger object. In >>the __del__() function i want to log a message but it fails even if i >>use self.__class__.log. >> >>The error i get is this: >>Traceback (most recent call last): >> File "C:\Python24\lib\logging\__init__.py", line 712, in emit >> self.stream.write(fs % msg) >>ValueError: I/O operation on closed file >> >>So is there no way to use the logger object in a __del__ >>I wanted to use the message to clearly indicate in the logger file that >>the instance had closed ok. >> > > > It all depends. If your __del__ is being called via atexit() for application > cleanup, for example, logging may not be available to you because it has been > cleaned up beforehand. > > The logging module registers an atexit() handler to flush and close handlers > before script termination. > > Vinay Sajip > > Thanks i was able to solve it using a function registered in both the classes i used in that project. Why would one use __del__ instead of atexit then especially if the calls you make in __del__ are so unrelieable? Regards, Benedict From onurb at xiludom.gro Fri May 13 04:39:11 2005 From: onurb at xiludom.gro (bruno modulix) Date: Fri, 13 May 2005 10:39:11 +0200 Subject: Python Documentation (should be better?) In-Reply-To: References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> <428276e8$0$318$626a14ce@news.free.fr> Message-ID: <428467b1$0$5860$626a14ce@news.free.fr> Ivan Van Laningham wrote: > Hi All-- > Yes. There are multiple ways I can correct myself, some, I'm sure, > involving chains and whips. Well, if you like it... > But you're all missing the point: > Christopher is right! Python docs are not as good as PHP docs. That's a POV, not a fact. > Why > not? Why do I have to be told "Hey, there are fifty ways to get what > you want!" when I should be able to go to the main doc page and SEE the > right link to click. I fail to see why would it would be better to have to open a browser, go to python.org, go to the doc, find the right link etc instead of just typing dir(xxx) and/or help(xxx). -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From hancock at anansispaceworks.com Thu May 12 01:13:37 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Thu, 12 May 2005 00:13:37 -0500 Subject: Python Documentation (should be better?) In-Reply-To: <1115844146.719570.158550@g47g2000cwa.googlegroups.com> References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <1115844146.719570.158550@g47g2000cwa.googlegroups.com> Message-ID: <200505120013.37038.hancock@anansispaceworks.com> On Wednesday 11 May 2005 03:42 pm, flamesrock wrote: > I don't know what you guys are talking about!! > In idle: > help(module) > > I love the way python handles documentation. Its not invansive Yeah, and if you write your docstrings with reasonable care it works for your own modules, too! I love that. ISTM, that Python is the best "Literate Programming" language yet available (much easier than cweb and whatnot that gave us the term). -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From jerf at jerf.org Mon May 2 16:21:25 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Mon, 02 May 2005 16:21:25 -0400 Subject: compare two voices References: Message-ID: On Mon, 02 May 2005 13:58:07 -0500, phil wrote: > You didn't indicate how deep you want to get into the code yourself. > > I am gonna step way out of my mathematical depth here I mean no disrespect, but this is the last accurate statement you made. I wouldn't say this, except that if the original poster tries to follow your advice, they'd be wasting a lot of time, so in I feel obligated to speak out. If it were that easy, phoneme recognition would have been a solved problem in the 70s. It is quite a bit harder than just waving Matlab at the problem. Based on the subsequent posts by the original poster, giving me a better feel of their skill level, I would estimate that in order to get to where they want to be, they are a minimum of nine years of solid work away from solving the problem, assuming no degree in computer science. (Such a degree would equip them better to know how hard the problem is, though you could get an undergrad degree without acquiring the requisite knowledge; with an undergrad degree in hand, subtract two years.) I am completely, 100% serious on that time estimate, and that's just to get you to the point where you *may* be able to solve the problem. Anyone who tells you it's less either has a solution in hand that you can use (good, but nobody has chimed up yet, except one guy to say it's really, really hard, he knows because he tried, so I'm not holding my breath), or has no clue what they are talking about. (We are often trained to be unthinkingly encouraging, but it is a net good to discourage someone from wasting significant amounts of time, oblivious to the fact they are unlikely to succeed. If the original poster wishes to dedicate that much time to the project, I would be happy to tell them how they can begin the process of learning what they need to learn, as long as they are aware of what they are starting.) From rbt at athop1.ath.vt.edu Wed May 25 10:06:14 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Wed, 25 May 2005 10:06:14 -0400 Subject: uploading files to a webdav SSL enabled server Message-ID: Has anyone used pure python to upload files to a webdav server over SSL? I have no control over the server. I can access it with all of the various webdav GUIs such as Konqueror, Cadaver, etc. by using a URL like this: webdavs://dav.hostname.com/user_name/uploads My goal is to upload files automatically with a python script. The server requires authentication over SSL which I can do with urllib2 like this: def auth_against_url(url, username, password): # This is a slightly modified version that I found here: # http://simon.incutio.com/archive/2004/07/15/instant import urllib2 import base64 request = urllib2.Request(url) b64 = base64.encodestring('%s:%s' % (username, password))[:-1] request.add_header('Authorization', 'Basic %s' % b64) try: f = urllib2.urlopen(request) print f.read() f.close() return True except urllib2.HTTPError, e: print e return False auth_against_url('https://dav.hostname.com/user_name/uploads',\ str.strip(raw_input('Enter User ID: ')),\ str.strip(raw_input('Enter Password: '))) If urllib2 supported webdav, I think I'd be in business, but it doesn't. Any one who can provide pointers on this? I've googled around to no avail. I've began playing with Perl's HTTP::DAV and somone reccomended PHP's curl functions as well, but I wanted to try this in Python first. Many thanks, rbt From notsew-reversePreceedingAndRemoveThis at canncentral.org Wed May 4 20:15:38 2005 From: notsew-reversePreceedingAndRemoveThis at canncentral.org (weston) Date: 4 May 2005 17:15:38 -0700 Subject: Looking for Example of wxFontEnumerator Use Message-ID: <1115252138.517437.193470@g14g2000cwa.googlegroups.com> Can anyone give an example of proper usage of wxFontEnumerator? Thanks, Weston From grante at visi.com Mon May 23 14:49:51 2005 From: grante at visi.com (Grant Edwards) Date: Mon, 23 May 2005 18:49:51 -0000 Subject: how do you return an exit code with out exiting References: Message-ID: <11949efia20ca7@corp.supernews.com> On 2005-05-23, Matthew Thorley wrote: > I wrote a simple python program that scrapes a web page every > 30 secons and dumps the result in a data base. I want to use > my linux distros build in init tools to run the script in the > back ground as a daemon. The problem is when I call the daemon > script to background the program I wrote it just hangs, > waiting for my program to exit 1 or 0. My program never does > exits because its looping every 30 seconds. > > Is there a way I can pass an exit value with out actualy exiting? No. > or is there are better way to do this? Yes. To be a well-behavied daemon, you need to do the things described in this howto: http://www.linuxprofilm.com/articles/linux-daemon-howto.html Here are a couple references on how to do this in Python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 http://homepage.hispeed.ch/py430/python/ -- Grant Edwards grante Yow! Intra-mural sports at results are filtering visi.com through th' plumbing... From skip at pobox.com Sat May 21 11:25:08 2005 From: skip at pobox.com (Skip Montanaro) Date: Sat, 21 May 2005 10:25:08 -0500 Subject: first release of PyPy In-Reply-To: <1116672984.452147.244760@g43g2000cwa.googlegroups.com> References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116644536.741250.249860@g44g2000cwa.googlegroups.com> <1116653460.808204.74460@g43g2000cwa.googlegroups.com> <87mzqpytep.fsf@wilson.rwth-aachen.de> <1116672984.452147.244760@g43g2000cwa.googlegroups.com> Message-ID: <17039.21204.804075.259515@montanaro.dyndns.org> beliavsky> C++ is a higher level language than C, >From the compiler's viewpoint C++ is not much higher level than C. It has the same basic types, (structs, unions and C++ classes are really the same thing data-wise, though C++ classes can be somewhat more complex layout-wise) and supports pointers to those types as well as void pointers (pointers to untyped memory). In addition, the operators are essentially the same. Python has a somewhat higher-level set of objects, doesn't have pointers, nor does it allow untyped pointers to random chunks of memory. I would think that a run-time specializing compiler like Psyco could potentially do more with that than a C/C++ compiler can do with the data structures and operations it has to work with. Skip From doodle4 at gmail.com Fri May 20 16:18:33 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 20 May 2005 13:18:33 -0700 Subject: buffer_info error References: <1116619271.294467.51400@g44g2000cwa.googlegroups.com> Message-ID: <1116620313.966569.154020@g44g2000cwa.googlegroups.com> i am filling in a packet with source and destination address and using the buffer_info call to pass on the address to an underlying low level call. The src and dest are strings, but buffer_info expects an array. How do i deal with this? From chris at angband.org Tue May 3 13:05:46 2005 From: chris at angband.org (Operation Latte Thunder) Date: Tue, 3 May 2005 17:05:46 +0000 (UTC) Subject: twisted jabber and xmlstream Message-ID: I am playing around with Jabber with Twisted. I can receive messages just fine, and thats great, however, I am a bit confused about how to actually _send_ messages. From what I've seen, I need to call send() on the xmlstream I get when I am auth'd... and thats where I get stuck. Do I need to create the jabber message documents myself, or are there factory methods that create message, presence, iq, etc messages for me. Better yet, does anybody have an example on the web somewhere? /goes back to staring at the XmlStream API doc... TIA -- chris at acheris.net | Roma Invicta! From rkern at ucsd.edu Sat May 28 19:23:35 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 28 May 2005 16:23:35 -0700 Subject: scipy for python 2.4 In-Reply-To: <1117317168.501105.187110@z14g2000cwz.googlegroups.com> References: <1117314382.677584.133160@o13g2000cwo.googlegroups.com> <1117317168.501105.187110@z14g2000cwz.googlegroups.com> Message-ID: querypk at gmail.com wrote: > I tried to compile it from source. But it dint work.It was looking for > python2.3 .But I want to install it on pyrthon 2.4 > PLatform you mean I am using RedHat 9.0. is that what you were > referring? > can you point me to the source you are referring. I used the sourse > from this link... > > http://www.scipy.org/download/ Yes, that's the source I'm talking about (although CVS is better). I don't understand what you mean when you say that the source "was looking for python2.3." The source distribution certainly doesn't do that. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From news at titanic.co.uk Fri May 27 12:17:43 2005 From: news at titanic.co.uk (Simon Faulkner) Date: Fri, 27 May 2005 17:17:43 +0100 Subject: CygWin ODBC In-Reply-To: References: <4296f337$0$38045$5a6aecb4@news.aaisp.net.uk> Message-ID: <4297481e$0$38038$5a6aecb4@news.aaisp.net.uk> Steve Holden wrote: > Simon Faulkner wrote: > >> Hi All, >> >> I am new to Cygwin and am hoping that someone here will be able to >> tell me how to get ODBC running in Python on Cygwin. >> >> Maximum gratefullness... >> >> >> Simon > > > There's a trick to this which involves recompiling from source. If you > aren't experienced with Unix/Linux this might seem a bit intimidating. > > The latest version I worked on is mxODBC 2.0.7. If Egenix have released > something later it may incorporate these changes. Sorry they aren't > "diff -c" format. > > I also remember the need in the past to rename some ".cpp" files to > ".c", but I believe this has now been done in the distributions. > > regards > Steve Cheers Steve, I will try that next week.... Ta :-) From arserlom at gmail.com Sun May 8 15:07:58 2005 From: arserlom at gmail.com (arserlom at gmail.com) Date: 8 May 2005 12:07:58 -0700 Subject: A question about inheritance Message-ID: <1115579277.999256.269960@f14g2000cwb.googlegroups.com> Hello I have a question about inheritance in Python. I'd like to do something like this: class cl1: def __init__(self): self.a = 1 class cl2(cl1): def __init__(self): self.b = 2 But in such a way that cl2 instances have atributes 'b' AND 'a'. Obviously, this is not the way of doing it, because the __init__ definition in cl2 overrides cl1's __init__. Is there a 'pythonic' way of achieving this? Armando Serrano From cgarciaf at lucent.com Thu May 5 14:40:11 2005 From: cgarciaf at lucent.com (Carlos Garcia) Date: Thu, 5 May 2005 20:40:11 +0200 Subject: phyton memory management Message-ID: <00ec01c551a1$df8b73d0$ba565887@1068801y07c0j> Hi all, I do have a problem with python and it is that it raise an outofmemory (i comment lines in Py.java to avoid system.exit, to debug), i try to debug this issue with jprobe and realize that i get the exception even although the java heap is not in the limit, i can notice that python need a memory pick to parse the command line. The program is a command line that receive a string line that python parse and call some java classes ti execute the appropiate command, any idea? Thansk, ========================================================== Carlos Garc?a Phone : +34 91 714 8796 Lucent Technologies e-mail : cgarciaf at lucent.com Avenida de Bruselas , 8 - 28108 Alcobendas (Madrid) ========================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: From peter at engcorp.com Fri May 27 18:02:56 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 27 May 2005 18:02:56 -0400 Subject: write to the same file from multiple processes at the same time? In-Reply-To: <119ecss4o7co9ef@corp.supernews.com> References: <119ecss4o7co9ef@corp.supernews.com> Message-ID: Grant Edwards wrote: > On 2005-05-27, Peter Hansen wrote: >>Unfortunately this assumes that the open() call will always succeed, >>when in fact it is likely to fail sometimes when another file has >>already opened the file but not yet completed writing to it, AFAIK. > > Not in my experience. At least under Unix, it's perfectly OK > to open a file while somebody else is writing to it. Perhaps > Windows can't deal with that situation? Hmm... just tried it: you're right! On the other hand, the results were unacceptable: each process has a separate file pointer, so it appears whichever one writes first will have its output overwritten by the second process. Change the details, but the heart of my objection is the same. -Peter From glauco.silva at cenpra.gov.br Mon May 2 10:38:39 2005 From: glauco.silva at cenpra.gov.br (Glauco Silva) Date: Mon, 2 May 2005 11:38:39 -0300 Subject: problem in the compiler ? Message-ID: <007e01c54f24$a18bfc50$e87290c8@piau> when i creat a RadioButton and put a command = self.Function , this function is called in the creation of RadioButton. It?s right this or it?s wrong ? Thank you Glauco -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.11.1 - Release Date: 2/5/2005 From bdesth.quelquechose at free.quelquepart.fr Tue May 3 16:21:44 2005 From: bdesth.quelquechose at free.quelquepart.fr (Bruno Desthuilliers) Date: Tue, 03 May 2005 22:21:44 +0200 Subject: PHPParser pod Zope In-Reply-To: References: Message-ID: <4277d8ea$0$18802$636a15ce@news.free.fr> JZ a ?crit : > Probuje zainstalowac modul php pod zope i tam napisali dziwna rzecz ze > potrzebuje "PHP CGI program" a nie PHP CLI. Kompilacja php 5.0.4 pod > linuksem daje mi w wyniku mod_php + 5 plikow binarnych: pear, php, > php-config, phpextdist, phpsize. Zas lektura skryptu do zope jest nizbyt > jasna. Napisali: > (snip) D?sol?, ce groupe est anglophone, il serait donc tr?s probablement pr?f?rable (en tous cas pour toi, et si bien s?r tu esp?res une r?ponse, mais sinon je ne vois pas l'int?r?t de poster ici...) de nous renvoyer ?a en anglais dans le texte !-) I-too-can-speak-weird-foreign-languages-ly'yrs Bruno From Robert at AbilitySys.com Mon May 2 14:53:15 2005 From: Robert at AbilitySys.com (Robert D. Young) Date: Mon, 2 May 2005 11:53:15 -0700 Subject: Quick and dirty dialogs? References: <1115059445.673382.218000@g14g2000cwa.googlegroups.com> Message-ID: <117ctos4l3esj0b@corp.supernews.com> I use quick-and-dirty code like this: ############################################################################ # Get source directory and text file ############################################################################ Root = Tkinter.Tk() Root.title(programname) srcdir = tkFileDialog.askdirectory(title='Choose the source directory', initialdir='C:\\') srcfile = tkFileDialog.askopenfilename(title='Choose the text file', initialdir=srcdir) Root.destroy() - Robert wrote in message news:1115059445.673382.218000 at g14g2000cwa.googlegroups.com... > What's the easiest way for a script to throw up simple dialogs such as > file select and alerts? > > I thought there was something in the standard library that didn't need > TK and was cross-platform but I can't seem to get my Google-fu working > well enough to find it. > From olaamigoquepasa at hotmail.com Wed May 25 20:17:40 2005 From: olaamigoquepasa at hotmail.com (hawkesed) Date: 25 May 2005 17:17:40 -0700 Subject: setting up scipy in windows In-Reply-To: <428b07c3$0$50617$edfadb0f@dread14.news.tele.dk> References: <1116384514.608584.9180@g49g2000cwa.googlegroups.com> <428b07c3$0$50617$edfadb0f@dread14.news.tele.dk> Message-ID: <1117066659.953966.268160@z14g2000cwz.googlegroups.com> Thanks to both you guys. I got scipy up and running yesterday. Here are the steps I went through: 1. I un-installed some non-official pythons. (Plone and ActiveState) 2. I loaded STANDARD Python 2.3.5 3. I loaded Python for Windows extensions. 4. I Loaded Numeric 5. Loaded SCIPY 6. Tested it by typing in pythonwin >>> from scipy import * >>> Then played around with some of the methods. Pretty cool stuff. Thanks all! Frithiof Andreas Jensen wrote: > "hawkesed" skrev i en meddelelse > news:1116384514.608584.9180 at g49g2000cwa.googlegroups.com... > > > > Scipy looks like just the thing I want, if anyone has got it running on > > a Windows box I would like to hear how you did it. > > With STANDARD Python 2.3 it installs from the Python 2.3 win 32 installers > and runs. > > The only problem I had was that "Numeric" needs to be installed before > "Scipy" or Scipy will chrash. From Scott.Daniels at Acm.Org Mon May 16 12:42:36 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Mon, 16 May 2005 09:42:36 -0700 Subject: Quick Reference from module doc strings. In-Reply-To: References: <1116199904.205240.58300@g49g2000cwa.googlegroups.com> <42880d98$1@nntp0.pdx.net> Message-ID: <4288c71e@nntp0.pdx.net> Ron Adam wrote: > Do you have any feature suggestions, additional information that could > go in, something that would extend the content in some way and make it > more useful? > > As it stands now, it could be just a module, so you could... > The style is still a sticking point for me -- too many evals (a nasty lure for evil-doers). Recall that sys.modules is a dictionary from module names to modules. Any python object (including a module) will return attributes listed in a dir(obj) with getattr(obj, attributename). So, no evals are needed in this program at all. I also wonder if you've ever used maxlevel>1. It seems you'd expand to way too many names to be useful. Finally, if you use StringIO (or cStringIO), most of your string construction can be turned into prints in a way similar to: def printnames(namelist, dest=None): for name in sorted(namelist, key=str.lower): print >>dest, name from cStringIO import StringIO def textnames(namelist): hold = StringIO() printnames(namelist, hold) return hold.getvalue() --Scott David Daniels Scott.Daniels at Acm.Org From peter at engcorp.com Tue May 31 20:53:34 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 31 May 2005 20:53:34 -0400 Subject: The need to put "self" in every method In-Reply-To: <429CE8F4.5070301@lexicon.net> References: <1117554344.938440.54700@g14g2000cwa.googlegroups.com> <429CE8F4.5070301@lexicon.net> Message-ID: John Machin wrote: > Simon Brunning wrote: >> Of course, if you *don't* use 'self', you should expect an angly mob >> with pitchforks and torches outside your castle. > > Wouldn't an angly mob be carrying fishing rods? No, I rather think they'd be acutely obtuse, right? From could.net at gmail.com Thu May 19 04:58:05 2005 From: could.net at gmail.com (could ildg) Date: Thu, 19 May 2005 16:58:05 +0800 Subject: How to learn OO of python? In-Reply-To: References: <1116417641.929050.30860@g14g2000cwa.googlegroups.com> Message-ID: <311b5ce105051901585138aa6c@mail.gmail.com> Steven Bethard: Thank you so much! Your answer is very very helpful~ On 5/19/05, Steven Bethard wrote: > could ildg wrote: > > I think decorator is a function which return a function, is this right? > > e.g. The decorator below if from http://www.python.org/peps/pep-0318.html#id1. > > > > def accepts(*types): > > def check_accepts(f): > > assert len(types) == f.func_code.co_argcount > > def new_f(*args, **kwds): > > for (a, t) in zip(args, types): > > assert isinstance(a, t), \ > > "arg %r does not match %s" % (a,t) > > return f(*args, **kwds) > > new_f.func_name = f.func_name > > return new_f > > return check_accepts > > > > After I saw all the examples, I concluded that every decorator must > > define an inner function which takes only one argument, the > > function to decorate. Is this right? > > It's close, but not quite right. (I will use the word "function" for > the moment, but see below for why this is inaccurate.) Every > *decorator* must take only one argument, the function to decorate. It is > not at all necessary that a decorator define an inner function. > Consider (from [1]): > > def onexit(f): > import atexit > atexit.register(f) > return f > > onexit is a decorator because it takes a function and returns a > function. In this case, it happens to be that the same function is > accepted and returned. > > Note that in the 'accepts' example above, *check_accepts* is the > decorator, not accepts. The accepts function is actually a function > that *returns* decorators. > > Now about that word "function". Decorators are actually *callables* > that accept a single *callable* and return a *callable*. Why does the > terminology matter? Because I can construct decorators from classes too > (from [2]): > > class memoized(object): > def __init__(self, func): > self.func = func > self.cache = {} > def __call__(self, *args): > try: > return self.cache[args] > except KeyError: > self.cache[args] = value = self.func(*args) > return value > except TypeError: > return self.func(*args) > > Now the memoized decorator can be used just like any other decorator, e.g.: > > @memoized > def fibonacci(n): > if n in (0, 1): > return n > return fibonacci(n-1) + fibonacci(n-2) > > Note however that memoized is a *callable*, not a *function*. > > STeVe > > [1] http://www.python.org/peps/pep-0318.html > [2] http://wiki.python.org/moin/PythonDecoratorLibrary > -- > http://mail.python.org/mailman/listinfo/python-list > From nickaddisonuk at yahoo.co.uk Sun May 1 17:17:00 2005 From: nickaddisonuk at yahoo.co.uk (Nick Addison) Date: Sun, 01 May 2005 22:17:00 +0100 Subject: Running script in background. In-Reply-To: <1114930327.902938.204630@z14g2000cwz.googlegroups.com> References: <1114930327.902938.204630@z14g2000cwz.googlegroups.com> Message-ID: <42754740$0$83046$ed2619ec@ptn-nntp-reader01.plus.net> Harlin Seritt wrote: > Hi, > > I have a script.py that is converted to .exe using py2exe. From another > script I call script.exe and would like to be able to run this > script.exe in the background (as well as in console -- giving the user > some simple options). How can I make this happen? > > thanks, > > Harlin > Have you considered running the exe as a scheduled job? Or you could turn it into an NT service. I run quite a few py2exe exes as scheduled jobs set up as run once on system start up. hth Nick. From fredrik at pythonware.com Thu May 19 04:53:18 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 19 May 2005 10:53:18 +0200 Subject: Is Python suitable for a huge, enterprise size app? References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com><1116432325.497438.64580@g49g2000cwa.googlegroups.com><1116433218.495131.71260@g49g2000cwa.googlegroups.com><1116443474.565264.176640@g44g2000cwa.googlegroups.com> <7xd5rn93zi.fsf@ruckus.brouhaha.com> Message-ID: Paul Rubin wrote: > 2) If you want to display a gif image in tkinter, you can make a > frame object, put a canvas in it, and put a PhotoImage object > onto the canvas, which works fine. But if you use your own > subclass of frame (maybe to add your own gui stuff), for some > reason the gif doesn't display in the canvas. did you read the PhotoImage documentation? see e.g. the note at the bottom of this page: http://effbot.org/zone/tkinter-photoimage.htm (this used to be explained in the Python FAQ too, but it looks as if that was lost in the great FAQ reorganization). From steve at holdenweb.com Fri May 6 07:14:10 2005 From: steve at holdenweb.com (Steve Holden) Date: Fri, 06 May 2005 07:14:10 -0400 Subject: properties vs. eval() In-Reply-To: <1115328861.200050.167030@z14g2000cwz.googlegroups.com> References: <1115235178.971840.248160@o13g2000cwo.googlegroups.com> <1115282375.131965.118320@z14g2000cwz.googlegroups.com> <1115328861.200050.167030@z14g2000cwz.googlegroups.com> Message-ID: Bob Rogers wrote: > So you're saying you don't know the answer? The question wasn't > "should I use setattr?" > No, the "*question*" was (paraphrasing slightly) "is [it] possible to dispense with the compile step and use eval() alone while setting a property" the *answer* was "you should use setattr". If you don't see that this implies that using eval() is not a good idea until other resources have been exhausted, then you need to understand: "using eval() is not a good idea until other resources have been exhausted". regards Steve -- Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ From xah at xahlee.org Sun May 15 05:50:38 2005 From: xah at xahlee.org (Xah Lee) Date: 15 May 2005 02:50:38 -0700 Subject: Range function In-Reply-To: <1115951576.138445.51080@z14g2000cwz.googlegroups.com> References: <1115951576.138445.51080@z14g2000cwz.googlegroups.com> Message-ID: <1116150638.868535.10690@g14g2000cwa.googlegroups.com> Here's the Perl code. ---------- #! perl # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 #_____ Range _____ _____ _____ _____ =pod B Range($iMax) generates the list [1, 2, ... , $iMax]. Range($iMin, $iMax) generates the list [$iMin, ... , $iMax]. Range($iMin, $iMax, $iStep) uses increment $iStep, with the last element in the result being less or equal to $iMax. $iStep cannot be 0. If $iStep is negative, then the role of $iMin and $iMax are reversed. If Range fails, 0 is returned. Example: Range(5); # returns [1,2,3,4,5] Range(5,10); # returns [5,6,7,8,9,10] Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8] Range( 5, -4, -2); # returns [5,3,1,-1,-3] =cut sub Range ($;$$) { if (scalar @_ == 1) {return _rangeFullArgsWithErrorCheck(1,$_[0],1);}; if (scalar @_ == 2) {return _rangeFullArgsWithErrorCheck($_[0],$_[1],1);}; if (scalar @_ == 3) {return _rangeFullArgsWithErrorCheck($_[0],$_[1],$_[2]);}; }; sub _rangeFullArgsWithErrorCheck ($$$) { my ($a1, $b1, $dx) = @_; if ($dx == 0) {print "Range: increment cannot be zero."; return 0} elsif ($a1 == $b1) {return [$a1];} elsif ( ((($b1 - $a1) > 0) && ($dx < 0)) || ((($b1 - $a1) < 0) && ($dx > 0)) ) {print "Range: bad arguments. You have [$a1,$b1,$dx]"; return 0;} elsif ((($a1 < $b1) && ($b1 < ($a1 + $dx))) || (($a1 > $b1) && ($b1 > ($a1 + $dx)))) {return [$a1];} else { return _rangeWithGoodArgs ($a1,$b1,$dx);}; }; sub _rangeWithGoodArgs ($$$) { my ($a1, $b1, $dx) = @_; my @result; if ($a1 < $b1) {for (my $i = $a1; $i <= $b1; $i += $dx) { push (@result, $i);}; } else {for (my $i = $a1; $i >= $b1; $i += $dx) { push (@result, $i);}; }; return \@result; }; #end Range ########## # test use Data::Dumper; print Dumper(Range(5,7,0.3)); From w.ruijter at alumnus.utwente.nl Wed May 18 17:59:49 2005 From: w.ruijter at alumnus.utwente.nl (wout) Date: Wed, 18 May 2005 22:59:49 +0100 Subject: Help on slow attribute copy Message-ID: <428BBAD5.5080005@alumnus.utwente.nl> Hi there, I am fairly new to python, the problem is as follows: newnodes = {} for i in nodes: newnodes[i.label] = i.coordinate is very slow, which is due to the dots, I know that for functions the dot lookup can be done outside the loop, can this be done for attributes in any way? (in such a way that it is fast) Coordinate is a tuple in this case, filling a dictionary of that size is no problem without dots. I use python 2.0 as shipped with abaqus, there are about 100000 nodes in the current case, and more to come, and the system can be stuck on this for 15+ minutes :-( Greetings Wout This message has been checked for viruses but the contents of an attachment may still contain software viruses, which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. From jerf at jerf.org Sat May 7 10:29:16 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Sat, 07 May 2005 10:29:16 -0400 Subject: Need help subclassing Borg References: <1115480121.527653.220780@o13g2000cwo.googlegroups.com> Message-ID: On Sun, 08 May 2005 02:42:09 +1000, Steven D'Aprano wrote: > I'm thinking what I might need is a function that generates a Borg-like > class. So I would do something like: > > Rabbit = MakeBorgClass() > # Rabbit is now a class implementing shared state > # all instances of Rabbit share the same state > Duck = MakeBorgClass() > # Duck is now a class implementing shared state > # all instances of Duck share the same state > # but instances of Duck do not share state with instances of Rabbit > > Problem is, I haven't got the foggiest idea how to implement something > like that. Am I on the right track? Where do I go from here? Bengt's answer is better than this track, but this question is worth answering because it is so wonderfully easy in Python. Remember class is an executable statement, not a declaration: Python 2.3.5 (#1, Mar 3 2005, 17:32:12) [GCC 3.4.3 (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def makeBorg(): ... class Borg(object): ... _shared_state = {} ... def __init__(self): ... self.__dict__ = self._shared_state ... return Borg ... >>> Duck = makeBorg() >>> Rabbit = makeBorg() >>> d = Duck() >>> d2 = Duck() >>> d.cover = "fur" >>> d2.cover 'fur' >>> r = Rabbit() >>> r.cover Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Borg' object has no attribute 'cover' >>> r.cover = "feathers" >>> d.cover 'fur' >>> r2 = Rabbit() >>> r2.cover 'feathers' >>> (I flipped around the fur and feathers, but don't feel like fixing it :-) ) Now, the problem with this and the reason why Bengt's is more likely better is that each of these Borg classes is unrelated, so there's no using issubclass or anything like that. You *could* hack around this, but it's not worth it. (It is possible to dynamically choose the bases of a class; you can't do it in the class statement itself, but you can do something like: def makeBorg(base = object): class Borg(base): etc. but this is definitely not the best way to go. Still, as above, it does have its place other times; I've used it to dynamically pick up whether the user has certain modules installed and add support depending on the environment. I often do this when I'm writing something currently embedded in an app I'm writing, but may have use elsewhere outside of the environment of the app, allowing me to write code that both takes full advantage of the app environment, while not being completely tied to it.) From thomas at eforms.co.nz Sun May 1 22:35:11 2005 From: thomas at eforms.co.nz (Thomas) Date: Mon, 2 May 2005 14:35:11 +1200 Subject: socket error on windows, working fine on mac Message-ID: <20050502023305.B26B937A01@mail.tintz.co.nz> I am getting socket error for large file transfer on windows (100MB+) Working fine for files <50MB. Everything is working fine on mac.. File "C:\Python23\lib\httplib.py", line 576, in send self.sock.sendall(str) File "", line 1, in sendall socket.error: (10055, 'No buffer space available') cheers Thomas import httplib, mimetypes def post_multipart(host, selector, fields, files): """ Post fields and files to an http host as multipart/form-data. fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return the server's response page. """ content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTP(host) h.set_debuglevel(0) h.putrequest('POST', selector) h.putheader('content-type', content_type) h.putheader('content-length', str(len(body))) h.endheaders() #print body; h.send(body) errcode, errmsg, headers = h.getreply() return h.file.read() def encode_multipart_formdata(fields, files): """ fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance """ BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_$' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files: L.append('--' + BOUNDARY) L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename)) L.append('Content-Type: %s' % get_content_type(filename)) L.append('') L.append(value) L.append('--' + BOUNDARY + '--') L.append('') body = CRLF.join(L) content_type = 'multipart/form-data; boundary=%s' % BOUNDARY return content_type, body def get_content_type(filename): return mimetypes.guess_type(filename)[0] or 'application/octet-stream' import urllib2 import urllib2_file #URL = 'http://xxx.xxx.xxx.xxx/UploaderHttp/' FILE= 'c:/Documents and Settings/Administrator/Desktop/TM_A5_Bulk.pdf'; f = file(FILE, "rb") data = f.read() f.close() post_multipart("192.168.100.233","/UploaderHttp/",[('test','valTest')],[('FI LE1','TM_A5_Bulk.pdf',data)]); -------------- next part -------------- An HTML attachment was scrubbed... URL: From stefan_NOSPAM at NOSPAM_naewe.de Tue May 3 15:44:35 2005 From: stefan_NOSPAM at NOSPAM_naewe.de (Stefan =?UTF-8?B?TsOkd2U=?=) Date: Tue, 03 May 2005 21:44:35 +0200 Subject: text strings to binary... References: <1115149191.862429.51610@g14g2000cwa.googlegroups.com> Message-ID: oriana.falco at thalesesec.com wrote: > Hi, > > I've been working with Python for a bit now but I just came accross a > problem and I'm not sure how to approach it. I'd like to convert a text > string into binary data format. I though I'd use the struct module and > the pack function but I can't get it to work. I'm using Python 2.3.3 in > Windows XP. Why don't you post some pieces of your code ? Maybe someone can help you fix it. Stefan -- From jasondrew72 at gmail.com Wed May 4 12:27:37 2005 From: jasondrew72 at gmail.com (jasondrew72 at gmail.com) Date: 4 May 2005 09:27:37 -0700 Subject: A faster method to generate a nested list from a template? In-Reply-To: References: <117hlf2rvh6q28e@corp.supernews.com> Message-ID: <1115224057.531579.70040@z14g2000cwz.googlegroups.com> Jeff Epler wrote: > Are there only a few, unchanging templates? If so, (dynamiclly) create > a function for each template. This will be nearly the fastest you can > go in Python, excluding the time to create and byte-compile the nesting > function. > > # This code is in the public domain > def make_nesting_expression(l, s): > result = [] > for c in l: > if isinstance(c, list): > sub, s = make_nesting_expression(c, s) > result.append(sub) > else: > result.append("l[%d]" % s) > s += 1 > print "make_nesting_expression", l, result > return "[" + ",".join(result) + "]", s > > def make_nesting_function(l): > return eval("lambda l: %s" % make_nesting_expression(l, 0)[0]) > > t = [['a1','a2'],['b1'],['c1'],['d1']] > l = [1, 2, 3, 4, 5] > f = make_nesting_function(t) > print f(l) > > Jeff Nice approach! Though I'm wondering, because the "template" is so close to the function you're trying to create, why not just create the function directly? As in: >>> f5 = lambda p: (p[0:2], p[2], p[3], p[4]) >>> f5(('a', 'b', 'c', 'd', 'e', 'f')) (('a', 'b'), 'c', 'd', 'e') Or if you need to be able to remember what the template looks like (e.g. reading/writing it as a string in a file), you can always create the function by evaluating a (properly constructed) template string: >>> f5 = eval("lambda p: (p[0:2], p[2], p[3], p[4])") >>> f5(('a', 'b', 'c', 'd', 'e', 'f')) (('a', 'b'), 'c', 'd', 'e') If you want to avoid lambdas, the same ideas can be used with short defs, e.g.: def f5(p): return (p[0:2], p[2], p[3], p[4]) Incidentally, these solutions raise an IndexError if your list is too short, and silently drop the end of a list that's too long. That's my keep-it-simple-I-might-understand-it approach. Jason From greg at invalid.invalid Sat May 14 16:29:31 2005 From: greg at invalid.invalid (Greg Krohn) Date: Sat, 14 May 2005 20:29:31 GMT Subject: Modifying a built-in function for logging purposes In-Reply-To: <1116098593.970438.219860@g47g2000cwa.googlegroups.com> References: <1116098593.970438.219860@g47g2000cwa.googlegroups.com> Message-ID: qwweeeit at yahoo.it wrote: > Hi all, > I wonder if it is possible to change (temporarily) a built-in function > for logging purposes. > Let me explain: > I want to log all the 'open' operations, recording the file to be > opened, the "mode" (r/w/a...) and (possibly) the module which made the > call. > After that the 'open' can carry on following the standard built-in > path. > Possibly I don't want to have to modify the source of the application > to be logged. > If there is another solution, I am open to any suggestion... > > Bye. > Would this work? _file = file def file(path, mode): print path, mode return _file(path, mode) -greg From rkern at ucsd.edu Thu May 5 20:30:18 2005 From: rkern at ucsd.edu (Robert Kern) Date: Thu, 05 May 2005 17:30:18 -0700 Subject: F.readline In-Reply-To: References: <000001c551ca$15ddd3b0$6400a8c0@grondor> Message-ID: Erik Max Francis wrote: > Robert Kern wrote: > >>There is no such command built in. You will have to build it yourself >>out of the components that are available. > > linecache is probably what he's looking for. Well, I'll be darned, indeed it is. Hooray for the time machine. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From reinhold-birkenfeld-nospam at wolke7.net Tue May 3 03:07:10 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Tue, 03 May 2005 09:07:10 +0200 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <1115102577.942694.191810@z14g2000cwz.googlegroups.com> References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> <3dmi74F6q7m6hU2@individual.net> <1115094028.508122.174390@l41g2000cwc.googlegroups.com> <1115102577.942694.191810@z14g2000cwz.googlegroups.com> Message-ID: <3dombnF6vh6ptU1@individual.net> Dan Bishop wrote: > Well, I'd deal them into 2 piles, and... > > Damn! That was an obscure hint! > > Now, how do I open *.gfx files? You don't directly. Hint: gfx stands for? ************** SPOILER **************** Graphic*s*. From flamesrock at gmail.com Mon May 16 17:40:29 2005 From: flamesrock at gmail.com (flamesrock) Date: 16 May 2005 14:40:29 -0700 Subject: Like Christ PBBUH Prayed In-Reply-To: <1116278323.413749.302480@z14g2000cwz.googlegroups.com> References: <1116096706.696830.275140@g44g2000cwa.googlegroups.com> <1116278323.413749.302480@z14g2000cwz.googlegroups.com> Message-ID: <1116279629.332838.139870@g49g2000cwa.googlegroups.com> I don't understand.. why is everyone talking about christ on comp.lang.python? Isn't this not the place? From DaleWKing at insightbb.nospam.com Tue May 31 07:27:01 2005 From: DaleWKing at insightbb.nospam.com (Dale King) Date: Tue, 31 May 2005 11:27:01 GMT Subject: What are OOP's Jargons and Complexities? In-Reply-To: References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> <3584469.Aerji1NdQr@yahoo.com> Message-ID: <9SXme.22456$Is4.3402@attbi_s21> David Formosa (aka ? the Platypus) wrote: > On Tue, 24 May 2005 09:16:02 +0200, Tassilo v. Parseval > wrote: > >>Also sprach John W. Kennedy: > > [...] > > >>Most often, languages with strong typing can be found on the functional >>front (such as ML and Haskell). These languages have a dynamic typing >>system. I haven't yet come across a language that is both statically and >>strongly typed, in the strictest sense of the words. I wonder whether >>such a language would be usable at all. > > > Modula2 claims to be both statically typed and strongly typed. And > your wonder at its usablity is justified. I used a variant of Modula-2 and it was one of the best languages I have ever used. That strong, static type checking was a very good thing. It often took a lot of work to get the code to compile without error. Usually those errors were the programmers fault for trying to play fast and loose with data. But once you got it to compile it nearly always worked. -- Dale King From Florian.Lindner at xgm.de Mon May 2 17:23:46 2005 From: Florian.Lindner at xgm.de (Florian Lindner) Date: Mon, 02 May 2005 23:23:46 +0200 Subject: Libraries for creating graphs Message-ID: Hello, I'm looking for libraries to create graphs. I'm not talking about plotting a function like f(x)=x^2 just plotting a couple of values into a short, maybe interpolating them. Output should be something like JPEG. Thx, Florian From philippe at philippecmartin.com Sat May 7 11:58:29 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Sat, 07 May 2005 15:58:29 GMT Subject: New Python regex Doc (was: Python documentation moronicities) References: <1113301533.054410.203710@z14g2000cwz.googlegroups.com> <1113856843.023012.165500@l41g2000cwc.googlegroups.com> <1113908069.264676.207090@g14g2000cwa.googlegroups.com> <1115328523.852744.110390@f14g2000cwb.googlegroups.com> <1115423751.016177.250650@o13g2000cwo.googlegroups.com> <1115444726.627426.172260@g14g2000cwa.googlegroups.com> Message-ID: This is nice! I just might understand regex eventually. Xah Lee wrote: > erratum: > > the correct URL is: > http://xahlee.org/perl-python/python_re-write/lib/module-re.html > > Xah > xah at xahlee.org > ? http://xahlee.org/ From timothy at open-networks.net Wed May 4 08:01:53 2005 From: timothy at open-networks.net (Timothy Smith) Date: Wed, 04 May 2005 22:01:53 +1000 Subject: py2exe and library.zip In-Reply-To: References: <5uadnUTTqv6Iw-rfRVn-qw@powergate.ca> Message-ID: <4278B9B1.1060500@open-networks.net> Peter Hansen wrote: >Timothy Smith wrote: > > >>Peter Hansen wrote: >> >> >>>Anything's possible. Maybe you could explain what you're actually >>>trying to accomplish (or the reasons) so we can better understand >>>where you're going with this... >>> >>> >>> >>exactly what i just stated, i don't want py2exe to zip up it's >>library's, but to put them in a sub dir. >>the reason for this, is so that when users login and update from svn, >>they only have to download some tiny pyc files, not a great big zip file >>with everything in it ( 99% of which never changes) >> >> > >More detail on this version control thing would probably help. (Things >like that are why I asked fo more background... "exactly what I stated" >isn't as useful as something like (for example) "I want my app users to >use Subversion to retrieve updates to the application without having to >download a big zip file".) > >Do you know that Subversion has (as I understand it) a fairly >intelligent binary file comparison routine, and it will (again, as I >understand it) not transmit the entire contents of the zip file but >would actually send only the portions that have changed? At least, >that's if the file isn't compressed in some way that prevents this >algorithm from working well. (Note to self: check if zip files that can >be in sys.path can be compressed, and if py2exe compresses them.) > >Anyway, while this sort of thing isn't directly supported (probably >since almost nobody would want to do it, for reasons similar to what >Simon has explained), you should be able to work it out yourself. The >.exe produced by py2exe contains a "stub" executable that basically sets > sys.path to point to the .zip file, then runs the main .py which has >been integrated into the .exe file (not even compiled to a .pyc, just >like normal). If you modify your main .py to adjust sys.path to point >to an external subdirectory, you should be able to leave .py files (or >.pyc files) there and use svn to update them. > >I'll leave it as an exercise for the reader (mainly because I don't know >how to do it offhand) what you should do to prevent py2exe from putting >all your files in its zip. It should probably still put the standard >library modules there, since otherwise you'd have little reason to be >using py2exe in the first place... > >-Peter > > ideally i'd love to not to have to use py2exe at all, then they can just update from the stable branch of my svn. the problem with THAT is how to install python, wx,pysvn,reportlab etc etc on their systems with no fuss(py2exe convienently packages all dll's together for me). if you know of a way i can achieve that i'd be your best friend forever. the whole reason i'm going with the svn updating method is there is no user interaction required. even getting users to click a single button to update has proven too much to ask of them :/ the other reason is my particular project gets updated very often, so you can imagine the combination of users resistant to any kind of computer use with an environment requiring frequent updating. i have some other problems to solve before i get to that point, mainly svn related eg. pysvn whinges because files exist in the working directory that it wants to update ( with the same name ), only they aren't under version control. From kent37 at tds.net Sat May 28 17:19:34 2005 From: kent37 at tds.net (Kent Johnson) Date: Sat, 28 May 2005 17:19:34 -0400 Subject: Help with choice of suitable Architecture In-Reply-To: <1117311160.307176.216430@o13g2000cwo.googlegroups.com> References: <1117299643.380598.5540@g47g2000cwa.googlegroups.com> <1117311160.307176.216430@o13g2000cwo.googlegroups.com> Message-ID: <4298e04b$1_1@newspeer2.tds.net> Rob Cowie wrote: > I agree with the sentiments that a single XML file is not the way to go > for storing data that may be accessed concurrently. However, my hands > are tied. You might like to see the thread "write to the same file from multiple processes at the same time?" for a preview of the issues this raises. http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/475d065fa7871e63/c2fc42fefe114d38?hl=en#c2fc42fefe114d38 Kent From claird at lairds.us Tue May 31 12:08:03 2005 From: claird at lairds.us (Cameron Laird) Date: Tue, 31 May 2005 16:08:03 GMT Subject: Alternative history (was: prime number) References: <1117421732.677244.237730@g49g2000cwa.googlegroups.com> <86wtphtm3f.fsf@guru.mired.org> Message-ID: In article <86wtphtm3f.fsf at guru.mired.org>, Mike Meyer wrote: . . . >If it isn't a homework assignment, and you're honestly in such, then >you should know there's been a lot of research in this area, because >primes are important in cryptographic applications. Once again, google . . . There's been a lot of research in this area because some minds burn to grasp the beauty of number theory, and can't stop think- ing of Number despite blindness, hunger, family, political oppression, and the other frailties to which humans are prone. From borges2003xx at yahoo.it Tue May 24 09:06:03 2005 From: borges2003xx at yahoo.it (borges2003xx at yahoo.it) Date: 24 May 2005 06:06:03 -0700 Subject: searching substrings with interpositions References: <1116926253.186047.195260@g43g2000cwa.googlegroups.com> <3fgekjF7lq3qU1@individual.net> Message-ID: <1116939594.958040.14110@z14g2000cwz.googlegroups.com> thanx everyone, is what i need. As Claudio argues, it's a standard problem of dna sequences comparation. the next step of my job is to make limits of lenght of interposed sequences (if someone can help me in this way i'll apreciate a lot) thanx everyone. giorgio From martin at v.loewis.de Sun May 8 13:56:34 2005 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sun, 08 May 2005 19:56:34 +0200 Subject: Q: The `print' statement over Unicode In-Reply-To: References: <427cc8b2$0$26179$9b622d9e@news.freenet.de> <87r7ghg79t.fsf@pobox.com> Message-ID: <427e52d2$0$15902$9b622d9e@news.freenet.de> Jeremy Bowers wrote: > Then I'd honor his consistency of belief, but still consider it impolite > in general, as asking someone to do tons of work overall to save you a bit > is almost always impolite. This is not what he did, though - he did not break "the protocol" by sending in patches by email (which indeed we would reject). Instead, he said (before) that he cannot contribute because he is unwilling to/incapable of using a bug tracker. This is an acceptable position: contributors are volunteers, and he choses not to volunteer. He then has to accept (in the specific case) that the documentation is imprecise/incomplete. More precisely, he is correct that *his* contribution is not welcome, contrary to my broad statement "contributions are welcome". The more narrower statement "contributions that follow the guidelines are welcome" still stands. Regards, Martin From fredrik at pythonware.com Tue May 10 11:46:13 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 10 May 2005 17:46:13 +0200 Subject: Library Naming Conventions. References: <1114851378.781754.194030@z14g2000cwz.googlegroups.com><1114860766.488589.152380@o13g2000cwo.googlegroups.com> <1115739023.302545.109300@o13g2000cwo.googlegroups.com> Message-ID: chris.lyon at spritenote.co.uk wrote: > quoting: > > Modules should have short, lowercase names, without underscores. > > this still doesn't explain Cookie. the document you're quoting also says: This document was adapted from Guido's original Python Style Guide essay[2] where [2] points to a document that says: Module names can be either MixedCase or lowercase. There is no unambiguous convention to decide which to use. Modules that export a single class (or a number of closely related classes, plus some additional support) are often named in MixedCase, with the module name being the same as the class name (e.g. the standard StringIO module). Modules that export a bunch of functions are usually named in all lowercase. From jeffelkins at earthlink.net Wed May 11 08:42:23 2005 From: jeffelkins at earthlink.net (jeff elkins) Date: Wed, 11 May 2005 12:42:23 +0000 Subject: Finding startup files In-Reply-To: <1115829176.541687.22090@z14g2000cwz.googlegroups.com> References: <1115829176.541687.22090@z14g2000cwz.googlegroups.com> Message-ID: <200505111242.23778.jeffelkins@earthlink.net> On Wednesday 11 May 2005 04:32 pm, hemagician at gmail.com wrote: > The following script demonstrates a method that should work for you. I > believe it is entirely cross-platform. > > #! /usr/bin/python > > import sys > import os > > print os.path.abspath(os.path.dirname(sys.argv[0])) Works perfectly, thanks much! Jeff From rkern at ucsd.edu Tue May 17 05:26:22 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 17 May 2005 02:26:22 -0700 Subject: Python forum In-Reply-To: <4289B462.10804@softhome.net> References: <4289B462.10804@softhome.net> Message-ID: Jonas Melian wrote: > Hi, > > I'm going to say a suggestion, why don't you create a forum like the one > of Ruby (http://www.rubyforums.com/)? for the novices this is a great > help, better than a mail list > > It's also worth noting that rubyforums.com has nearly no posts (six > total) because it takes very just a short time working. > > I know that you have python-list, it's both an email and a usenet list. > But I think that a forum is great for the learning. The test is in > gentoo's forums. They are a lot of experienced people answering > questions without any problem and it goes very well Various Python web fora have sprung up now and again. None of them ever grab much of an audience. OTOH, if you're volunteering your own time and effort to set one up, I'm not going to stop you. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From simon.brunning at gmail.com Tue May 10 07:09:42 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Tue, 10 May 2005 12:09:42 +0100 Subject: Module on Getting the Date & Time In-Reply-To: <20050510092100.32410.qmail@web61108.mail.yahoo.com> References: <20050510092100.32410.qmail@web61108.mail.yahoo.com> Message-ID: <8c7f10c605051004096e13464d@mail.gmail.com> On 5/10/05, Sara Khalatbari wrote: > Is there a Modules in Python that returns the time & > date of today when ran? http://www.google.com/search?q=python+time+date -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From grante at visi.com Thu May 12 10:15:42 2005 From: grante at visi.com (Grant Edwards) Date: Thu, 12 May 2005 14:15:42 -0000 Subject: Finding startup files References: <1115829176.541687.22090@z14g2000cwz.googlegroups.com> <1184dj36mp5sdc6@corp.supernews.com> Message-ID: <1186p8e5nkrj095@corp.supernews.com> On 2005-05-11, jeff elkins wrote: > I'm totally new to Python (obvious,yes?) so how might argv[0] fail? argv[0] contains whatever is put there by the program that exec'ed you, and can therefore contain just about anything (or nothing). It may not contain a full path, and your program's install directory may not be in your $PATH (it be executed by a shortcut or symlink). If you're controlling how the program is installed and started, then you're probably safe. -- Grant Edwards grante Yow! I guess it was all a at DREAM... or an episode of visi.com HAWAII FIVE-O... From tzot at sil-tec.gr Wed May 11 10:45:13 2005 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Wed, 11 May 2005 17:45:13 +0300 Subject: unicode encoding problem References: <1114723563.553068.115410@z14g2000cwz.googlegroups.com> <42715b3e$0$3362$9b622d9e@news.freenet.de> Message-ID: On Thu, 28 Apr 2005 23:53:02 +0200, rumours say that "Martin v. L?wis" might have written: >In theory, Python should look at sys.stdin.encoding when processing >the interactive source. In practice, various Python releases ignore >sys.stdin.encoding, and just assume it is Latin-1. What is >sys.stdin.encoding on your system? The difference between theory and practice is that in theory there is no difference. -- TZOTZIOY, I speak England very best. "Be strict when sending and tolerant when receiving." (from RFC1958) I really should keep that in mind when talking with people, actually... From km at mrna.tn.nic.in Mon May 16 08:33:27 2005 From: km at mrna.tn.nic.in (km) Date: Mon, 16 May 2005 18:03:27 +0530 Subject: 20050111: list basics In-Reply-To: References: Message-ID: <20050516123327.GA21016@mrna.tn.nic.in> Hi all, > Perl's pack function will allow you to do direct memory access if you > ask it to via the "p" and "P" templates. can we do direct memory accessing in python also ? regards, KM From percivall at gmail.com Wed May 25 20:10:28 2005 From: percivall at gmail.com (Simon Percivall) Date: 25 May 2005 17:10:28 -0700 Subject: vim configuration for python In-Reply-To: References: Message-ID: <1117066228.282613.22020@g43g2000cwa.googlegroups.com> I don't know if the binary editions include the Misc directory, but if you download the Python source you'll find a directory called Misc. In it, there's a vimrc file. From cal_2pac at yahoo.com Sun May 22 16:01:33 2005 From: cal_2pac at yahoo.com (cal_2pac at yahoo.com) Date: 22 May 2005 13:01:33 -0700 Subject: How to receive events (eg. user mouse clicks) from IE In-Reply-To: <428f8660$1_1@spool9-west.superfeed.net> References: <1116476411.853695.235670@g14g2000cwa.googlegroups.com> <428c3cbe$1_1@spool9-west.superfeed.net> <1116529345.146032.91880@f14g2000cwb.googlegroups.com> <428cf5a9$1_1@spool9-west.superfeed.net> <1116537405.495521.252570@f14g2000cwb.googlegroups.com> <428f5882$1_2@spool9-west.superfeed.net> <428f8660$1_1@spool9-west.superfeed.net> Message-ID: <1116792093.323847.312700@g49g2000cwa.googlegroups.com> > This might make a good candidate for the Cookbook (or there's > a collection of IE automation examples at win32com.de) > so anybody else trying to do something similar knows some of the pitfalls. This thread has been very valuable for me and has provided clarifications which I could not get after hours of surfing web /reading python on win32 / python developer handbook and so on. Here are more questions that I am encountering a) the code above will return a click event from an anchor element. However, I need to identify which anchor element was clicked on. Similarly, if a user clicks on one cell in HTML table - I need to determine its identity. One possible solution to this will be to look at the onClick event provided by HTML_DocumentEvents and as desribed in msdn library http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/events/events.asp The problem is that msdn documentation says that in order to identify the element that was clicked - one has to query on IHTMLWindow2::event property on iHTMLWindow2 interface to get IEventOBj interface and then from there - use query interfce to get to the id of the element. How do I do this in python? ie. I have this code class Doc_Events(doc_mod.HTMLDocumentEvents): def Ononclick(self): print 'onClick fired ' and I see onClick being trapped. Now I need to go and get a reference to the iHTMLWindow2 interface. For this I need to get a reference to doc_mod (as far as I can see). How do I get that in the OnonClick method above. b) You had mentioned PumpWaitingMessages in the previous posting. I first encountered this on newsgroup postings. None of the standard books (python on win32 / python developer) seem to explain this in detail although this seems to be commonly used. Though I understand this now - my problem is that there seems to be a lack of cohesive explanation on how python ties up with COM (despite a good chapter 12 on python win32 book). How does a newbie get more info on coding? Essentially (a) is also a generic question which can be included in a standard text. If nothing of this sort exists - maybe I will think of jotting down the notes and posting on a public website. Roger Upole wrote: > Reducing the sleep time in the loop also seems to speed things up. > I'm guessing due to giving both event loops more resources, but > I can't prove it conclusively. > > This might make a good candidate for the Cookbook (or there's > a collection of IE automation examples at win32com.de) > so anybody else trying to do something similar knows some of the pitfalls. > > Roger > > "J Correia" wrote in message > news:jDKje.7423$wr.4173 at clgrps12... > > "Roger Upole" wrote in message > > news:428f5882$1_2 at spool9-west.superfeed.net... > >> There does appear to be some sort of conflict between the two event > >> hooks. I wasn't seeing it before since IE was getting google from my > >> browser cache and it was coming up almost instantaneously. As soon > >> as I switched the URL to a page that loads slowly, I got the same > >> result. > >> > >> Adding win32gui.PumpWaitingMessages() to the wait loop > >> seems to allow both event hooks to run without blocking each other. > >> > >> Roger > > > > I added that line to the wait loop and while it does indeed speed it > > up dramatically (in 10 tests: min = 13 sec; max = 33, ave ~ 20 secs) > > it's still nowhere near the 1-2 secs it takes without hooking the > > IE events. I also can't explain the wide differences between min > > and max times since they seem to occur randomly > > (e.g. min occurred on 7th run, max on 4th). > > > > I assume that that response time won't be adequate for the original > > poster's needs, due to the slowdown in browsing for his users. > > > > Jose > > > > > > > > > > > > > > > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- > http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups > ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- From tiissa at nonfree.fr Tue May 17 15:44:57 2005 From: tiissa at nonfree.fr (tiissa) Date: Tue, 17 May 2005 21:44:57 +0200 Subject: Markov chain with extras? In-Reply-To: <1116333014.950383.310040@g44g2000cwa.googlegroups.com> References: <1116278880.976106.191780@o13g2000cwo.googlegroups.com> <1116283144.051195.193370@g44g2000cwa.googlegroups.com> <1116333014.950383.310040@g44g2000cwa.googlegroups.com> Message-ID: <428a49bb$0$31079$626a14ce@news.free.fr> temp at mclift.fsnet.co.uk wrote: > I think is more easy explained as two linked markov chains. So given > one list the other can be generated. 'Given one list sounds' like an observation (and this sound like an order 2 hmm). But I'm not sure what exactly you want to do with your markov chain. Do you want the probability distribution at each time step or some value ? In this case, I'd do something like: #### hmm.py from random import random def St_given_St1_St2_Ot(St1,St2,Ot): p0=0.5*St1*St2+0.25*St1+0.125*St2+0.0625 return Ot and p0 or 1-p0 def decision(p): return (random()>p) and 1 or 0 def hmm(LO,LS): for ot in LO[2:]: p=St_given_St1_St2_Ot(LS[-1],LS[-2],ot) LS.append(decision(p)) return LS LO1=(-1,-1,1,0,0,0,1,1) LS1=[1,0] print ''.join(map(str,hmm(LO1,LS1))) LO2=(0,)*50 LS2=[1,1] print ''.join(map(str,hmm(LO2,LS2))) LO3=(1,)*50 LS3=[1,1] print ''.join(map(str,hmm(LO3,LS3))) #### Which gives hours of fun looking at random numbers: $ python hmm.py 10111101 11111111111111111111111111100000000000001000000000 11011011011011011011010110011011011011011010101101 $ python hmm.py 10101011 11111111111111111111111111111111000000000000000111 11011010011010100011010110110011001101101101011010 $ python hmm.py 10100011 11111111111111111111111111111111111111111111111111 11011010110011001101011011011101010110101101101011 $ python hmm.py 10111101 11101010000000000000000000000000000000000000000001 11011001101101011010110111010101010110110110011101 $ python hmm.py 10100011 11111111111111111111111111111111111111111111111111 11010110110110110011011010110011010011011011011010 $ Instead of generating the whole sequence, you can wrap it in an iterator. And the observations list can also be an iterator (generated with another chain if you like). HTH From kostem at gmail.com Mon May 23 17:44:16 2005 From: kostem at gmail.com (kostem) Date: 23 May 2005 14:44:16 -0700 Subject: ClientForm question Message-ID: <1116884656.597169.85640@g47g2000cwa.googlegroups.com> Hi, I need some help on using ClientForm to post to cgi and getting response. I have done this many times and it worked very well until now. I have contacted the webmaster of the page I'm interested in an this is the response I got: > Indeed, a simple wget does _not_ do the trick for > our servers. > You must start by doing a POST (e.g. not a GET) with > the > form data. From what i can guess about the python > code it > seems to be doing the post correctly. > > The response page to that form is a very short page > that > reloads another page (using javascript). This page > will eventually > contain the resulting webpage. You should try > reloading it until > it no longer tells you that your job is queued or > processing. > Use a nice poll timeout, say 10 every seconds. If > the job > takes a long time (or the queue is full) the page > will take > a few seconds to load. This is intentional, as the > cgi-script in this period automatically polls the > status of > the job, and issues a javascript re-load if it > finishes > within the time of the page-load (now showing the > result). > > Hope this helps.... The post I do returnes and error from the python code saying there is no form field called xxx but actually it exists in the form. Any help is appreciated, thanks for your time... From steven.bethard at gmail.com Sun May 29 11:46:40 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 29 May 2005 09:46:40 -0600 Subject: Newbie learning OOP In-Reply-To: <1117374143.284962.3080@z14g2000cwz.googlegroups.com> References: <1117374143.284962.3080@z14g2000cwz.googlegroups.com> Message-ID: LenS wrote: > class names: > def __init__(self, format = "F"): > self.format = format > > def namesplit(self, name): > if self.format == "F": > self.namelist = name.split() > self.first = self.namelist[0] > self.init = self.namelist[1] > self.last = self.namelist[2] > else: > self.namelist = name.split() > self.first = self.namelist[1] > self.init = self.namelist[2] > self.last = self.namelist[0] > > return self.first, self.init, self.last > > def fjoin(self): > self.namestring = self.first + ' ' + self.init + ' ' + > self.last > > def ljoin(self): > self.namestring = self.last + ' ' + self.first + ' ' + > self.init > > > Any comments appreciated. Seems to me like you really want a Name object, not a Names object. Note that fjoin() and ljoin() seem to be methods associated with an instance consisting of 'first', 'init' and 'last' attributes. But your constructor does not provide such attributes, so a call to fjoin() or ljoin() immediately after creating a new names() object will fail with an AttributeError. I would move the assignment of 'first', 'init' and 'last' into the constructor, e.g. something like: py> class Name(object): ... def __init__(self, name, format='F'): ... if format == 'F': ... self.first, self.init, self.last = name.split() ... else: ... self.last, self.first, self.init = name.split() ... def first_str(self): ... return ' '.join([self.first, self.init, self.last]) ... def last_str(self): ... return ' '.join([self.last, self.first, self.init]) ... py> n = Name('Steven John Bethard') py> n.first_str() 'Steven John Bethard' py> n.last_str() 'Bethard Steven John' py> n = Name('Bethard Steven John', 'L') py> n.first_str() 'Steven John Bethard' py> n.last_str() 'Bethard Steven John' You might consider passing a function instead of a string instead of the format parameter: py> def first_splitter(name): ... return name.split() ... py> def last_splitter(name): ... names = name.split() ... return names[1:] + names[:1] ... py> class Name(object): ... def __init__(self, name, splitter=first_splitter): ... self.first, self.init, self.last = splitter(name) ... def first_str(self): ... return ' '.join([self.first, self.init, self.last]) ... def last_str(self): ... return ' '.join([self.last, self.first, self.init]) ... py> Name('Steven John Bethard').first_str() 'Steven John Bethard' py> Name('Bethard Steven John', last_splitter).first_str() 'Steven John Bethard' This means you don't have to keep track of a mapping between strings and functions; you just pass the function objects themselves. STeVe From Scott.Daniels at Acm.Org Thu May 12 12:38:19 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Thu, 12 May 2005 09:38:19 -0700 Subject: Unique Elements in a List In-Reply-To: <87mzr0evga.fsf@titan.staselog.com> References: <1115676903.432187.294910@z14g2000cwz.googlegroups.com> <87psvzikjk.fsf@titan.staselog.com> <87mzr0evga.fsf@titan.staselog.com> Message-ID: <42838037$1@nntp0.pdx.net> Edvard Majakari wrote: > I realized that, but maybe I should've pointed it out too. For the OP if > he/she is unaware - notation O(N^2) (big O n squared) means the computing time > of the algorithm increases exponentially (where exponent is 2) relative to the > size of the input. Normally this is called a polynomial, rather than exponential increase. Exponential increases are typically of the form (C^N) (they are all equivalent). Polynomial times are hallways characterized by their largest exponent, So you never call something O(N^3 - N^2) Since, as N gets large enough, The N^2 term shrinks to non-existence. http://en.wikipedia.org/wiki/Exponential_time > ... generally one should avoid using exponential O(n^k) (where k > 1) Again polynomial, not exponential time. Note that there is no polynomial time algorithm with (k < 1), since it takes O(n) time to read the problem. --Scott David Daniels Scott.Daniels at Acm.Org From jabel at plus.net Fri May 27 04:19:23 2005 From: jabel at plus.net (John Abel) Date: Fri, 27 May 2005 09:19:23 +0100 Subject: More Rewrite Request Within SocketServer? In-Reply-To: <7xacmhgkm7.fsf@ruckus.brouhaha.com> References: <7xr7ftkt91.fsf@ruckus.brouhaha.com> <7xacmhgkm7.fsf@ruckus.brouhaha.com> Message-ID: <4296D80B.1020305@plus.net> Paul Rubin wrote: > If verify_request is finished before the new thread starts, then I'd > >think it could set a flag and the new thread could find it. You get a >race condition only if both threads are trying to mess with the flag >simultaneously. > > Hmm, I think you're right. Thanks! J From Scott.Daniels at Acm.Org Wed May 4 11:52:43 2005 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Wed, 04 May 2005 08:52:43 -0700 Subject: Read / Write image file In-Reply-To: References: Message-ID: <4278e9c1$1@nntp0.pdx.net> phil wrote: >> >> By the way, what is 'rb' and 'wb' ? >> > > Read Binary, Write Binary > In Win32 the default is text mode which > will screw up binary files > In fact, this is not just for Windows. Linux / Unix is unusual using the originally non-standards-conforming line feed ('\n') character as a line separator. Various different OS's define text files in different ways. The distinction between binary and text is a C standards thing, not a Windows goof. Heaven knows I dislike a lot of what Microsoft has done in the way of interfering with standard ways of doing things, but their end-of-line convention is not one of those things. The use of the extension ".doc" was such a deliberate violation of standards. Note older Apple files used '\r' as a line separator, Tenex used \r\n, or \037, some systems used a line count (leaving no end-of-line string), and so on.... It is a good idea to provide an indication of whether a file is binary or text to the file system; the clue could guide compression information. -Scott David Daniels Scott.Daniels at Acm.Org From tomlis at notmyisp.pl Mon May 23 06:39:00 2005 From: tomlis at notmyisp.pl (Tomasz Lisowski) Date: Mon, 23 May 2005 12:39:00 +0200 Subject: Strange behaviour of floating point constants in imported modules Message-ID: <4291b2c0$1@news.home.net.pl> Hi, We are distributing our Python application as the short main script (.py file) and a set of modules compiled to the .pyc files. So far, we have always treated .pyc files as portable between platforms, but recently we have discovered an annoying problem. In a module, there is the following code fragment: Deg2Rad = math.pi/180.0 angleEPS = 0.5 angle0B = angleEPS*Deg2Rad which calculates 'angle0B' as the angle of a half of a degree, converted to radians. The module has been compiled on an English Windows XP machine, and then tested on a Polish Windows XP workstation. What was our astonishment, when various exceptions started to be raised on a test machine (no problem on the original English-version Windows XP). We have traced them to the fact, that both angleEPS and angle0B were found to be ZERO (!!!), whereas in reality, angle0B is about 0.008. And this all happened silently, without any error during the import of the module! What's the reason of this error? I start thinking, that it may be related to the fact, that the decimal point on the Enlish Windows XP is the '.' character, and on the Polish one - ','. Is there a good method to avoid this kind of problems? How to make such distributed modules really portable? Thanks in advance -- Tomasz Lisowski From RLG101166 at yahoo.com Tue May 24 10:48:47 2005 From: RLG101166 at yahoo.com (RLG101166 at yahoo.com) Date: 24 May 2005 07:48:47 -0700 Subject: I want to ask you the most important question of your life. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? The reason some people don't know for sure if they are going to Heaven when they die is because they just don't know. The good news is that you can know for sure you are going to Heaven. May 24, 2005 10:49:20 am Message-ID: <1116946127.220677.235770@o13g2000cwo.googlegroups.com> THE MOST IMPORTANT QUESTION OF YOUR LIFE This is the most important question of your life. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? The reason some people don't know for sure if they are going to Heaven when they die is because they just don't know. The good news is that you can know for sure that you are going to Heaven. The Holy Bible describes Heaven as a beautiful place with no death, sorrow, sickness or pain. God tells us in the Holy Bible how simple it is to be saved so that we can live forever with Him in Heaven. "For if you confess with your mouth Jesus is Lord and believe in your heart that God raised Him from the dead, you will be saved." (Romans 10:9) Over 2000 years ago God came from Heaven to earth in the person of Jesus Christ to shed His blood and die on a cross to pay our sin debt in full. Jesus Christ was born in Israel supernaturally to a virgin Jewish woman named Mary and lived a sinless life for thirty-three years. At the age of thirty-three Jesus was scourged and had a crown of thorns pressed onto His head then Jesus was crucified. Three days after Jesus died on a cross and was placed in a grave He rose from the dead as He said would happen before He died. If someone tells you that they are going to die and then three days later come back to life and it actually happens then this person must be the real deal. Jesus Christ is the only person that ever lived a perfect sinless life. This is why Jesus is able to cover our sins(misdeeds) with His own blood because Jesus is sinless. The Holy Bible says, "In Him(Jesus) we have redemption through His blood, the forgiveness of sins..." (Ephesians 1:7) If you would like God to forgive you of your past, present and future sins just ask Jesus Christ to be your Lord and Saviour. It doesn't matter how old you are or how many bad things that you have done in your life including lying and stealing all the way up to murder. Just pray the prayer below with your mouth and mean it from your heart and God will hear you and save you. Dear Jesus Christ, I want to be saved so that I can have a home in Heaven with You when I die. I agree with You that I am a sinner. I believe that You love me and want to save me. I believe that You bled and died on the cross to pay the penalty for my sins and that You rose from the dead. Please forgive my sins and come into my heart and be my Lord and Saviour. Thanks Lord Jesus Christ for forgiving me and saving me through Your merciful grace. Amen. Welcome to the family of God if you just allowed God to save you. Now you are a real Christian and you can know for sure that you will live in Heaven forever when this life comes to an end. As a child of God we are to avoid sin(wrongdoing), but if you do sin the Holy Bible says, "My dear children, I write this to you so that you will not sin. But if anybody does sin, we have one who speaks to the Father in our defense Jesus Christ, the Righteous One." Those of you that have not yet decided to place your trust in the Lord Jesus Christ may never get another chance to do so because you do not know when you will die. Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever separated from the love of God in a place called Hell. The Holy Bible descibes Hell as a place of eternal torment, suffering, pain and agony for all those who have rejected Jesus Christ. The good news is that you can avoid Hell by allowing Jesus Christ to save you today. Only then will you have true peace in your life knowing that no matter what happens you are on your way to Heaven. Praise the Lord! Servant of the Lord Jesus Christ Ronald L. Grossi * Show this to your family and friends so they can also be saved. * This message may get deleted so you may want to print a copy. * Just press the [Ctrl][P] keys on your keyboard to print this page. [Please Visit These Excellent Websites] Free Video http://fathersloveletter.com/fllpreviewlarge.html Free Jesus Videos http://www.jesusvideo.org/videos/index.php Free Movie: To Hell and Back http://www.tbn.org/index.php/8/1.html Other Languages http://www.godssimpleplan.org/gsps.html The Passion Of The Christ http://www.thepassionofthechrist.com Beware Of Cults http://www.carm.org/cults/cult_list.htm About Hell http://www.equip.org/free/DH198.htm Is Jesus God? http://www.powertochange.com/questions/qna2.html Free Online Bible http://www.biblegateway.com From bokr at oz.net Fri May 6 23:00:54 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 07 May 2005 03:00:54 GMT Subject: Reference to self not passed to member function References: <200505061533.02116.jstroud@mbi.ucla.edu> Message-ID: <427c2a33.869538890@news.oz.net> On Sat, 7 May 2005 01:06:31 +0200, "Fredrik Lundh" wrote: >James Stroud wrote: > >> I did this: >> >> py> class bob(object): >> ... def __init__(self,**kwargs): >> ... for fname,func in kwargs.items(): >> ... setattr(self, fname, lambda *args : func(*args)) >> ... >> py> def doit(): >> ... print "wuzzup?" >> ... >> py> abob = bob(doit=doit) >> py> >> py> abob.doit() >> wuzzup? >> >> Much to my surprise, this works fine. > >why is that surprising? "doit" is a callable, you wrap it in another >callable, and then you store it in an attribute. > >that's no different from storing a integer as an attribute, and it >sure doesn't turn your callable into an instance method. > >> 1. What exactly is going on? > >see above. > >> 2. How can I get ref to self passed to doit() if I want it to? > >try using this bob instead: > > import new > > class bob(object): > def __init__(self, **kwargs): > for fname, func in kwargs.items(): > setattr(self, fname, new.instancemethod(func, self, bob)) > ISTM "instancemethod" doesn't really tell the story of what that usage means, which is actually storing a bound method as an attribute of the instance it _happens_ to be bound to. I.e., this "instancemethod" is a bound method that could be stored as an attribute of _anything_ and if used as a callable the function would see the same bound "self" no matter where the bound method was picked up from (well, unless someone perversely interfered with some hack ;-) I am wondering whether anyone mistakenly thinks that there is a dynamic binding process involved at the time of the attribute access for the instancemethod, as there is for an ordinary method. Of course I know you know how to mess with the class to make function attributes of instances get dynamically bound as if they were class attributes accessed via the instance, but I wonder if others appreciate this distinction, or would be surprised by e.g., >>> import new >>> >>> class bob(object): ... def __init__(self, **kwargs): ... for fname, func in kwargs.items(): ... setattr(self, fname, new.instancemethod(func, self, bob)) ... >>> def m(self, *args): ... return self, args ... >>> b = bob(bm=m) >>> vars(b) {'bm': >} >>> b.bm('hi') (<__main__.bob object at 0x02EF16EC>, ('hi',)) >>> bmg = b.bm >>> bmg('hello') (<__main__.bob object at 0x02EF16EC>, ('hello',)) >>> class C: pass ... >>> c=C() >>> c.m = b.bm >>> c.m('greets') (<__main__.bob object at 0x02EF16EC>, ('greets',)) >>> C.M = b.bm >>> C.M('saludos') (<__main__.bob object at 0x02EF16EC>, ('saludos',)) >>> c.M('amigos') (<__main__.bob object at 0x02EF16EC>, ('amigos',)) Obviously "self" has nothing to do with c or C etc. Regards, Bengt Richter From aahz at pythoncraft.com Mon May 16 01:18:25 2005 From: aahz at pythoncraft.com (Aahz) Date: Sun, 15 May 2005 22:18:25 -0700 Subject: BayPIGgies: May 19, 7:30pm (FIRST meeting at Google) Message-ID: <20050516051825.GA4426@panix.com> NOTE: we are no longer meeting at Stanford; the May meeting is at Google in Mountain View. The next meeting of BayPIGgies will be Thurs, May 19 at 7:30pm. NOTE: to celebrate our first meeting at Google, Google will be providing a buffet dinner starting at 6:45pm. Alex Martelli will be repeating his OSCON/PyCon presentations about OOP and design patterns -- with improvements! BayPIGgies meetings alternate between IronPort (San Bruno, California) and Google (Mountain View, California). For more information and directions, see http://www.baypiggies.net/ Advance notice: The June 9 meeting agenda has been set. Drew Perttula will be talking about his Python-based lighting system controller. Advance notice: The July 14 meeting agenda has not been set. Please send e-mail to baypiggies at baypiggies.net if you want to suggest an agenda (or volunteer to give a presentation). -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "And if that makes me an elitist...I couldn't be happier." --JMS From holbertr at dma.org Wed May 11 09:14:38 2005 From: holbertr at dma.org (Rick Holbert) Date: Wed, 11 May 2005 09:14:38 -0400 Subject: Put a file on an ftp server over ssl References: <1115749959.870607.20720@o13g2000cwo.googlegroups.com> <1115755428.196173.213360@f14g2000cwb.googlegroups.com> <1115805483.903002.109830@g14g2000cwa.googlegroups.com> Message-ID: Have a look at Putty's pscp and PySCP... http://www.chiark.greenend.org.uk/~sgtatham/putty/ http://py.vaults.ca/apyllo.py/990075885.195097684.69935243 Rick Lars wrote: > Daniel, > > Why don't you just use the 'sftp' command line program, it's available > for all unixes and I bet you can find a build for windows to? Then you > could just do an os.system(..) and be done with it. > > Cheers! > Lars From gnb at itga.com.au Tue May 17 22:46:54 2005 From: gnb at itga.com.au (Gregory Bond) Date: Wed, 18 May 2005 12:46:54 +1000 Subject: processing a Very Large file In-Reply-To: <118k530sl6kve5c@corp.supernews.com> References: <118k530sl6kve5c@corp.supernews.com> Message-ID: DJTB wrote: > Hi, > > I'm trying to manually parse a dataset stored in a file. The data should be > converted into Python objects. In addition to what the others have mentioned, this sort of problem is pretty easy to do with a C coded extension type, if you have (or can buy/borrow) any C skills. The result is waaaay more efficient in time and memory, particularly if you actually don't wind up looking at most elements. But Robert's solution (use iterators/generators rather than store them all in a list) is probably best/quickest if that is possible for your app. From mefjr75 at hotmail.com Sat May 14 19:11:16 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 14 May 2005 16:11:16 -0700 Subject: A new to Python question In-Reply-To: References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> <1116107944.677219.17980@o13g2000cwo.googlegroups.com> Message-ID: <1116112276.699739.6160@o13g2000cwo.googlegroups.com> Ok I give up you have convinced me. Of what I am not sure ;) Anyway I have always viewed : a,b,c= (1,2,3) as unpacking a tuple and : (a,b,c) = (1,2,3) as creation of a tuple It was a false assumption, I have used Python for years and have never written an unpacking as: (a,b,c) = (1,2,3) I have always put parens around my tuples I always thought that a tuple was a parens with at least one comma ;) It is just not something I have done, it seems counter to my thinking , till I read from Bengt it is the commas that make the tuple not the parens. It all makes sense now, but if they are not needed I think they that should be avoided for clarity. Steve thanks for your time. I always learn a little from you ;) M.E.Farmer From sam_spam_cat at comcast.net Sun May 29 18:44:16 2005 From: sam_spam_cat at comcast.net (Sam the Cat) Date: Sun, 29 May 2005 18:44:16 -0400 Subject: network ping Message-ID: <4LednU5KFIZc2AffRVn-3Q@comcast.com> Besides calling the external ping utility -- is there a way native to python to execute a similar utility ? From usenet at datahansa.com Mon May 23 16:57:52 2005 From: usenet at datahansa.com (Oleg Paraschenko) Date: 23 May 2005 13:57:52 -0700 Subject: Comparing 2 similar strings? References: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> Message-ID: Hello William, William Park wrote in message news:<24a6d$428b9c10$d1b717f8$2300 at PRIMUS.CA>... > How do you compare 2 strings, and determine how much they are "close" to > each other? > ... If your strings are between 1 and 16 Kb, look at GetReuse SDK: http://getreuse.com/sdk/ It has Perl and Python bindings. You might be interested in the latter as you posted to comp.lang.python. I can't disclosure the algorithm. Here is an excerpt from the home page: The formula for the calculation of the similarity is based on the scientific research. Any other "good" method of calculations should produce results that are equivalent in some terms to the GetReuse results. -- olpa@ http://datahansa.com/ XML publishing and documentation management http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme From claird at lairds.us Wed May 25 16:08:05 2005 From: claird at lairds.us (Cameron Laird) Date: Wed, 25 May 2005 20:08:05 GMT Subject: Has ComboBox ctrl in Tkinter? References: Message-ID: In article , Fredrik Lundh wrote: >"????????" wrote: > >>i have not find the ComboBox in Tkinter,has it? where to get the doc about >> how to use combobox ctrl? > >the Tix add-on contains a combobox: > > http://docs.python.org/lib/node727.html > >see > > http://docs.python.org/lib/node725.html > >for some information on how to check for a working Tix install. > >if you cannot get Tix to work (or don't want to use it), there's a combobox in >the bwidgets package as well: > > http://tkinter.unpythonic.net/bwidget/ > > > > > There are also several pure-Tk implementations , including Bryan Oakley's popular one, all of which can be used directly from Tkinter. From flupke at nonexistingdomain.com Mon May 23 05:30:31 2005 From: flupke at nonexistingdomain.com (flupke) Date: Mon, 23 May 2005 09:30:31 GMT Subject: firebird and unicode In-Reply-To: <5w9ke.98690$Ir4.5630011@phobos.telenet-ops.be> References: <2u5ke.98532$384.5621810@phobos.telenet-ops.be> <5w9ke.98690$Ir4.5630011@phobos.telenet-ops.be> Message-ID: flupke wrote: I solved it by getting the latest py files from CVS and overwriting the existing ones. It gave an Attribute error but that was gone after commenting this line: #isc_info_isc_version = _k.isc_info_isc_version I'm not sure if this is a safe way of working. It's like jumping over a fence with barb wire. You know your balls might be in danger but sometimes you got to take a risk :) I hope i don't end up singing with a funny voice ;) Thanks, Benedict Verheyen From ggg at zzz.it Fri May 20 03:53:43 2005 From: ggg at zzz.it (deelan) Date: Fri, 20 May 2005 09:53:43 +0200 Subject: MySQLdb and Unicode In-Reply-To: References: Message-ID: <0uh0m2-i76.ln1@news.interplanet.it> Achim Domma (Procoders) wrote: > Hi, > > I try to write unicode strings to a MySQL database via MySQLdb. > According to the documentation I should pass 'utf-8' as keyword > parameter to the connect method. But then I get the following error: > (...) > > > I'm using version 1.2 of MySQLdb. Any hint what I'm doing wrong? this is changed in 1.2, from the Connection class docstring: "use_unicode" ''If True, text-like columns are returned as unicode objects using the connection's character set. Otherwise, text-like columns are returned as strings. columns are returned as normal strings. Unicode objects will always be encoded to the connection's character set regardless of this setting.'' -- @prefix foaf: . <#me> a foaf:Person ; foaf:nick "deelan" ; foaf:weblog . From rkern at ucsd.edu Tue May 10 07:57:56 2005 From: rkern at ucsd.edu (Robert Kern) Date: Tue, 10 May 2005 04:57:56 -0700 Subject: why this happend using model random? In-Reply-To: References: Message-ID: flyaflya wrote: > Robert Kern wrote: > >>flyaflya wrote: >> >> >>>from random import * >>> >>>col = [0 for i in range(10)] >>>a = [col for i in range(10)] >> >> >>This is the problem. The list "a" now has ten references to the same >>object "col". They are not copied. >> >> >>>seed() >>>for i in range(10): >>> for j in range(10): >>> a[i][j] = randint(0, 100) >> >> >>So every time you index into "a[i][j]" you are always getting "col[j]". >> > > thanks,I see,I know about reference and copy,but when is it a copy?when > a reference?how can I get a copy when need? Usually, references get passed around wherever possible. Just putting "col" into the list comprehension like you did will never copy. If you need a copy of a list, you could do "col[:]" or "list(col)". More generally, see the "copy" module. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From Michael.Coll-Barth at VerizonWireless.com Thu May 12 09:52:32 2005 From: Michael.Coll-Barth at VerizonWireless.com (Michael.Coll-Barth at VerizonWireless.com) Date: Thu, 12 May 2005 09:52:32 -0400 Subject: Launch file in Notepad Message-ID: <20050512135235.06FA91E400A@bag.python.org> try b1="c:/test.txt" It seems to work for me on Windows 2000. -----Original Message----- From: python-list-bounces+michael.coll-barth=verizonwireless.com at python.org [mailto:python-list-bounces+michael.coll-barth=verizonwireless.com at pytho n.org]On Behalf Of George Sent: Thursday, May 12, 2005 9:41 AM To: python-list at python.org Subject: Launch file in Notepad Newbie question: I'm trying to lauch Notepad from Python to open a textfile: import os b1="c:\test.txt" os.system('notepad.exe ' + b1) However, the t of test is escaped by the \, resulting in Notepad trying to open "c: est.txt". How do I solve this? (By the way, b1 comes from a command line parameter, so the user enters c:\test.txt as command line parameter.) George -- http://mail.python.org/mailman/listinfo/python-list ___________________________________________________________________ The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. From theller at python.net Tue May 24 11:22:16 2005 From: theller at python.net (Thomas Heller) Date: Tue, 24 May 2005 17:22:16 +0200 Subject: Running in Release or Debug version of the python interpreter? In-Reply-To: References: Message-ID: <429346A8.2080102@python.net> Raphael Zulliger schrieb: > Hi > > I have to check wheter a .py script is run within the debug or the > release version of an embedded python interpreter (in short, wheter > python24_d.dll or python24.dll is in use). > > long version: I'm using ctypes to load my own dll. There exists 2 > version of this dll - a debug and a release version (where one is linked > against debug C runtime dll and the other to release C runtime dll). Now > I have to change the name of the dll I want to be loaded by ctypes... > But how can I find out which of the dll I have to load?! > > Thanks in advance! > Raphael Zulliger You could use imp.get_suffixes(). In a release build the returned list will contain these entries ('.pyd', 'rb', 3), ('.dll', 'rb', 3) in a debug build that will be ('_d.pyd', 'rb', 3), ('_d.dll', 'rb', 3) Another way would be to look at the filename of any binary extension module. _ctypes.__file__, for example: '.....\\_ctypes.pyd' vs. '....\\_ctypes_d.pyd'. Thomas From mackstevenson at hotmail.com Sun May 15 02:05:25 2005 From: mackstevenson at hotmail.com (MackS) Date: 14 May 2005 23:05:25 -0700 Subject: converting a set into a sorted list In-Reply-To: <1116120701.520116.315230@f14g2000cwb.googlegroups.com> References: <1116120701.520116.315230@f14g2000cwb.googlegroups.com> Message-ID: <1116137125.474289.249210@z14g2000cwz.googlegroups.com> Thank you for the pointer. I'll upgrade to 2.4. Best, Mack From nnorwitz at gmail.com Sat May 21 22:23:35 2005 From: nnorwitz at gmail.com (Neal Norwitz) Date: 21 May 2005 19:23:35 -0700 Subject: porting help In-Reply-To: <1116579660.125778.140060@z14g2000cwz.googlegroups.com> References: <1116579660.125778.140060@z14g2000cwz.googlegroups.com> Message-ID: <1116728615.438357.117260@o13g2000cwo.googlegroups.com> You may need to write your own dynload_vxworks.c. Notice there are various OS specific dynload_*.c files. You can try to use dynload_stub.c to see if you can get it to compile. You may also need to muck with Include/pyport.h and configure to get things going. Good Luck! n From tiissa at nonfree.fr Sun May 29 04:08:17 2005 From: tiissa at nonfree.fr (tiissa) Date: Sun, 29 May 2005 10:08:17 +0200 Subject: need help of RE In-Reply-To: <1117353427.242568.47010@g43g2000cwa.googlegroups.com> References: <1117352350.179209.206930@z14g2000cwz.googlegroups.com> <1117353427.242568.47010@g43g2000cwa.googlegroups.com> Message-ID: <42997871$0$27689$636a15ce@news.free.fr> cheng wrote: > im sorry, my engilsh is not vell well, That's alright, you could have been french. ;) > the string not only contain '&' and '|' and it can be anyting > > i just want to split out the "whole word" inside the string Look at the example for split function of re module in the doc [1]. In short: >>> import re >>> s="(word1 & (Word2|woRd3))" >>> re.split("\W+",s) ['', 'word1', 'Word2', 'woRd3', ''] >>> [w.lower() for w in re.split("\W+",s) if w != ''] ['word1', 'word2', 'word3'] >>> [1]http://python.org/doc/lib/node114.html From jabel at plus.net Fri May 27 04:07:44 2005 From: jabel at plus.net (John Abel) Date: Fri, 27 May 2005 09:07:44 +0100 Subject: Running a python program during idle time only In-Reply-To: <4296D2E3.8060605@hathawaymix.org> References: <1116637560.499307.28700@o13g2000cwo.googlegroups.com> <1116869538.611233.264960@g14g2000cwa.googlegroups.com> <5j64x9gz09.fsf@idiom.com> <4296D2E3.8060605@hathawaymix.org> Message-ID: <4296D550.7090304@plus.net> Shane Hathaway wrote: >Mike Meyer wrote: > > >>On a completely different topic, this looks like the wrong way to solve >>the problem. You want to update a search engine based on changes to the >>underlying file system. The right way to do this isn't to just keep >>rescanning the file system, it's to arrange things so that your scanner >>gets notified of any changes made to the file system. I did something like >>this for my web site search engine, but that's hooked into the SCM that's >>used for propogating changes to the web site. I know someone is working >>on patches to the FreeBSD kernel to make this kind of thing work. It would >>seem that some of the "backup" facilities that worked by keeping a mirror >>of the disk on separate media would have to have used such hooks, but maybe >>not. >> >> > >I think you're right that filesystem change notification is what Carlos >needs. > >If you're interested in using Linux, Carlos, "inotify" is a new kernel >module that can notify your program of filesystem changes. It's not >folded into the mainline kernel yet, but it's a clean patch. > >http://www.edoceo.com/creo/inotify/ > >I don't know if Windows has anything like it. I'd be interested to hear >if it does. > >Shane > > Using the PyWin32 extensions, you can register an event with the kernel, and then have the script sleep. If I can remember how, I'll post some code. It's been a while since I coded specific Win32 stuff. J From fphsml at gmail.com Sat May 7 01:28:59 2005 From: fphsml at gmail.com (James) Date: 6 May 2005 22:28:59 -0700 Subject: Found python for delphi new web site In-Reply-To: References: Message-ID: <1115443739.747455.200590@f14g2000cwb.googlegroups.com> It has been around for a while now. But I am glad I visited it again. The new PyScripter IDE is great. They should really announce new software like these here. From exarkun at divmod.com Sun May 1 16:25:54 2005 From: exarkun at divmod.com (Jp Calderone) Date: Sun, 01 May 2005 20:25:54 GMT Subject: BitKeeper for Python? In-Reply-To: Message-ID: <20050501202554.15422.229561071.divmod.quotient.12330@ohm> On Sun, 01 May 2005 20:16:40 GMT, John Smith wrote: >I am going to be working with some people on a project that is going to be >done over the internet. I am looking for a good method of keeping everyone's >code up to date and have everyone be able to access all the code including >all the changes and be able to determine what parts of the code were >changed. > >If it were opensource that would be even better. > Have you checked out this page? http://www.google.com/search?hl=en&lr=&q=version+control+system&btnG=Search Jp From prashanthellina at gmail.com Fri May 27 06:01:05 2005 From: prashanthellina at gmail.com (Prashanth Ellina) Date: 27 May 2005 03:01:05 -0700 Subject: Xml writing in Python and verifying using XSD Message-ID: <1117188065.742367.219360@o13g2000cwo.googlegroups.com> Hi, I need to write some data to an xml file. I have an XML Schema defined. I would like to use some mechanism of writing the data to the xml file and having exceptions thrown back to me when the data is invalid. I have looked at xml.dom and xml.dom.minidom but could not figure out what to do to include xml validation using the xsd while writing. Any ideas? Thanks in advance, Prashanth Ellina From sjmachin at lexicon.net Tue May 31 20:37:28 2005 From: sjmachin at lexicon.net (John Machin) Date: Wed, 01 Jun 2005 10:37:28 +1000 Subject: Swig compile errors In-Reply-To: <1117583720.968040.230380@g47g2000cwa.googlegroups.com> References: <1117583720.968040.230380@g47g2000cwa.googlegroups.com> Message-ID: <429d0347$1@news.eftel.com> superprad at gmail.com wrote: > Hi I am trying to write a python wrapper for a C code I have using > swig. when i try to compile the _wrap.c i get a bunch of these warnings > and errors can anyone help > Steps I followed : > > $swig -python test_hk.c > this generates test_hk.py and test_hk_wrap.c > then i compile it as > > $gcc -Wall -std=c99 test_hk.c test_hk_wrap.c -I/usr/include/python2.3/ Worth a try: gcc -Wall -std=c99 -I/usr/include/python2.3/ test_hk.c test_hk_wrap.c From k04jg02 at kzoo.edu Sun May 15 15:35:32 2005 From: k04jg02 at kzoo.edu (Joseph Garvin) Date: Sun, 15 May 2005 19:35:32 +0000 Subject: Safe eval, or how to get list from string In-Reply-To: <1116007844.564530.178880@g43g2000cwa.googlegroups.com> References: <1115999726.286709.140690@f14g2000cwb.googlegroups.com> <1116007844.564530.178880@g43g2000cwa.googlegroups.com> Message-ID: <4287A484.80300@kzoo.edu> bwooster47 at gmail.com wrote: >>http://twistedmatrix.com/users/moshez/unrepr.py >>http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 >> >> > >Thanks, this helps - but I was looking at using no additional modules, >or using something that came bundled in with python 2.3 > >I just discovered mx.Tools.NewBuiltins > >It has something called "reval" looks that would fit my needs >perfectly. > >Details: >http://www.faqts.com/knowledge_base/view.phtml/aid/4550/fid/538 > > > If I remember correctly reval and it's brothers were deemed insecure, are no longer developed, and are present only for sake of backwards compatibility. See the global module index entry on it. From joram.gemma at pandora.be Sun May 15 09:24:25 2005 From: joram.gemma at pandora.be (joram gemma) Date: Sun, 15 May 2005 15:24:25 +0200 Subject: string.lstrip stripping too much? Message-ID: <000401c55951$6a4b25e0$0505a8c0@cheopsturbo> Hello, on windows python 2.4.1 I have the following problem >>> s = 'D:\\music\\D\\Daniel Lanois\\For the beauty of Wynona' >>> print s D:\music\D\Daniel Lanois\For the beauty of Wynona >>> t = 'D:\\music\\D\\' >>> print t D:\music\D\ >>> s.lstrip(t) 'aniel Lanois\\For the beauty of Wynona' >>> why does lstrip strip the D of Daniel Lanois also? thanks in advance joram From belred at gmail.com Mon May 2 22:25:57 2005 From: belred at gmail.com (Bryan) Date: Mon, 02 May 2005 19:25:57 -0700 Subject: Which IDE is recommended? In-Reply-To: <1115039282.069052.287920@o13g2000cwo.googlegroups.com> References: <426f90ac$1_2@rain.i-cable.com> <9f7v619jhigbtoksslnr88f4idoc6ejvu3@4ax.com> <1115039282.069052.287920@o13g2000cwo.googlegroups.com> Message-ID: dcrespo wrote: >>But I personally recommend DrPython. (Not only, I'm a member of the >>project). > > > I saw this message and downloaded DrPython. It's very good: I like the > class/functions browser while I'm coding... but I can't find the > autocompletion feature you talk, and I think this feature is very > important. Where it is? > > Daniel > i saw this message too and i've been using it for the last couple days, but i don't see the class/functions browser you are talking about. where is it??? thanks, bryan From qwweeeit at yahoo.it Thu May 26 09:31:40 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 26 May 2005 06:31:40 -0700 Subject: File list from listdir or shell? Message-ID: <1117114300.592398.92440@f14g2000cwb.googlegroups.com> Hi all, to obtain a file list from a dir you can use: import os, sys try: . sExtension=sys.argv[1] . sPath=sys.argv[2] except: . sExtension="" . sPath='.' lF=os.listdir(sPath) # to remove from the list also the names of backup files lF=filter(lambda lF: '~' not in lF and sExtension in lF,lF) Running this small script you obtain the file list (based on a given extension) from a dir (sPath). My question is: is there another better way? or can we use the sys.stdin to capture the stdout of a shell command? Examples of single line shell commands could be: ls -1 *.py (for the filenames only) or find ~/ -name '*.py' (to get path+filename of all my root dir) Unluckily, to capture the stdout I have to redirect it to a file... I hoped that this could work ... lF=sys.stdin.readline(os.system("ls -1 *.py")) Bye. From swaroopch at gmail.com Tue May 3 06:00:52 2005 From: swaroopch at gmail.com (Swaroop C H) Date: Tue, 3 May 2005 15:30:52 +0530 Subject: python+windows/linux -> write stdout text to always on top text? In-Reply-To: <1115064842.454916.305970@f14g2000cwb.googlegroups.com> References: <1115064842.454916.305970@f14g2000cwb.googlegroups.com> Message-ID: <351e88710505030300495a0169@mail.gmail.com> On 2 May 2005 13:14:02 -0700, flamesrock wrote: > I'm curious if theres a way in python to write stdout text to the > screen (ie top right) the way they do in some FPS games, so that its > always on top, in an invisible window of some set dimensions. No matter > what program is on top. Why would you want to do that ? -- Swaroop C H Blog: http://www.swaroopch.info Book: http://www.byteofpython.info From jerf at jerf.org Thu May 5 16:32:38 2005 From: jerf at jerf.org (Jeremy Bowers) Date: Thu, 05 May 2005 16:32:38 -0400 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: On Thu, 05 May 2005 18:42:17 +0000, Charles Krug wrote: > On 5 May 2005 10:37:00 -0700, mrstephengross > wrote: >> Hi all... How can I find out the number of significant digits (to the >> right of the decimal place, that is) in a double? At least, I *think* >> that's what I'm asking for. For instance: >> >> 0.103 --> 3 >> 0.0103 --> 4 >> 0.00103 --> 5 >> 0.000103 --> 6 >> 0.0000103 --> 7 >> >> Thanks in advance! >> --Steve (mrstephengross at hotmail.com) >> >> > I would say that each of these examples has three signficant figures. Each > of them can be expressed as: > > 1.03e+n > > For any integer n. You beat me to it. Step one for mrstephengross is to *rigorously* define what he means by "significant digits", then go from there. Since I think he mentioned something about predicting how much space it will take to print out, my suggestion is to run through whatever printing routines there are and get a string out, the measure the string, as anything else will likely be wrong. If that's not possible with the formatting library, you've already lost; you'll have to completely correctly re-implement the formatting library, and not only is that a major PITA, you almost never get it bug-for-bug right... From skip at pobox.com Wed May 11 16:18:45 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 May 2005 15:18:45 -0500 Subject: Python Documentation (should be better?) In-Reply-To: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> Message-ID: <17026.26789.592527.975821@montanaro.dyndns.org> Jue> Maybe a mailing list or forum people can contribute example and Jue> notes? Contributions can be made at the SourceForge patch tracker: http://sourceforge.net/tracker/?group_id=5470&atid=305470 Plain text is fine. Skip From python at rcn.com Tue May 31 10:55:52 2005 From: python at rcn.com (Raymond Hettinger) Date: 31 May 2005 07:55:52 -0700 Subject: change vars in place w/loop or list comprehension References: <1117547939.650578.316090@g47g2000cwa.googlegroups.com> Message-ID: <1117551352.595284.162580@g43g2000cwa.googlegroups.com> > >>> a = 'one' > >>> b = 'two' > >>> c = 'three' > >>> [a, b, c] = [s.upper() for s in [a, b, c]] > >>> a > 'ONE' > > Both of these accomplish what I'm after; I prefer the second for its > brevity. But either approach requires that I spell out my list of > vars-to-alter [a, b, c] twice. This strikes me as awkward, and > would be difficult > with longer lists. seq = a, b, c a, b, c = seq = [s.upper() for s in seq] From skip at pobox.com Wed May 11 10:48:21 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 May 2005 09:48:21 -0500 Subject: pylab: plot update In-Reply-To: References: Message-ID: <17026.6965.301229.370123@montanaro.dyndns.org> Jan> After that i call sleep(5) until I can acuire the next tuple. Jan> But during that I can't use the zoom/pan, save etc in the window. ... Jan> Is there any better way to do this easily? Set a timeout. How to do that depends on what gui tools you are using. I've never used pylab so I don't know how it integrates with the rest of your app. If you're using PyGTK, something like this should suffice: gobject.timeout_add(5000, update_plot) where the update_plot function executes your acquisition/plot code. It needs to return True if you want it to be triggered every five seconds, otherwise it's a one-shot. Skip From jeffelkins at earthlink.net Wed May 11 14:54:40 2005 From: jeffelkins at earthlink.net (jeff elkins) Date: Wed, 11 May 2005 18:54:40 +0000 Subject: Finding startup files In-Reply-To: References: <200505111807.16833.jeffelkins@earthlink.net> Message-ID: <200505111854.41401.jeffelkins@earthlink.net> On Wednesday 11 May 2005 10:18 pm, Robert Kern wrote: > jeff elkins wrote: > > On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote: > >>On 2005-05-11, hemagician at gmail.com wrote: > >>>The following script demonstrates a method that should work for you. I > >>>believe it is entirely cross-platform. > >>> > >>>#! /usr/bin/python > >>> > >>>import sys > >>>import os > >>> > >>>print os.path.abspath(os.path.dirname(sys.argv[0])) > >> > >>That will probably work most of the time, but... > >> > >> 1) you're not gauranteed that argv[0] contains the application > >> path/filename. > >> > >> 2) the directory containing the executable is not where > >> configuration files are supposed to be stored under > >> Unix/Linux. > > > > Thanks Grant, > > > > I live and develop in Linux, but unfortunately, 99.99% of the users of > > this particular application (analysis of medical laboratory data) will be > > working with Windows. > > > > I'm totally new to Python (obvious,yes?) so how might argv[0] fail? > > If I make a symbolic link to the executable script and run it using that > link, sys.argv[0] will give the filename of that link, not the real file > it points to. Thanks. I just tested that and it does indeed fail. Jeff From eurleif at ecritters.biz Sun May 15 15:31:20 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sun, 15 May 2005 19:31:20 GMT Subject: Is isinstance always "considered harmful"? In-Reply-To: <1116157672.683839.49700@o13g2000cwo.googlegroups.com> References: <1116157672.683839.49700@o13g2000cwo.googlegroups.com> Message-ID: Jordan Rastrick wrote: > Say you're writing, in Python, the extend() method for a Linked List > version of python's builtin list. Its really important to know what > kind of iterable youre being passed in - because if its another > Linked list, and you know it, you can connect the two in 0(1) time; > whereas any other arbitrary iterable is going to take 0(n), as you're > just going to have to append the items one by one. Is this a case > where use of isinstance, to see exactly what kind of Iterable you > have, can be justified? > > def extend(self, elems): > if isinstance(elems, LinkedList): > # Point last to first > else: > for elem in elems: self.append(elem) Regardless of the various issues surrounding isinstance(), you have a difference in functionality. Since you're just storing a reference in the case of another LinkedList instead of copying it, mutating the LinkedList will be different from mutating another iterable type which has been passed to extend: >>> linkedlist1 = LinkedList() >>> list1 = [1, 2, 3] >>> linkedlist2 = LinkedList([4, 5, 6]) >>> linkedlist1.extend(list1) >>> linkedlist1.extend(linkedlist2) >>> linkedlist1 LinkedList([1, 2, 3, 4, 5, 6]) >>> list1.append(4) >>> linkedlist1 # Notice how there's still only one 4 LinkedList([1, 2, 3, 4, 5, 6]) >>> linkedlist2.append(7) >>> linkedlist1 # Notice how there's now a 7 LinkedList([1, 2, 3, 4, 5, 6, 7]) From cookedm+news at physics.mcmaster.ca Sun May 1 17:22:06 2005 From: cookedm+news at physics.mcmaster.ca (David M. Cooke) Date: Sun, 01 May 2005 17:22:06 -0400 Subject: editor for shelve files References: <1114942869.144312.253720@o13g2000cwo.googlegroups.com> Message-ID: "Amir Michail" writes: > Hi, > > Is there a program for editing shelve databases? > > Amir I doubt it. A shelf is basically just a file-based dictionary, where the keys must be strings, while the values can be arbitrary objects. An editor could handle the keys, but most likely not the values. If you have an editor for arbitrary objects, you could probably make an editor for shelfs easily enough :-) Do you have a specific use in mind? That would be easier to handle than the general case. -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke |cookedm(at)physics(dot)mcmaster(dot)ca From dwelch at vcd.hp.com Mon May 2 16:53:49 2005 From: dwelch at vcd.hp.com (djw) Date: Mon, 02 May 2005 13:53:49 -0700 Subject: Comparision of GUI framworks In-Reply-To: References: Message-ID: Florian Lindner wrote: > Hello, > I've read the chapter in the Python documentation, but I'm interested in a a > more in-depth comparision. Especially regarding how pythonic it is and how > well it performs and looks under Windows. > I've some C++ experiences with Qt, so I'm very interested to have PyQt > compared to wxWindows and Tk. How fast does PyQt catches up with the > versiones released from Trolltech? etc.. > > Thx, > Florian I would ask this question on the pyqt/pykde mailing list... but, for what's its worth, I've been using PyQt (on Linux) for > 4 years, and am very happy with it. I find it very "Pythonic". When I first started looking at UI toolkits, the decision came down to wx vs. Qt. I found wx a bit more complex and cryptic and less OO than Qt. Also, I find Qt Designer + Eric to be a nicer development environment than Boa Constructor. The main problem with Qt is apparently licensing issues on Windows... I can't comment since I only use PyQt/Qt on Linux. -Don From mrmaple at gmail.com Wed May 25 15:17:13 2005 From: mrmaple at gmail.com (James Carroll) Date: Wed, 25 May 2005 15:17:13 -0400 Subject: Where do I find the dispatch name? In-Reply-To: References: Message-ID: I looked through all the IIDs in: PythonWin, Tools, COM Object Browser, RegisteredCategories, Automation Objects. After looking through all the IIDs I saw one that looked like it might work... and it did. -Jim On 5/25/05, James Carroll wrote: > I just ran makepy to create a wrapper for my com object, and it > generated the wrapper with the CLSID.py under > site-packages/win32com/gen_py/ > > Now, I'm trying to figure out how to invoke it. How do I figure out > what string to give Dispatch? > > For instance: > xl = win32com.client.Dispatch("Excel.Application") > > If I understand right would give me an instance of the wrapper.... > Do I give it the entire classID? > > -Jim > From bogus@does.not.exist.com Thu May 19 09:45:02 2005 From: bogus@does.not.exist.com () Date: Thu, 19 May 2005 13:45:02 -0000 Subject: No subject Message-ID: #! rnews 2056 Newsgroups: comp.lang.python Path: news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!border2.nntp.ams.giganews.com!nntp.giganews.com!fi.sn.net!newsfeed2.fi.sn.net!newsfeed3.funet.fi!newsfeed1.funet.fi!newsfeeds.funet.fi!newsfeed1.swip.net!swipnet!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp From: Harry George Subject: Re: ElementTree and xsi to xmlns conversion? X-Nntp-Posting-Host: cola2.ca.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Lines: 43 Sender: hgg9140 at cola2.ca.boeing.com Organization: The Boeing Company References: Mime-Version: 1.0 Date: Thu, 19 May 2005 13:24:58 GMT Xref: news.xs4all.nl comp.lang.python:378110 "Fredrik Lundh" writes: [snip] > > are you sure? the prefix shouldn't matter; it's the namespace URI that's important. > if you're writing code that depends on the namespace prefix rather than the name- > space URI, you're not using namespaces correctly. when it comes to namespaces, > elementtree forces you to do things the right way: > > http://www.jclark.com/xml/xmlns.htm > > (unfortunately, the XML schema authors didn't understand namespaces so they > messed things up: > http://www.w3.org/2001/tag/doc/qnameids-2002-04-30 > to work around this, see oren's message about how to control the namespace/prefix > mapping. in worst case, you can manually insert xsi:-attributes in the tree, and rely on > the fact that the default writer only modifies universal names) > > > > > First, thanks for ElementTree and cElementTree. Second, I've read the docs and see a lot of examples for building trees, but not a lot for traversing parsed trees. Questions: 1. Is there a good idiom for namespaces? I'm currently doing things like: UML='{href://org.omg/UML/1.3}' .... packages=ns2.findall(UML+'Package') 2. Is there a similar idiom which works for Paths? I've tried: packages=pkg1.findall(UML+'Namespace.ownedElement/'+UML+'Package') but haven't found the right combination, so I do step-at-a-time descent. -- harry.g.george at boeing.com 6-6M21 BCA CompArch Design Engineering Phone: (425) 294-4718 From tjreedy at udel.edu Mon May 30 14:24:54 2005 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 30 May 2005 14:24:54 -0400 Subject: Case Sensitive, Multiline Comments References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> Message-ID: "D H" wrote in message news:z5adnQMsOLiL7AffRVn-hQ at comcast.com... > Elliot Temple wrote: >> Hi I have two questions. Could someone explain to me why Python is >> case sensitive? I find that annoying. > > I do too. I don't. > As you've found, the only reason is because it is, False. As someone else already pointed out in this thread, and as some said years ago when Guido brought up the subject, standard math notation *is* case sensitive and some people like Python because they can directly translate math expressions into Python expressions. I am annoyed by the disinformation and slander ('anti-newbie') repeated indefinitely by some case-folding advocates. Difference annoyances for different folks, I guess. Terry J. Reedy From philippe at philippecmartin.com Tue May 3 21:46:04 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Wed, 04 May 2005 01:46:04 GMT Subject: OOP References: <1114709684.096071.109960@l41g2000cwc.googlegroups.com> Message-ID: Try this: http://pigseye.kennesaw.edu/~dbraun/csis4650/A&D/UML_tutorial/ demon_slayer2839 at yahoo.com wrote: > Hey yall, > I'm new to Python and I love it. Now I can get most of the topics > covered with the Python tutorials I've read but the one thats just > stumping me is Object Orientation. I can't get the grasp of it. Does > anyone know of a good resource that could possibly put things in focus > for me? Thanks. From grante at visi.com Tue May 17 11:40:04 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 17 May 2005 15:40:04 -0000 Subject: Python forum References: Message-ID: <118k42k64ai7316@corp.supernews.com> On 2005-05-17, Jonas Melian wrote: > I'm going to say a suggestion, why don't you create a forum > like the one of Ruby (http://www.rubyforums.com/)? for the > novices this is a great help, better than a mail list Says you. I prever a newsgroup. Mailing lists are in second place and web forums a very distant third. I really don't see how pointing Mozilla or Thunderbird at a newsgroup isn't any harder than pointing it at a web forum. > I know that you have python-list, it's both an email and a usenet list. And both are far better than web forums. > But I think that a forum is great for the learning. The test > is in gentoo's forums. They are a lot of experienced people > answering questions without any problem and it goes very well Except for the torture of using a web forum's UI. [In case you can't tell, I hate web forums. I've never seen a single one with a suable UI.] -- Grant Edwards grante Yow! .. My vaseline is at RUNNING... visi.com From ken at perfect-image.com Tue May 17 10:54:27 2005 From: ken at perfect-image.com (Ken Godee) Date: Tue, 17 May 2005 07:54:27 -0700 Subject: Python RPM and CentOS In-Reply-To: References: Message-ID: <428A05A3.9060409@perfect-image.com> The reasonable thing would be to use "yum". > Not really a Python question, but I thought some on this list may be > able to answer.... so here goes: > > I have several machines on which I must install CentOS. There are many > updates to CentOS and it's very time consuming to do the updates over > the network. I have a local copy of all of the updated rpms. Would it be > reasonable to do something like this to upgrade them locally and more > quickly than over the network??? > > updated_rpms = [list of updated rpms] > > for f in updated_rpms: > > try: > os.popen("/bin/rpm --nodeps -U %s" %f) > > except Exception, e: > print e > > > Thanks, > > rbt From could.net at gmail.com Wed May 4 21:30:21 2005 From: could.net at gmail.com (could ildg) Date: Thu, 5 May 2005 09:30:21 +0800 Subject: How to write this regular expression? In-Reply-To: References: Message-ID: <311b5ce1050504183047bc4d73@mail.gmail.com> On 5/5/05, Jeremy Bowers wrote: > On Wed, 04 May 2005 20:24:51 +0800, could ildg wrote: > > > Thank you. > > > > I just learned how to use re, so I want to find a way to settle it by > > using re. I know that split it into pieces will do it quickly. > > I'll say this; you have two problems, splitting out the numbers and > verifying their conformance to some validity rule. > > I strongly recommend treating those two problems separately. While I'm not > willing to guarantee that an RE can't be written for something like ("[A > number A]_[A number B]" such that A < B) in the general case, it won't be > anywhere near as clean or as easy to follow if you just write an RE to > extract the numbers, then verify the constraints in conventional Python. > > In that case, if you know in advance that the numbers are guaranteed to be > in that format, I'd just use the regular expression "\d+", and the > "findall" method of the compile expression: > > Python 2.3.5 (#1, Mar 3 2005, 17:32:12) > [GCC 3.4.3 (Gentoo Linux 3.4.3, ssp-3.4.3-0, pie-8.7.6.6)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import re > >>> m = re.compile("\d+") > >>> m.findall("344mmm555m1111") > ['344', '555', '1111'] > >>> > > If you're checking general matching of the parameters you've given, I'd > feel no shame in checking the string against r"^(_\d+){1,3}$" with .match > and then using the above to get the numbers, if you prefer that. (Note > that I believe .match implies the initial ^, but I tend to write it > anyways as a good habit. Explicit better than implicit and all that.) > > (I just tried to capture the three numbers by adding a parentheses set > around the \d+ but it only gives me the first. I've never tried that > before; is there a way to get it to give me all of them? I don't think so, > so two REs may be required after all.) You can capture each number by using group, each group can have a name. > -- > http://mail.python.org/mailman/listinfo/python-list > From majordomo-owner at mutt.org Thu May 26 13:27:12 2005 From: majordomo-owner at mutt.org (majordomo-owner at mutt.org) Date: Thu, 26 May 2005 18:27:12 +0100 Subject: Majordomo results: {Filename?} HELLO Message-ID: <20050526172719.C6E6D1E4002@bag.python.org> An embedded and charset-unspecified text was scrubbed... Name: not available URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: not available URL: From dagurp at gmail.com Tue May 3 11:33:15 2005 From: dagurp at gmail.com (dagurp at gmail.com) Date: 3 May 2005 08:33:15 -0700 Subject: Locale and cookies In-Reply-To: References: <1115037383.913329.143470@l41g2000cwc.googlegroups.com> Message-ID: <1115134395.452558.123460@f14g2000cwb.googlegroups.com> Setting it to "C" worked fine. Thanks! From Moiz.Golawala at ge.com Wed May 25 13:31:49 2005 From: Moiz.Golawala at ge.com (Golawala, Moiz M (GE Infrastructure)) Date: Wed, 25 May 2005 13:31:49 -0400 Subject: Pyro2.3 problem Message-ID: Hi All, I am seeing some interesting behavior with Pyro 2.3. I created a server using Pyro2.2 and a client on a different machine with Python2.2 and communication was just fine (I am not using a Name server). However when I upgraded the client to Pyro2.3 (the server was sill on Pyro2.2) and try and communicate with the server, I get a bunch of exception telling me that there is a problem with the URI etc.. My server code is simple: import MyClass from Pyro.ext import remote_nons remote_nons.provide_server_object(MyClass.MyClass(), 'myhost', 'myhost', 9199) sys.exit(remote_nons.handle_request()) My client code is: from Pyro.ext import remote_nons s = remote_nons.get_server_object('Myhost','Myhost',9199) s.helloWorld() Please can someone tell me why the above code would work when both client and server are running Pyro2.2 but not when server is on Pyro2.2 and client is on Pyro2.3 Any help is greatly appreciated. Thanks, Moiz Golawala GE Infrastructure, Security Software Engineer Enterprise Solutions T 561 912 5972 F 561 994 6572 E moiz.golawala at ge.com www.gesecurity.com 791 Park of Commerce Blvd., Suite 100 Boca Raton, FL, 33487, U.S.A. GE Security, Inc. From simba at simba.eclipse.co.uk Wed May 18 17:35:49 2005 From: simba at simba.eclipse.co.uk (millerch) Date: Wed, 18 May 2005 22:35:49 +0100 Subject: socket programming and port scans In-Reply-To: References: Message-ID: Are you explicitly referencing the port for nmap, or is it a general port scan? The version of nmap I run only checks common ports unless a port range is specified. rbt wrote: > I don't fully understand sockets, I just know enough to be dangerous. > The below is not detected by nmap, but is affected by iptables or ipsec. > Can anyone explain why that is? > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((ip_param, port_param)) > while 1: > s.listen(5) > > I can connect to the socket server and even transmit data so I know it's > there. > > Thanks, > rbt From sjmachin at lexicon.net Mon May 16 21:07:13 2005 From: sjmachin at lexicon.net (John Machin) Date: Tue, 17 May 2005 11:07:13 +1000 Subject: Parsing text into dates? References: <1116277171.492587.38080@g47g2000cwa.googlegroups.com> <1116291091.292107.196730@g49g2000cwa.googlegroups.com> Message-ID: On 16 May 2005 17:51:31 -0700, "George Sakkis" wrote: >#======================================================= > >def parseDateTime(string, USA=False, implyCurrentDate=False, > yearHeuristic=_20thcenturyHeuristic): > '''Tries to parse a string as a valid date and/or time. > > It recognizes most common (and less common) date and time formats. Impressive! > > Examples: [snip] > >>> str(parseDateTime('15.6.2001')) > '2001-06-15' > >>> str(parseDateTime('6.15.2001')) > '2001-06-15' A dangerous heuristic -- 6.12.2001 (meaning 2001-12-06) can be easily typoed into 6.13.2001 or 6.15.2001 on the numeric keypad. From steven.bethard at gmail.com Sun May 29 21:19:40 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Sun, 29 May 2005 19:19:40 -0600 Subject: finding indices in a sequence of parentheses In-Reply-To: <429a382d$0$15392$626a14ce@news.free.fr> References: <429a382d$0$15392$626a14ce@news.free.fr> Message-ID: tiissa wrote: > I'd personnally extract the parenthesis then zip the lists of indices. > In short: > > >>> def indices(mylist): > ... lopen=reduce(list.__add__, [[i]*s.count('(') for i,s in > enumerate(mylist)],[]) > ... lclose=reduce(list.__add__, [[i]*s.count(')') for i,s in > enumerate(mylist)],[]) > ... return zip(lopen,lclose) > ... > >>> indices(lst) > [(2, 2), (4, 7), (6, 7), (8, 9), (8, 10)] > >>> Thanks, that's a good idea. In case anyone else is reading this thread, and had to mentally unwrap the reduce expressions, I believe they could be written as: lopen = [x for i, s in enumerate(lst) for x in [i]*s.count('(')] lclose = [x for i, s in enumerate(lst) for x in [i]*s.count(')')] or maybe: lopen = [i for i, s in enumerate(lst) for _ in xrange(s.count('('))] lclose = [i for i, s in enumerate(lst) for _ in xrange(s.count(')'))] Sorry, I have an irrational fear of reduce. ;) STeVe From grante at visi.com Wed May 11 10:21:07 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 11 May 2005 14:21:07 -0000 Subject: Python Args By Reference References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> <1182j1daaepv6f4@corp.supernews.com> <1115787330.723188.295610@f14g2000cwb.googlegroups.com> Message-ID: <118456jg0jgnqee@corp.supernews.com> On 2005-05-11, Roy Smith wrote: > The most common immutable objects you'll see are strings and tuples, And integers. They're immutable, aren't they? At least the small ones. And floats. -- Grant Edwards grante Yow! .. bleakness.... at desolation.... plastic visi.com forks... From bill.mill at gmail.com Fri May 6 12:04:28 2005 From: bill.mill at gmail.com (Bill Mill) Date: Fri, 6 May 2005 12:04:28 -0400 Subject: Getting number of iteration In-Reply-To: References: Message-ID: <797fe3d405050609045bd2457b@mail.gmail.com> On 5/6/05, Florian Lindner wrote: > Hello, > when I'm iterating through a list with: > > for x in list: > > how can I get the number of the current iteration? Python 2.4 and greater: for n, x in enumerate(lst): print "iteration %d on element %s" % (n, x) Earlier: n = 0 for x in lst: print "iteration %d on element %s" % (n, x) n += 1 And you shouldn't use list as a variable name; list() is a built-in function which you'll clobber if you do. Peace Bill Mill bill.mill at gmail.com From onurb at xiludom.gro Wed May 4 04:24:23 2005 From: onurb at xiludom.gro (bruno modulix) Date: Wed, 04 May 2005 10:24:23 +0200 Subject: Creating Files In-Reply-To: References: Message-ID: <427886b9$0$285$626a14ce@news.free.fr> Dan wrote: > > I know how to open a system file with Python, but is there some way to > create one if it's not there? As in any other language I know : just open it in write mode !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in 'onurb at xiludom.gro'.split('@')])" From phillip.watts at anvilcom.com Thu May 19 11:05:29 2005 From: phillip.watts at anvilcom.com (phil) Date: Thu, 19 May 2005 10:05:29 -0500 Subject: Tkinter special math chars Message-ID: <428CAB39.1070109@anvilcom.com> Using Tkinter to teach high school geometry. Sorta committed to Tkinter at least for now. Would like to use some special chars like limits, infinity, square root, cube root and a buch more. in Text Box and Cancas Is there some package I can integrate with Tkinter to do this. Even better would a 'supplemental' font file. In other words I create my own fonts without disturbing the regular fonts and I have to write the code which tells it when to use the special fonts. I haven't a clue how to do something like that. I know Tkinter will let you change fonts but I would have to control it on a char basis somthing like: 'As the function approaches {INFINITY}' scan and somehow replace. TIA. From kay.schluehr at gmx.net Fri May 20 01:56:06 2005 From: kay.schluehr at gmx.net (Kay Schluehr) Date: 19 May 2005 22:56:06 -0700 Subject: Is Python suitable for a huge, enterprise size app? In-Reply-To: References: <1116430620.004234.187280@f14g2000cwb.googlegroups.com> <1116432325.497438.64580@g49g2000cwa.googlegroups.com> <1116433218.495131.71260@g49g2000cwa.googlegroups.com> <1116443474.565264.176640@g44g2000cwa.googlegroups.com> <7xd5rn93zi.fsf@ruckus.brouhaha.com> Message-ID: <1116568566.776426.6390@g43g2000cwa.googlegroups.com> Dave Brueck wrote: > Overall it's been such a positive experience for us that nobody in the company - > from grunt testers up to the CTO - has any reservations about using Python in > production anymore (even though initially they all did). All of the developers > have previous experience with using Java in production systems, and none > seriously consider it for new projects at all. > > -Dave Think there is still a lack of communicating success on that scale. If I think about serious IT magazines published in Germany ( e.g. "Object Spectrum" ), there are tons of experience reports about all kinds of enterprise systems, that were created and managed in Java/dotNET. There might be a slight progress if you review some of the talks on the next Europython conference: http://www.python-in-business.org/ep2005/alisttrack.chtml?track=692 But this is still internal from the fans of the language to other fans. Ciao, Kay From henkjan at xs4all.nl Sat May 7 03:39:41 2005 From: henkjan at xs4all.nl (Henk-Jan de Jong) Date: Sat, 07 May 2005 09:39:41 +0200 Subject: Encryption with Python? In-Reply-To: <1115324411.952821.150780@o13g2000cwo.googlegroups.com> References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com> Message-ID: <427c707c$0$165$e4fe514c@news.xs4all.nl> Blake T. Garretson wrote: > I want to save some sensitive data (passwords, PIN numbers, etc.) to > disk in a secure manner in one of my programs. What is the > easiest/best way to accomplish strong file encryption in Python? Any > modern block cipher will do: AES, Blowfish, etc. I'm not looking for > public key stuff; I just want to provide a pass-phrase. > > I found a few modules out there, but they seem to be all but abandoned. > Most seem to have died several years ago. The most promising package > is A.M. Kuchling's Python Cryptography Toolkit > (http://www.amk.ca/python/code/crypto.html). > > Is this the defacto Python encryption solution? What does everyone > else use? Any other suggestions? The SSLCrypto package > (http://www.freenet.org.nz/python/SSLCrypto/) may be a good alternative > too, but I am not sure if it is actively maintained. > > Thanks, > Blake > There's a DES implementation at http://home.pacific.net.au/~twhitema/des.html From dieter at handshake.de Sat May 21 14:36:05 2005 From: dieter at handshake.de (Dieter Maurer) Date: 21 May 2005 20:36:05 +0200 Subject: python24.zip References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> Message-ID: "Martin v. L?wis" writes on Fri, 20 May 2005 18:13:56 +0200: > Robin Becker wrote: > > Firstly should python start up with non-existent entries on the path? > > Yes, this is by design. > > > Secondly is this entry be the default for some other kind of python > > installation? > > Yes. People can package everything they want in python24.zip (including > site.py). This can only work if python24.zip is already on the path > (and I believe it will always be sought in the directory where > python24.dll lives). The question was: "should python start up with **non-existent** objects on the path". I think there is no reason why path needs to contain an object which does not exist (at the time the interpreter starts). In your use case, "python24.zip" does exist and therefore may be on the path. When "python24.zip" does not exist, it does not contain anything and especially not "site.py". I recently analysed excessive import times and saw thousands of costly and unneccesary filesystem operations due to: * long "sys.path", especially containing non-existing objects Although non-existent, about 5 filesystem operations are tried on them for any module not yet located. * a severe weakness in Python's import hook treatment When there is an importer "i" for a path "p" and this importer cannot find module "m", then "p" is treated as a directory and 5 file system operations are tried to locate "p/m". Of course, all of them fail when "p" happens to be a zip archive. Dieter From qwweeeit at yahoo.it Wed May 11 09:05:47 2005 From: qwweeeit at yahoo.it (qwweeeit at yahoo.it) Date: 11 May 2005 06:05:47 -0700 Subject: Importing modules Message-ID: <1115816747.292060.292200@o13g2000cwo.googlegroups.com> The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In some cases there is a further complication: module importing through an indirect mechanism, like: exec "from " + xxx + " import *". A part the fact that I have not understood the "real" difference between import and from ... import (or also from... import *), is it possible to re-build the application in only one chunck? This is only to better understand the application's structure, in order to implement a flow chart tool. I have already developed a cross reference tool and I applied it to PySol (solitary card games). PySol is made up of almost 100 modules for a total of almost 30000 lines. To understand a program, however, you need also a flow chart... From http Mon May 23 13:29:58 2005 From: http (Paul Rubin) Date: 23 May 2005 10:29:58 -0700 Subject: execution error References: <3fehq6F7flfgU1@individual.net> Message-ID: <7x8y257svd.fsf@ruckus.brouhaha.com> "Ximo" writes: > And my question is how can show the execution error whitout exit of the > program, showing it in the error output as... > >>6/0 > >>"Error: Division per 0" Trap the ArithmeticError exception and go by the name of the exception class. See the language ref manual about how exceptions work. From anton.vredegoor at gmail.com Tue May 17 08:03:04 2005 From: anton.vredegoor at gmail.com (Anton Vredegoor) Date: 17 May 2005 05:03:04 -0700 Subject: Python on a public library computer In-Reply-To: References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> <42892C88.6090609@open-networks.net> Message-ID: <1116331384.934151.306320@z14g2000cwz.googlegroups.com> Chris Lambacher topposted: > usb key and moveable python. > http://www.voidspace.org.uk/python/movpy/ I have a usb card reader and I can use it. That saves me from having to have remote storage at least. However I can only save files, not open them, except if I use word, excel or powerpoint. The moveable python is great indeed. This worked here before, but then I could even access *other* peoples usb sticks in this whole building ... Crazy. Not anymore though. They could really use someone like me here for a sensible security policy that doesn't cripple the users. I can't even set internet options, that means I can't remove my history or clear my cache :-( Anton 'security doesn't mean shooting everyone in the foot' From robin at reportlab.com Sat May 21 15:16:17 2005 From: robin at reportlab.com (Robin Becker) Date: Sat, 21 May 2005 19:16:17 +0000 Subject: python24.zip In-Reply-To: References: <428e0cc3$0$29954$9b622d9e@news.freenet.de> Message-ID: <428F8901.5000300@jessikat.fsnet.co.uk> Dieter Maurer wrote: ..... > > The question was: > > "should python start up with **non-existent** objects on the path". > > I think there is no reason why path needs to contain an object > which does not exist (at the time the interpreter starts). > > In your use case, "python24.zip" does exist and therefore may > be on the path. When "python24.zip" does not exist, it does > not contain anything and especially not "site.py". > I think this was my intention, but also I think I have some concern over having two possible locations for the standard library. It seems non pythonic and liable to cause confusion if some package should manage to install python24.zip while I believe that python24\lib is being used. > > I recently analysed excessive import times and > saw thousands of costly and unneccesary filesystem operations due to: > > * long "sys.path", especially containing non-existing objects > > Although non-existent, about 5 filesystem operations are > tried on them for any module not yet located. > > * a severe weakness in Python's import hook treatment > > When there is an importer "i" for a path "p" and > this importer cannot find module "m", then "p" is > treated as a directory and 5 file system operations > are tried to locate "p/m". Of course, all of them fail > when "p" happens to be a zip archive. > > > Dieter I suppose that's a reason for eliminating duplicates and non-existent entries. -- Robin Becker From jhofmann at ucsc.edu Sat May 28 22:11:49 2005 From: jhofmann at ucsc.edu (James Hofmann) Date: Sun, 29 May 2005 02:11:49 +0000 (UTC) Subject: Strings for a newbie References: Message-ID: Malcolm Wooden dtptypes.com> writes: > > I'm trying to get my head around Python but seem to be failing miserably. I > use RealBasic on a Mac and find it an absolute dream! But Python....UGH! > > I want to put a sentence of words into an array, eg "This is a sentence of > words" > > In RB it would be simple: > > Dim s as string > Dim a(-1) as string > Dim i as integer > > s = "This is a sentence of words" > For i = 1 to CountFields(s," ") > a.append NthField(s," ",i) > next > > That's it an array a() containing the words of the sentence. > > Now can I see how this is done in Python? - nope! > > UGH! > > Malcolm > (a disillusioned Python newbie) > This is the "verbose" version. s = "This is a sentence of words" nextword = "" words = [] for character in s: if character==" ": words.append(nextword) nextword = "" else: nextword+=character # string types use += instead of append words.append(nextword) # include the last word print words The main sticking point for you was probably understanding the way Python lets you loop through sequence types. In general, sequences(list, string, etc.) can be iterated either by an explicit function call, item = sequence.next(), or more commonly with "for item in sequence:" which will make Python go through every item it sees inside the sequence. This turns out to be more convenient than keeping a seperate counter in the vast majority of cases, because it cuts straight to the business of manipulating each item, rather than tracking where it is. Now a "slim" version: s = "This is a sentence of words" print s.split() But there's no learning from that one, it's just an easy library call. From simon.brunning at gmail.com Mon May 9 10:14:49 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Mon, 9 May 2005 15:14:49 +0100 Subject: Trouble saving unicode text to file In-Reply-To: <427f6c37$0$283$edfadb0f@dread12.news.tele.dk> References: <1115500976.571232.76100@z14g2000cwz.googlegroups.com> <427DDAA5.9020606@v.loewis.de> <427E5136.4000300@v.loewis.de> <427f6c37$0$283$edfadb0f@dread12.news.tele.dk> Message-ID: <8c7f10c6050509071430925755@mail.gmail.com> On 5/9/05, Max M wrote: > Fredrik Lundh wrote: > > > (I just noticed that there's no euro sign on my swedish keyboard. I've > > never missed it ;-) > > It's probably "AltGR + E" like here in DK My UK keyboard has it as AltGr + 4, FWIW. -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From jonasmg at softhome.net Wed May 18 06:27:20 2005 From: jonasmg at softhome.net (Jonas Melian) Date: Wed, 18 May 2005 11:27:20 +0100 Subject: Python forum In-Reply-To: <1116362069.228928.72720@z14g2000cwz.googlegroups.com> References: <1116362069.228928.72720@z14g2000cwz.googlegroups.com> Message-ID: <428B1888.3050506@softhome.net> madsurfer2000 at hotmail.com wrote: > > What's wrong with this web forum ;-) > > http://groups-beta.google.com/group/comp.lang.python?hl=en > > c.l.python is a mailing list, usenet group and a web forum. How you > access it is up to you. There are also other nntp-to-web sites out > there, and you can even make your own if you don't like them. > I personally try of not using google. One has become too powerful. From rune.strand at gmail.com Thu May 5 06:29:23 2005 From: rune.strand at gmail.com (runes) Date: 5 May 2005 03:29:23 -0700 Subject: using variables with modules In-Reply-To: <1115285809.074451.171110@z14g2000cwz.googlegroups.com> References: <1115285809.074451.171110@z14g2000cwz.googlegroups.com> Message-ID: <1115288963.571659.22820@o13g2000cwo.googlegroups.com> The only problem I can see, is trailing whitespace from the ip.txt file. Perhaps ClientIP.strip() will help? From peter at engcorp.com Mon May 16 12:48:58 2005 From: peter at engcorp.com (Peter Hansen) Date: Mon, 16 May 2005 12:48:58 -0400 Subject: command string good in subprocess.Popen(string) fails in process.Process(string) In-Reply-To: References: <9YSdnavxIbdvAhXfRVn-1w@powergate.ca> Message-ID: <7pmdnS5f65ySUhXfRVn-2A@powergate.ca> Earl Eiland wrote: > from Trent Mick trentm at ActiveState.com: > "You might be able to use or borrow code from my process.py module. Few here have ever heard of it, I suspect. Maybe you should ask Trent for help? > >>Earl Eiland wrote: >> >>>The command string consists of "filename.exe instruction1 instruction2 >>>..." It works in subprocess, but in process, returns the error "can't >>>find the file instruction1". >>> >>>How do I pass command line instructions in process.Process? I tried a >>>list ['filename.exe', 'instruction1 instruction2 ...'] with the same >>>result. The docs (in the form of the Powerpoint presentation on his site, which I'm reading using OpenOffice) suggest maybe you should be using ['filename.exe', 'instruction1', 'instruction2', ...] instead... -Peter From loicderoyand at yahoo.fr Sun May 8 05:59:22 2005 From: loicderoyand at yahoo.fr (LDD) Date: 8 May 2005 02:59:22 -0700 Subject: Newbie : checking semantics In-Reply-To: References: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> Message-ID: <1115546362.927282.151840@o13g2000cwo.googlegroups.com> Be reassured, I'm not working in any business related to pacemakers, avionics or railway signalling equipement ... :) I'm just a guy who is learning Python because to me it seems to be the best alternative to Perl, and trying to know what it is fit for. From sjmachin at lexicon.net Mon May 16 17:34:46 2005 From: sjmachin at lexicon.net (John Machin) Date: Tue, 17 May 2005 07:34:46 +1000 Subject: Anyway to designating the encoding of the "source" for compile? References: <1116087091.856022.155340@z14g2000cwz.googlegroups.com> <1116263722.499345.73260@g43g2000cwa.googlegroups.com> Message-ID: On 16 May 2005 10:15:22 -0700, janeaustine50 at hotmail.com wrote: >janeaustine50 at hotmail.com wrote: >> Python's InteractiveInterpreter uses the built-in compile function. >> >> According to the ref. manual, it doesn't seem to concern about the >> encoding of the source string. >> >> When I hand in an unicode object, it is encoded in utf-8 >automatically. >> It can be a problem when I'm building an interactive environment >using >> "compile", with a different encoding from utf-8. I don't understand this. Suppose your "different encoding" is cp125x (where x is a digit). Would you not do something like this? compile_input = user_input.decode('cp125x') code_object = compile(compile_input, ...... >> IDLE itself has the >> same problem. ( '' is treated okay >> but u'' is treated wrong.) >> >> Any suggestions or any plans in future python versions? > >I've read a posting from Martin Von Loewis mentioning trying to build >in that feature(optionally marking encoding when calling "compile"). >Anyone knows how it is going on? Firstly, it would help those who might be trying to help you if you could post a simple example: input, output, what error message, what you mean by 'is treated wrong' ... and when it comes to Unicode objects (indeed any text), show us repr(text) -- "what you see is often not what others see and often not what you've actually got". Secondly, are any of the contents of PEP 263 of any use to you? http://www.python.org/peps/pep-0263.html From jacob at cd.chalmers.se Sun May 15 17:34:35 2005 From: jacob at cd.chalmers.se (Jacob Hallen) Date: 15 May 2005 21:34:35 GMT Subject: Optimise Europython competition Message-ID: A classic dilemma for conferences is that if you have many tracks, you may find that all of a sudden, a room is swamped, and there is a queue of people wanting to get in. Another problem is that you risk scheduling talks against each other that have a very large set of interested people in common. At Europython we are this year going to try a new way of scheduling, in order to reduce these problems. Before the schedule is made, we will give all attendees the opportunity to register what talks they are most interested in. We then want to make a schedule that is optimised based on these data. Since I am no expert in optimising algorithms of this type, and since the time I have available for these things is limited, I'm turning to the readers of c.l.p and python-logic for help. I'm offering the following bounty for a working solution (in Python): - Free attendance at this years Europython, as a guest of honour - A Europython T-shirt in a limited special edition - Fame and gratitude from conference attendees who get better scheduling The winner of the bounty is the person who scores most points, according to the criteria below. If we get more than one solution that does good optimisation, we will award more than one bounty. Here are the parameters: 1. There are 10 tracks with between 1 and 30 talks in each track. You may not schedule two talks in the same track against each other, unless there is more talks than available calendar time. 2. A track should be continuous. Each track that is continuous gives you 10 points. 3. We expect about 300 attendees. About half of them are expected to register their interests. Interests may range from a single talk to more than half of all the talks. You get one point for each talk an attendee can attend out of the ones the attendee has registered interest in. 4. Talks are of varying lengths. Lengths can be 30, 45, 60 and 90 minutes. The large majority of talks are 30 minutes. Only a very few are 45 minutes. 5. Rooms come in different sizes Room A has 180 seats Room B has 140 seats Room C has 140 seats Room D has 70 seats Room E has 70 seats Room A-D should be scheduled throughout the conference while room E is extra expansion space, only to be used when absolutely necessary. For every person scheduled above (Room capacity * (Number of responding attendees / Total number of attendees)) you get one point taken off your score. 6. There are a total of 10 90-minute time blocks. Day 1: 09:00 Day 1: 11:00 Day 1: 14:00 Day 1: 16:00 Day 2: 09:00 Day 2: 11:00 Day 2: 14:00 Day 2: 16:00 Day 3: 09:00 Day 3: 11:00 A track should not change room in the middle of a time block. Doing so reduces your score by 50 points. 7. Input data You get your input data in the form of a list of tuples; one tuple per talk. Each tuple looks like this: (, , , [list of interested attendees]) Talk length is an integer, all other items are strings. 8. Output data You should supply your output data in the form of a list of tuples; one tuple per talk. Each tuple should look like this: (, , , ) Talk id should be the same as in the input. Room should be a one letter string with a value in the range A-E. Day should be a one letter string in the range 1-3. Starting time should be a string on the form HH:MM, in the 24 hour clock. Solutions should be sent by email to europython at python.org no later than 1 June 2005. Currently we haven't started gathering real data, but there should be some available for real world testing before 1 June. -- From nyamatongwe+thunder at gmail.com Sat May 21 18:20:47 2005 From: nyamatongwe+thunder at gmail.com (Neil Hodgson) Date: Sat, 21 May 2005 22:20:47 GMT Subject: Fw: evidence john bokma al jazeera connection ? In-Reply-To: <1T87IN1838493.4652546296@anonymous.poster> References: <1T87IN1838493.4652546296@anonymous.poster> Message-ID: <3vOje.10678$E7.5693@news-server.bigpond.net.au> There is a response to this on John's web site: http://johnbokma.com/mexit/2005/05/19/daniel-joseph-min.html Neil From mefjr75 at hotmail.com Sat May 14 18:27:37 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 14 May 2005 15:27:37 -0700 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> <42866cb8.177725696@news.oz.net> Message-ID: <1116109657.494997.315650@o13g2000cwo.googlegroups.com> I explained what i meant in previous post there was nothing more than just a discussion I have no real problem here just more of a sore point in style for me. I feel that parens are quite overloaded and it can be confusing to newbies. But if the parens are just fluff then get rid of them, it is clearer * at least to me * ;) There are enough things wrapped in parens nowadays it is starting to look like lisp. > BTW, UIAM it is the commas that define tuples, so the outermost parens are really >expression >parens more than tuple syntax. Hadn't really thought of that way but it makes sense >>> w = 1,2,3 >>> w.__doc__ """tuple() -> an empty tuple tuple(sequence) -> tuple initialized from sequence's items If the argument is a tuple, the return value is the same object.""" Thanks for your time Bengt! M.E.Farmer From duncan.booth at invalid.invalid Fri May 27 11:21:40 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2005 15:21:40 GMT Subject: Incrementing letters References: Message-ID: Dan Sommers wrote: > Wolfram Kraus wrote: > >> Duncan Booth wrote: > >>>>>> import string >>>>>> upone = string.maketrans( >>> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', >>> 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA') >>> >>>>>> string.translate("I've got a string s....", upone) > >>> "J'wf hpu b tusjoh t...." > >>> Note the difference though: the Python code does what you said you >>> wanted, whereas your sample code corrupts punctuation. > >> Wow, that's quite nice. You really learn something new every day :-) A >> minor improvement: Use string.ascii_letters as the first parameter for >> string.maketrans Yes, my first attempt at responding did that, but I changed it because that makes the assumption that string.ascii_letters is in a specific order (did you know that lowercase came first and uppercase second without checking?) > > And use string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ] for the > second parameter to string.maketrans. > Bzzt. Wrong answer. Look closely at the middle of the string. I did have: >>> upone = string.maketrans(string.ascii_letters, 'z'+string.ascii_lowercase[:-1] + 'Z' + string.ascii_uppercase[:-1]) but as I said, that makes too many assumptions for my liking about the contents of those variables. From elie at flashmail.com Sun May 15 03:30:59 2005 From: elie at flashmail.com (Eli) Date: 15 May 2005 00:30:59 -0700 Subject: Question about extending the interperter In-Reply-To: References: <1115654593.479760.52610@o13g2000cwo.googlegroups.com> Message-ID: <1116142259.356209.86070@z14g2000cwz.googlegroups.com> Thanks for your answer, I've tried the way Fredrik suggested which pointed out to a solution. cheers From ninjalabs at gmail.com Mon May 16 10:05:44 2005 From: ninjalabs at gmail.com (Chris) Date: 16 May 2005 07:05:44 -0700 Subject: Web server platform for beginner In-Reply-To: <42889bc1$0$64748$e4fe514c@news.xs4all.nl> References: <1116247947.853539.316620@g49g2000cwa.googlegroups.com> <42889bc1$0$64748$e4fe514c@news.xs4all.nl> Message-ID: <1116250197.036479.61030@z14g2000cwz.googlegroups.com> If only i'd seen that page ;-) Thanks for the heads up Cheers, - Chris. From eurleif at ecritters.biz Sat May 28 07:45:26 2005 From: eurleif at ecritters.biz (Leif K-Brooks) Date: Sat, 28 May 2005 11:45:26 GMT Subject: search/replace in Python (solved) In-Reply-To: References: Message-ID: Vamsee Krishna Gomatam wrote: > text = re.sub( "([^<]*)", r' href="http://www.google.com/search?q=\1">\1', text ) But see what happens when text contains spaces, or quotes, or ampersands, or... From mnations at gmail.com Thu May 26 16:09:46 2005 From: mnations at gmail.com (Mudcat) Date: 26 May 2005 13:09:46 -0700 Subject: Design problem...need some ideas In-Reply-To: <1117081206.100096.298770@g49g2000cwa.googlegroups.com> References: <1117081206.100096.298770@g49g2000cwa.googlegroups.com> Message-ID: <1117138186.239544.229700@g43g2000cwa.googlegroups.com> bump Anyone? I don't need code. Just widgets and a compass for the right direction. From pugnatio at gmail.com Thu May 12 11:34:18 2005 From: pugnatio at gmail.com (pugnatio at gmail.com) Date: 12 May 2005 08:34:18 -0700 Subject: Creating new StructuredText-like content type for Zope/Plone Message-ID: <1115912058.576813.292150@g44g2000cwa.googlegroups.com> I prefer to use my own text format instead of StructuredText or the like, because I also use emacs outline mode a lot. What would be the best approach for creating this new content type in Zope/Plone? Writing a new Plone product with page templates seems fairly involved, but maybe it's desirable to have that control. Would Archetypes suffice? Thanks in advance, --tobias From mcherm at mcherm.com Tue May 24 12:46:10 2005 From: mcherm at mcherm.com (Michael Chermside) Date: Tue, 24 May 2005 09:46:10 -0700 Subject: line-by-line output from a subproce Message-ID: <20050524094610.mu1i6j0fs9gg08gk@login.werra.lunarpages.com> I wrote: > I am using the subprocess module to invoke a command-line utility > [...] I would like to process the output line-by-line [...] > rather than running [...] to completion Simon Percivall writes: > Okay, so the reason what you're trying to do doesn't work is that the > readahead buffer used by the file iterator is 8192 bytes, which clearly > might be too much. Jp Calderone writes: > def iterread(fobj): > return iter(fobj.readline, '') Thanks folks... that did it nicely! -- Michael Chermside From lee_cullens at mac.com Tue May 17 00:32:33 2005 From: lee_cullens at mac.com (Lee Cullens) Date: Tue, 17 May 2005 00:32:33 -0400 Subject: Python Interest Group Query Message-ID: <103EFE5F-2E0D-402C-8455-A2A17C6C697E@mac.com> Python Interest Group Query I'm aware of the Boston PIG, a smaller one in Amherst and have been told that there is possibly a PIG in Manchester, NH. Basically I'm trying to find out if there are any, or any interest in (or even any other Python users at all :~)) in a PIG in the northern NE corridor (Vermont, New Hampshire, Maine). I'm a recent Mac and Python convert working at some multimedia software development, and retired from a software engineering career. I live in western NH and back in the late 80's commuted to Boston and NY, so I'm not very keen on such anymore :~) Thank you, Lee C From "myname" at example.invalid Sun May 29 10:23:20 2005 From: "myname" at example.invalid (VK) Date: Sun, 29 May 2005 16:23:20 +0200 Subject: Entry scroll doesn't work Message-ID: <3fu1jhF9klm2U1@news.dfncis.de> Hi! Can entry widget be scrolled? VK TypeError: xview() takes exactly 2 arguments (4 given) Code: from Tkinter import * class ScrollEntry: def __init__(self): self.root = Tk() self.scrollbar = Scrollbar(self.root,orient=HORIZONTAL,) self.entry = Entry(self.root,xscrollcommand=self.scrollbar.set) self.entry.focus() self.entry.pack(side=TOP,fill=X) self.scrollbar.pack(fill=X) self.scrollbar.config(command=self.entry.xview) self.entry.config() a=ScrollEntry() a.root.mainloop() From sjmachin at lexicon.net Thu May 19 18:39:44 2005 From: sjmachin at lexicon.net (John Machin) Date: Fri, 20 May 2005 08:39:44 +1000 Subject: Comparing 2 similar strings? References: <24a6d$428b9c10$d1b717f8$2300@PRIMUS.CA> <428BA05D.1010600@lsupcaemnt.com> <3d9n815cpmavos1fl6ts712h9qogdv3fur@4ax.com> <153o811mt7uhqa3aojb5101sd7qo4jrgps@4ax.com> Message-ID: <053q81p4fivbdpunaedsk618u08jdku7qg@4ax.com> On Fri, 20 May 2005 01:47:15 +1000, Steven D'Aprano wrote: >On Thu, 19 May 2005 14:09:32 +1000, John Machin wrote: > >> None of the other approaches make the mistake of preserving the first >> letter -- this alone is almost enough reason for jettisoning soundex. > >Off-topic now, but you've made me curious. > >Why is this a bad idea? > >How would you handle the case of "barow" and "marow"? (Barrow and >marrow, naturally.) Without the first letter, they sound identical. Why is >throwing that information away a good thing? Sorry if that was unclear. By "preserving the first letter", I meant that in "standard" soundex, the first letter is not transformed into a digit. Karen -> K650 Kieran -> K650 (R->6, N->5; vowels->0 and then are squeezed out) Now compare this: Aaron -> A650 Erin -> E650 Bearing in mind that the usual application of soundex is "all or nothing", the result is Karen == Kieran, but Aaron !== Erin, which is at the very least extremely inconsistent. A better phonetic-key creator would produce the same result for each of the first pair, and for each of the second pair -- e.g. KARAN and ARAN respectively. Also consider Catherine vs Katherine. Cheers, John From loicderoyand at yahoo.fr Sat May 7 18:05:20 2005 From: loicderoyand at yahoo.fr (LDD) Date: 7 May 2005 15:05:20 -0700 Subject: Newbie : checking semantics Message-ID: <1115503520.392357.230620@f14g2000cwb.googlegroups.com> Hi everyone, I am new to python and was very enthustic about its possibilities when I discover that python is really what it is : just a scripting language. What disappoints me is that pyton will happily accept and execute this code : if ( aConditionThatIsFalse ): AFunctionThatIsntDefined() print "Hello world" The fact that python doesn't check if the symbol AFunctionThatIsntDefined is defined, is really bad when you develop big pieces of code. You will never be sure that your code is free of this kind of dummy errors and testing every possible execution paths is nightmarish ! Is there a way to force Python to check the definition of symbol ? LDD From reinhold-birkenfeld-nospam at wolke7.net Mon May 2 15:17:00 2005 From: reinhold-birkenfeld-nospam at wolke7.net (Reinhold Birkenfeld) Date: Mon, 02 May 2005 21:17:00 +0200 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: Message-ID: <3dnco7F6sgmkrU1@individual.net> darren kirby wrote: > quoth the Ganesan Rajagopal: >> I am stuck on level 3. I've tried every re that I can think of. Some body >> give me a clue. >> >> Ganesan >> >> -- >> Ganesan Rajagopal > >>>> t = /text of page source.../ >>>> re.findall('[a-z][A-Z]{3}[a-z]{1}[A-Z]{3}[a-z]', t) > > You should get ten results. Consider all ten together to get your solution... Somehow writing '[a-z]{1}' is strange... Reinhold From getvijay at gmail.com Fri May 27 17:21:36 2005 From: getvijay at gmail.com (Vijay Kumar) Date: Fri, 27 May 2005 15:21:36 -0600 Subject: f->f_locals is NULL for a method call Message-ID: hi, I have written a trace function in C using the Python/C API. I want to find whether the call occured is a function call or method call and if a method call, its self object. int tracer(PyObject *obj, PyObject *f, int what, PyObject *args){ PyObject *item,*SelfItem; switch(what){ case PyTrace_CALL: { printf("%s",PyString_AS_STRING(f->f_code->co_name)); if(f->f_code->co_argcount>0 && strcmp(PyString_AS_STRING(PyTuple_GetItem(f->f_code->co_varnames,0),"self")==0) { //checks if the call is a method call printf("Method\n"); SelfItem = f->f_locals; } else printf("Function"); } } The SelfItem obtained is a NULL object (for method call).But when I wrote the same trace function in python, f->f_locals is a dictionary with "self" as a keyword. How can i get the dictionary in C? Thanks, Vijay. From onfrek at yahoo.com Fri May 27 09:31:56 2005 From: onfrek at yahoo.com (Michael Onfrek) Date: 27 May 2005 06:31:56 -0700 Subject: Copy paste in entry widget Message-ID: <1117200716.423741.257870@f14g2000cwb.googlegroups.com> Hi, is copy, paste, cut of selection possible in entry widget? Docs say selection must be copied by default, in my programm it doesn't work. Regards, M.O. From kenneth.pronovici at cedar-solutions.com Sun May 22 13:25:12 2005 From: kenneth.pronovici at cedar-solutions.com (Kenneth Pronovici) Date: Sun, 22 May 2005 12:25:12 -0500 Subject: EpyDoc problem In-Reply-To: <428C4867.4050906@geochemsource.com> References: <428A5CAA.906@geochemsource.com> <428A66A8.9090000@geochemsource.com> <1116446157.756809.97320@g49g2000cwa.googlegroups.com> <428C4867.4050906@geochemsource.com> Message-ID: <20050522172512.GA11769@cedar-solutions.com> > >EpyDoc is hosted in Sourceforge. This alone may answer your question > >about a bug-tracker: > > > >http://sourceforge.net/tracker/?atid=405618&group_id=32455&func=browse > > > > > Well, I wrote to the bug tracker some days ago but no answer so far. I am the maintainer of the Debian epydoc package. Lately, I have also found it difficult to contact epydoc's author, Edward Loper. I'm currently not sure whether my mail is getting spam-filtered or whether something else has happened and he's not available any more. Maybe someone on the list knows what's going on? I think your best bet is to file the bug (which you have done) and wait for a reply, keeping in mind that it might be a while before someone has time to deal with your bug. Most people writing free software are volunteers, after all. KEN -- Kenneth J. Pronovici http://www.cedar-solutions.com/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 240 bytes Desc: not available URL: From Bernd.Nawothnig at t-online.de Sat May 14 13:01:15 2005 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sat, 14 May 2005 19:01:15 +0200 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> Message-ID: On 2005-05-14, David wrote: > abc(x,y,dotp,sumx,maxv) (x,y,dotp,sumx,maxv) = abc(x,y,dotp,sumx,maxv) Bernd -- Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. [T. Jefferson] From rrr at ronadam.com Sun May 15 16:30:53 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 15 May 2005 16:30:53 -0400 Subject: Quick Reference from module doc strings. In-Reply-To: <42861D22.6000701@ronadam.com> References: <42861D22.6000701@ronadam.com> Message-ID: <4287B17D.4050102@ronadam.com> I think this deserves a little more of a description than I gave it initially. The routine in the previous message does a little more than just print out __doc__ strings. It outputs a formatted alphabetical list of objects in a module with each objects, name, class or type, and then tries to determine if the doc string is part of the class or was inherited from a parent class. If the object is a storage type, then it will print the objects contents/values giving you what they are at import time. If the string or list, tuple, or dict is large, it will print just the beginning with '......' at the end to let you know there is more. So what you get is a printable alphabetical quick reference guide with the first level class's, functions, exceptions, and attributes with the initial values after importing. (You can also do this with a single class and get it's methods and attributes.) Here is the first part of __builtins__ (Python 2.3) as an example. If anyone has any suggestions or corrections, Please let me know. Cheers, _Ron Adam ---------------------------------------- __builtins__ Class: Built-in functions, exceptions, and other objects. Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices. ---------------------------------------- __builtins__.__debug__ Class: __builtins__.__debug__=True ---------------------------------------- __builtins__.__doc__ Class: __builtins__.__doc__="""Built-in functions, exceptions, and other objects. Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices.""" ---------------------------------------- __builtins__.__import__ Module:__builtin__ Class: __import__(name, globals, locals, fromlist) -> module Import a module. The globals are only used to determine the context; they are not modified. The locals are currently unused. The fromlist should be a list of names to emulate ``from name import ...'', or an empty list to emulate ``import name''. When importing a module from a package, note that __import__('A.B', ...) returns package A when fromlist is empty, but its submodule B when fromlist is not empty. ---------------------------------------- __builtins__.__name__ Class: __builtins__.__name__="__builtin__" ---------------------------------------- __builtins__.abs Module:__builtin__ Class: abs(number) -> number Return the absolute value of the argument. ---------------------------------------- __builtins__.apply Module:__builtin__ Class: apply(object[, args[, kwargs]]) -> value Call a callable object with positional arguments taken from the tuple args, and keyword arguments taken from the optional dictionary kwargs. Note that classes are callable, as are instances with a __call__() method. Deprecated since release 2.3. Instead, use the extended call syntax: function(*args, **keywords). ---------------------------------------- __builtins__.ArithmeticError Module:exceptions Type: Base class for arithmetic errors. ---------------------------------------- __builtins__.AssertionError Module:exceptions Type: Assertion failed. ---------------------------------------- __builtins__.AttributeError Module:exceptions Type: Attribute not found. ---------------------------------------- __builtins__.basestring Module:__builtin__ Class: Type basestring cannot be instantiated; it is the base for str and unicode. ---------------------------------------- __builtins__.bool Module:__builtin__ Class: bool(x) -> bool Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed. ---------------------------------------- __builtins__.buffer Module:__builtin__ Class: buffer(object [, offset[, size]]) Create a new buffer object which references the given object. The buffer will reference a slice of the target object from the start of the object (or at the specified offset). The slice will extend to the end of the target object (or with the specified size). ---------------------------------------- Continued..... And here is the program again. def getobjs(object, dlist=[], lvl=0, maxlevel=1): """ Retreive a list of sub objects from an object. """ if object not in dlist: dlist.append(object) if lvl200: s = object[0:200]+"......" else: s = object outtext.append(obj+'=') if '\n' in s: quotes='"""' else: quotes ='"' if len(s)>60: print outtext.append(quotes+s+quotes+'\n\n') elif (isinstance(object,str) or isinstance(object,int) or isinstance(object,bool) or isinstance(object,tuple) or isinstance(object,list) or isinstance(object,dict)): s = str(object) if len(s)<200: outtext.append(obj+'='+s+'\n\n') else: outtext.append(obj+'='+s[0:200]+'......\n\n') if hasattr(object,'__doc__'): if object.__doc__ != type(object).__doc__: outtext.append(str(object.__doc__)+'\n\n') return ''.join(outtext) def quick_ref(name): """ quick_ref(module_name) -> printable string Generate a sorted quick reference guide from an objects doc strings. The module_name is a string with the name of the module or class to get documents string from. Example: import os print quick_ref('os') """ objlist = getobjs(name) return printdoc(objlist) if __name__ == "__main__": #import os print quick_ref('__builtins__') From skip at pobox.com Wed May 11 21:43:34 2005 From: skip at pobox.com (Skip Montanaro) Date: Wed, 11 May 2005 20:43:34 -0500 Subject: Python Documentation (should be better?) In-Reply-To: <428276e8$0$318$626a14ce@news.free.fr> References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> <428276e8$0$318$626a14ce@news.free.fr> Message-ID: <17026.46278.169449.880219@montanaro.dyndns.org> Ivan> I can never remember ...where to find string methods >>>> dir('') Bruno> ['__add__', '__class__', ... Also: >>> help(str) Help on class str in module __builtin__: class str(basestring) | str(object) -> string | | Return a nice string representation of the object. | If the argument is a string, the return value is the same object. | | Method resolution order: | str | basestring | object | | Methods defined here: ... Skip From modelnine at ceosg.de Wed May 4 17:23:12 2005 From: modelnine at ceosg.de (Heiko Wundram) Date: Wed, 4 May 2005 23:23:12 +0200 Subject: Bandwith Shaping In-Reply-To: <42791055.1090809@anvilcom.com> References: <1115228921.520113.245920@z14g2000cwz.googlegroups.com> <42791055.1090809@anvilcom.com> Message-ID: <200505042323.15342.modelnine@ceosg.de> Am Mittwoch, 4. Mai 2005 20:11 schrieb phil: > But those packets ( I assume TCP ) are going to stack up somewhere, > the sender is gonna keep trying and retrying. In other words > you are increasing overall load to someone's router and the > network. This is not true, as TCP tries to adjust its sending speed at the sender end to the receiving speed at the receiver end (it raises speed until packets start getting dropped, and when they are, it starts decreasing send speed again). Of course, this requires a proper TCP implementation, but any operating system should have one. What you said, with a sleep(.01) is actually not quite the way to go. What you could do is something like the following: MAX_RATE = 1*1024 # (1k) MAX_SEND = 1024 data = "blabber" sent = 0 starttime = time.time() - 0.01 while data: curtime = time.time() if sent / ( curtime - starttime ) > MAX_RATE: time.sleep(0.5) continue newsent = sock.send(data[:MAX_SEND]) data = data[newsent:] sent += newsent > Someone correct me if I'm drunk on this. See above. ;) -- --- Heiko. listening to: Pearl Jam - Man Of The Hour see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: From peter at engcorp.com Tue May 3 07:19:23 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 03 May 2005 07:19:23 -0400 Subject: py2exe and library.zip In-Reply-To: References: Message-ID: <5uadnUTTqv6Iw-rfRVn-qw@powergate.ca> Timothy Smith wrote: > is it possible instead of py2exe putting all library's in a zip file, to > just put them in a sub dir? Anything's possible. Maybe you could explain what you're actually trying to accomplish (or the reasons) so we can better understand where you're going with this... -Peter From ruach at chpc.utah.edu Tue May 10 12:40:35 2005 From: ruach at chpc.utah.edu (Matthew Thorley) Date: Tue, 10 May 2005 10:40:35 -0600 Subject: object oriented inheritance problem Message-ID: I am trying to inherit from ElementTree so I can add some methods. This is the code I am trying to make work, and the following is the error I am getting. from elementtree import ElementTree class AcidTree(ElementTree): def write_string(self): .... File "/home/hope/var/proj/acid/server/mgacparse.py", line 22, in ? class AcidTree(ElementTree): TypeError: Error when calling the metaclass bases module.__init__() takes at most 2 arguments (3 given) I have *no* idea what is going on here. AcidTree does not implement an __init__. It just adds two simple methods, which aren't even being called when then exception is thrown. The exception occurs on the class definition line when I try to inherit from ElementTree. I looked around, and read some stuff in the python cook book, and everything I've seen indicates that it should just work. My only thought is that its a 'oldstyle' vs 'newstyle' classes issue. I know that elementtree was written to be compatible with python 1.5 so maybe it doesn't work with the new stuff. But thats just a crazy assumption I made up to make myself feel better. If anyone could please exmplain what my problem *really* is I would appreciate it greatly. Thanks very much. -Matthew From newsgroups at jhrothjr.com Fri May 27 10:41:14 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 27 May 2005 08:41:14 -0600 Subject: Case Sensitive, Multiline Comments References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> <8664x5y92g.fsf@guru.mired.org> <429654DA.9050903@lexicon.net> <1117154013.092736.298310@g14g2000cwa.googlegroups.com> Message-ID: <119eccdgjtaru5d@news.supernews.com> "Duncan Booth" wrote in message news:Xns96635F84E6901duncanbooth at 127.0.0.1... > Dennis Lee Bieber wrote: > >> On 26 May 2005 17:33:33 -0700, "Elliot Temple" >> declaimed the following in comp.lang.python: >> >>> Thanks for the link on case sensitivity. I'm curious about the person >>> who found case sensitivity useful though: what is it useful for? >>> >> Making a language run faster on slow machines since the syntax >> parsing doesn't have to do the equivalent of upper or lower casing >> anything that is not a string literal before checking for keywords or >> identifiers. >> >> Consider the time spent by languages like Ada and Fortran when >> they have to do case normalization every time you compile. >> > That isn't a good argument for case sensitivity. You really aren't going > to > be able to measure a slowdown in compilation speed just because the > compiler has to lowercase all the identifiers before using them. Actually it is, but you have to get out of ASCII into the wider world of all of the real languages out there. Something I heard from one of the people who invented XML is that it originally started out as case insensitive, and they had quite an extensive discussion about it. When they made it case sensitive, one of the basic tools sped up by a factor of three. Doing case translations in Unicode following all of the rules for all of the world's languages is, for want of a better world, a real bitch. John Roth From peter at engcorp.com Wed May 18 00:55:59 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 18 May 2005 00:55:59 -0400 Subject: Representing ambiguity in datetime? In-Reply-To: References: Message-ID: Terry Hancock wrote: > What do you do when a date or time is > incompletely specified? Doesn't the answer to this pretty much entirely depend on how you are going to make use of the information? What are your use cases? From igorcarron at gmail.com Tue May 31 05:25:26 2005 From: igorcarron at gmail.com (igorcarron at gmail.com) Date: 31 May 2005 02:25:26 -0700 Subject: How do you drive-by-wire a car using Python ? In-Reply-To: References: <1117478120.880612.75250@g44g2000cwa.googlegroups.com> Message-ID: <1117531526.205312.192360@f14g2000cwb.googlegroups.com> Please note we had to avoid trash cans when the DARPA folks came to visit us. Our vehicle aims at being a garbage avoidance system instead :-) Igor. From ckwiguno at gmail.com Tue May 3 10:17:06 2005 From: ckwiguno at gmail.com (custard_pie) Date: 3 May 2005 07:17:06 -0700 Subject: sorting list and then return the index of the sorted item In-Reply-To: <1115128668.633320.285090@f14g2000cwb.googlegroups.com> References: <1115127433.984686.99060@f14g2000cwb.googlegroups.com> <1115128668.633320.285090@f14g2000cwb.googlegroups.com> Message-ID: <1115129826.951292.73070@f14g2000cwb.googlegroups.com> Okay...THanks a lot everyone,.. Those codes are a real help.... From doodle4 at gmail.com Mon May 16 13:32:41 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 16 May 2005 10:32:41 -0700 Subject: optparse global Message-ID: <1116264761.204065.15980@g14g2000cwa.googlegroups.com> Hello, How do i make an option passed through command line, using optparse global. I need to import this value in another file. This is what iam trying to do. $python test.py -d ffffffffffff i should be able to store 'ffffffffffff' as global so that i could access this value in another file. If 'ffffffffffff' is not given, then a default value stored in parser.add_options("-d", default="01ff010BFFFF", action="store") will be returned. Thanks, -Ashton From lbates at syscononline.com Fri May 13 09:39:54 2005 From: lbates at syscononline.com (Larry Bates) Date: Fri, 13 May 2005 08:39:54 -0500 Subject: doc tags? In-Reply-To: References: Message-ID: <4284AE2A.4070106@syscononline.com> In python they are called decorators, but I've never had a need to use them myself, but then I'm a little old fashioned. Larry Bates Wolfram Kriesing wrote: > i was already searching and remember i had seen something like "its not needed". > > Anyway, are there any doc tags, like in Java/PHPDoc etc, where you can > describe parameters (@param[eter]), return values (@ret[urn]), > attributes (@var), references (@see), etc? > > I guess I have just not found the link to the last flameware about it :-)) > From bokr at oz.net Wed May 4 18:33:43 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 04 May 2005 22:33:43 GMT Subject: xmlrpclib and decoding entity references References: <1115132826.795008.320190@z14g2000cwz.googlegroups.com> <427827a2$1_3@newspeer2.tds.net> <1115210118.418388.164710@g14g2000cwa.googlegroups.com> <1115219827.829558.200940@f14g2000cwb.googlegroups.com> Message-ID: <427924a7.671510130@news.oz.net> On 4 May 2005 08:17:07 -0700, "Chris Curvey" wrote: >Here is the solution. Incidentally, the client is Cold Fusion. > I suspect your solution may be not be general, though it would seem to satisfy your use case. It seems to be true for python's latin-1 that all the first 256 character codes are acceptable and match unicode 1:1, even though the windows character map for lucida sans unicode font with latin-1 codes shows undefined-char boxes for codes 0x7f-0x9f. >>> sum(chr(i).decode('latin-1') == unichr(i) for i in xrange(256)) 256 >>> sum(unichr(i).encode('latin-1') == chr(i) for i in xrange(256)) 256 Not sure what to make of that. E.g. should unichr(0x7f).encode('latin-1') really be legal, or is it just expedient to have latin-1 serves as a kind of compressed utf_16_le? E.g., there's 256 Trues in these: >>> sum(unichr(i).encode('utf_16_le')[0] == chr(i) for i in xrange(256)) 256 >>> sum(unichr(i).encode('utf_16_le')[1] == '\x00' for i in xrange(256)) 256 Maybe we could have a 'u_as_str' or 'utf_16_le_lsbyte' codec for that, so the above would be spelled >>> sum(unichr(i).encode('u_as_str') == chr(i) for i in xrange(256)) # XXX faked, not implemented 256 Utf-8 only goes half way: >>> sum(unichr(i).encode('utf-8') == chr(i) for i in xrange(256)) 128 >import re >import logging >import logging.config >import os >import SimpleXMLRPCServer > >logging.config.fileConfig("logging.ini") > >######################################################################## >class >LoggingXMLRPCRequestHandler(SimpleXMLRPCServer.CGIXMLRPCRequestHandler): > def __dereference(self, request_text): > entityRe = re.compile("((?P&#x)(?P..)(?P;))") What about entity ☺ ? Or the same in decimal: ☺ :) > for m in re.finditer(entityRe, request_text): > hexref = int(m.group(3),16) > charref = chr(hexref) unichr(hexref) would handle >= 256, if you used unicode. > request_text = request_text.replace(m.group(1), charref) > > return request_text > > >#------------------------------------------------------------------- > def handle_xmlrpc(self, request_text): > logger = logging.getLogger() > #logger.debug("************************************") > #logger.debug(request_text) ^^^^^^^^^^^^ I would suggest repr(request_text) for debugging, unless you know that your logger is going to do that for you. Otherwise a '%s' format may hide things that you'd like to know. > try: > #logger.debug("-------------------------------------") > request_text = self.__dereference(request_text) > #logger.debug(request_text) > request_text = request_text.decode("latin-1").encode('utf-8') AFAIK, XML can be encoded with many encodings other than latin-1, so you are essentially saying here that you know it's latin-1 somehow. Theoretically, your XML could start with something like and .decode("latin-1") is only going to "work" when the source is plain ascii. I wouldn't be surprised if that's what's happening up to the point where you __dereference, but str.replace doesn't care that you are potentially making a utf-8 encoding invalid by just replacing 8-bit characters with what is legal latin-1. after that, you are decoding your utf-8_clobbered_with_latin-1 as latin-1 anyway, so it "works". At least I think this is a consistent theory. See if you can get the client to send something with characters >128 that aren't represented as &#x..; to see if it's actually sending utf-8. > #logger.debug("************************************") > except Exception, e: > logger.error(request_text) again, suggest repr(request_text) > logger.error("had a problem dereferencing") > logger.error(e) > > SimpleXMLRPCServer.CGIXMLRPCRequestHandler.handle_xmlrpc(self, >request_text) >######################################################################## >class Foo: > def settings(self): > return os.environ > def echo(self, something): > logger = logging.getLogger() > logger.debug(something) repr it, unless you know ;-) > return something > def greeting(self, name): > return "hello, " + name > ># these are used to run as a CGI >handler = LoggingXMLRPCRequestHandler() >handler.register_instance(Foo()) >handler.handle_request() > Regards, Bengt Richter From megahrtz at gte.net Thu May 5 20:34:41 2005 From: megahrtz at gte.net (Alex N) Date: 5 May 2005 17:34:41 -0700 Subject: F.readline In-Reply-To: References: <000001c551ca$15ddd3b0$6400a8c0@grondor> Message-ID: <1115339681.312476.282990@z14g2000cwz.googlegroups.com> Erik Max Francis wrote: > Robert Kern wrote: > > > There is no such command built in. You will have to build it yourself > > out of the components that are available. > > linecache is probably what he's looking for. > > -- > Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis > No man who needs a monument ever ought to have one. > -- Nathaniel Hawthorne I figured I would have to write one, luckily I am not doing many Lines. Thank you. Alex Nordhus Clipboard Copy and Paste ! http://www.pasteaway.com From prabapython at yahoo.co.in Fri May 13 06:03:58 2005 From: prabapython at yahoo.co.in (praba kar) Date: Fri, 13 May 2005 11:03:58 +0100 (BST) Subject: Reg php equivalent Mail_mime Module in Python In-Reply-To: 6667 Message-ID: <20050513100358.33722.qmail@web8401.mail.in.yahoo.com> Dear All, email.Message module base we can build message for mailing services which is like php Mail_mime module. In php Mail_mime module willautomatically build all the header fields like content-type, content-Transfer-encoding, Return-Path and so on for a mailing messages. I want to know this(Mail_mime) kind of module in python. If Mail_mime like modules are not available in python kindly give guidenance how to build message for mailing service. regards Prabahar ________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony From k04jg02 at kzoo.edu Thu May 12 07:32:24 2005 From: k04jg02 at kzoo.edu (Joseph Garvin) Date: Thu, 12 May 2005 11:32:24 +0000 Subject: How "return" no return ? In-Reply-To: <3ehaurF34ak0U1@individual.net> References: <3ehaurF34ak0U1@individual.net> Message-ID: <42833EC8.9030103@kzoo.edu> Ximo wrote: >Hello, I want that the return sentence don't return anything, how can I do >it?. If i do only return it returns None, and pass don't run too. > >Can anyone help me?, thanks. >XIMO > > > > Returning None is the same as returning nothing. What exactly are you trying to do? From phillip.watts at anvilcom.com Thu May 5 14:04:21 2005 From: phillip.watts at anvilcom.com (phil) Date: Thu, 05 May 2005 13:04:21 -0500 Subject: How to detect a double's significant digits References: <1115314620.902071.323410@f14g2000cwb.googlegroups.com> Message-ID: <427A6025.8020704@anvilcom.com> fl = 1.0002 x = str(fl) pos = x.find('.') print len( x[pos+1:] ) >>> 4 mrstephengross wrote: > Hi all... How can I find out the number of significant digits (to the > right of the decimal place, that is) in a double? At least, I *think* > that's what I'm asking for. For instance: > > 0.103 --> 3 > 0.0103 --> 4 > 0.00103 --> 5 > 0.000103 --> 6 > 0.0000103 --> 7 > > Thanks in advance! > --Steve (mrstephengross at hotmail.com) > > From exarkun at divmod.com Fri May 20 16:45:00 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 20 May 2005 20:45:00 GMT Subject: buffer_info error In-Reply-To: <1116620313.966569.154020@g44g2000cwa.googlegroups.com> Message-ID: <20050520204500.559.197785299.divmod.quotient.5566@ohm> On 20 May 2005 13:18:33 -0700, "ashtonn at gmail.com" wrote: >i am filling in a packet with source and destination address and using >the buffer_info call to pass on the address to an underlying low level >call. > >The src and dest are strings, but buffer_info expects an array. How do >i deal with this? What's the low-level call you're invoking? Jp From bbcofchina at yahoo.com.cn Fri May 20 21:19:58 2005 From: bbcofchina at yahoo.com.cn (fdsl ysnh) Date: Sat, 21 May 2005 09:19:58 +0800 (CST) Subject: Can you introduce some book about python? In-Reply-To: Message-ID: <20050521011958.93547.qmail@web15007.mail.cnb.yahoo.com> --- python-list-request at python.org??: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, > visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body > 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it > is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: appending key-value pairs to a dict (Peter > Hansen) > 2. Re: Is Python suitable for a huge, enterprise > size app? > (Paul Rubin) > 3. Re: appending key-value pairs to a dict (Brian > Beck) > 4. Re: Comparing 2 similar strings? (Skip > Montanaro) > 5. Re: Is Python suitable for a huge, enterprise > size app? > (Paul Rubin) > 6. Re: buffer_info error (ashtonn at gmail.com) > 7. Re: appending key-value pairs to a dict (James > Stroud) > 8. From the call hook, how do I know more > precisely what is > called? (Vijay Kumar) > 9. Re: PyGame and Rotozoom (Sorry if OT) (Lee > Harr) > 10. Re: buffer_info error (Jp Calderone) > 11. Re: appending key-value pairs to a dict (Roy > Smith) > 12. Re: Is Python suitable for a huge, enterprise > size app? > (Dave Brueck) > 13. Re: Process monitoring (John Abel) > > ???: Peter Hansen > ???: python-list at python.org > ??: Fri, 20 May 2005 16:12:17 -0400 > ??: Re: appending key-value pairs to a dict > > rbt wrote: > > I know how to setup an empty list and loop thru > something... appending > > to the list on each loop... how does this work > with dicts? > > > > I'm looping thru a list of files and I want to put > the file's name and > > its sha hash into a dict on each loop. > > Whereas with a list you would call "append" in the > loop, with a > dictionary you simply use an indexed-assignment type > of access: > > mydict = {} > for filename in some_list_of_filenames: > hash = > sha.sha(open(filename).read()).hexdigest() # or > whatever > mydict[filename] = hash > > -Peter > > > ???: Paul Rubin > ???: python-list at python.org > ??: 20 May 2005 13:12:50 -0700 > ??: Re: Is Python suitable for a huge, enterprise > size app? > > Dave Brueck writes: > > One thing from your experience that did resonate > with me is that, > > except for ftplib and occasionally urllib (for > basic, one-shot GETs), > > we don't use any of the standard library's > "protocol" modules - partly > > because we had to implement our own HTTP libraries > for performance and > > scalability reasons anyway, and partly because we > had trouble figuring > > out e.g. all the ins and outs of > urllib/urllib2/httplib. > > What do you use for HTTPS? And did you use the > Cookie module in your > HTTP servers? You may have had problems without > even being aware of > them (until recently if you used Cookie with its > default settings, any > attacker could completely take over your server by > sending you > carefully concoted cookies). I'm not trying to be > contentious here, > just mentioning a couple further cases of where > problems aren't > visible from far away but are there when you look > close. > > > ???: Brian Beck > ???: python-list at python.org > ??: Fri, 20 May 2005 16:14:17 -0400 > ??: Re: appending key-value pairs to a dict > > rbt wrote: > > I know how to setup an empty list and loop thru > something... appending > > to the list on each loop... how does this work > with dicts? > > > > I'm looping thru a list of files and I want to put > the file's name and > > its sha hash into a dict on each loop. > > Like so: > > d = {} > for filename in files: > d[sha_func(filename)] = filename > > > Or like so: > > d = dict([(sha_func(filename), filename) for > filename in files]) > > -- > Brian Beck > Adventurer of the First Order > > > ???: Skip Montanaro > ??: python-list at python.org > ???: Steve Holden > ??: Fri, 20 May 2005 15:16:49 -0500 > ??: Re: Comparing 2 similar strings? > > > Steve> (is this the same as 'Conchobar'?) > > No, that's a trendy pub in Key West... > > > > Skip > > > ???: Paul Rubin > ???: python-list at python.org > ??: 20 May 2005 13:15:48 -0700 > ??: Re: Is Python suitable for a huge, enterprise > size app? > > "Fredrik Lundh" writes: > > this has been reported before, and it won't get > fixed (unless you're > > volunteering to add Python-compatible garbage > collection to Tk, that is). > > Yeah, I think I understand what the issue is. I can > think of some > kludgy possible fixes but I assume they've been > thought about already > and rejected. The workaround of making the > application save an extra > reference isn't too bad, but all relevant docs that > say anything about > these images should mention the requirement > emphatically. > > > ???: "ashtonn at gmail.com" > ???: python-list at python.org > ??: 20 May 2005 13:18:33 -0700 > ??: Re: buffer_info error > > i am filling in a packet with source and destination > address and using > the buffer_info call to pass on the address to an > underlying low level > call. > > The src and dest are strings, but buffer_info > expects an array. How do > i deal with this? > > > > ???: James Stroud > ???: python-list at python.org > ??: Fri, 20 May 2005 13:20:48 -0700 > ??: Re: appending key-value pairs to a dict > > On Friday 20 May 2005 01:04 pm, rbt wrote: > > I know how to setup an empty list and loop thru > something... appending > > to the list on each loop... how does this work > with dicts? > > > > I'm looping thru a list of files and I want to put > the file's name and > > its sha hash into a dict on each loop. > > > > Many thanks, > > > > rbt > > Simple assignment. > > adict[filename] = an_sha_hash > > > > -- > James Stroud > UCLA-DOE Institute for Genomics and Proteomics > Box 951570 > Los Angeles, CA 90095 > > http://www.jamesstroud.com/ > > > ???: Vijay Kumar > ??: vsuryade at cs.nmsu.edu > ???: python-list at python.org > ??: Fri, 20 May 2005 14:21:33 -0600 > ??: From the call hook, how do I know more > precisely what is called? > > Hi, > > I wrote a trace function using the profiling and > tracing hooks > provided by the python interpreter. > > The Python interpreter reports the calls occuring in > the source > program to my trace function. > > How can I know whether the call happened is a > function call or method > call and if it is a method call what is its self > object and/or class > is?. > > I receive a frame object from the interpreter for > every call. > > Thanks, > Vijay. > > > ???: Lee Harr > ???: python-list at python.org > ??: Fri, 20 May 2005 20:38:45 GMT > ??: Re: PyGame and Rotozoom (Sorry if OT) > > On 2005-05-20, J. W. McCall > wrote: > > I'm not sure if this is off-topic, since it > doesn't deal with Python > > itself, but here goes: > > > > I'm messing around with writing a simple "game" > where the player (a > > crudely drawn smiley face) moves by rotating and > moving back or forward > > (think Resident Evil, but from an always-above > view). After much > > hacking, I have it working where left and right > rotate the player sprite > > and up always moves the sprite whichever direction > it's facing, while > > down is reverse. I'm using > pygame.transform.RotoZoom(). > > > > My problem is that it doesn't rotate smoothly. > When it rotates, the > > corners of the image (just a plain white > background) look like they're > > hitting some barrier and making it move around. > Think of an empty box > > turned diagonally (so that it looks like a > diamond, with its open end > > facing you), and a cube in that box being turned > while it's resting in > > the bottom corner. I want it to rotate smoothly > around its center, it's > > it's not doing that. > > > > I'm guessing that it has something to do with me > not setting up a Rect > > right, but I'm not sure. Maybe this is a > limitation of Rotozoom/Rotate? > > > > Any advice would be greatly appreciated. And yes, > I'm a rank PyGame newbie. > > > > > > You might want to try pygsear: > http://www.nongnu.org/pygsear/ > > It has a RotatedImage class which takes care of > rotating > things for you. See the examples roti.py and > wings.py > for some use of rotated image sprites. > > > ???: Jp Calderone > ???: python-list at python.org > ??: Fri, 20 May 2005 20:45:00 GMT > ??: Re: buffer_info error > > On 20 May 2005 13:18:33 -0700, "ashtonn at gmail.com" > wrote: > >i am filling in a packet with source and > destination address and using > >the buffer_info call to pass on the address to an > underlying low level > >call. > > > >The src and dest are strings, but buffer_info > expects an array. How do > >i deal with this? > > What's the low-level call you're invoking? > > Jp > > > ???: roy at panix.com (Roy Smith) > ???: python-list at python.org > ??: 20 May 2005 16:50:39 -0400 > ??: Re: appending key-value pairs to a dict > > rbt wrote: > >I know how to setup an empty list and loop thru > something... appending > >to the list on each loop... how does this work with > dicts? > > > >I'm looping thru a list of files and I want to put > the file's name and > >its sha hash into a dict on each loop. > > You just assign values to keys. If the key doesn't > exist, it's > created automagically. You want something like > this: > > shaDict = {} > for fileName in fileNameList: > hash = generateShaHash (fileName) > shaDict[hash] = fileName > > > ???: Dave Brueck > ???: python-list at python.org > ??: Fri, 20 May 2005 15:07:05 -0600 > ??: Re: Is Python suitable for a huge, enterprise > size app? > > Paul Rubin wrote: > > Dave Brueck writes: > > > >>One thing from your experience that did resonate > with me is that, > >>except for ftplib and occasionally urllib (for > basic, one-shot GETs), > >>we don't use any of the standard library's > "protocol" modules - partly > >>because we had to implement our own HTTP libraries > for performance and > >>scalability reasons anyway, and partly because we > had trouble figuring > >>out e.g. all the ins and outs of > urllib/urllib2/httplib. > > > > > > What do you use for HTTPS? > > Hi Paul, > > m2crypto (plus some patches to make asynchronous SSL > do what we needed). > > > And did you use the Cookie module in your > > HTTP servers? You may have had problems without > even being aware of > > them (until recently if you used Cookie with its > default settings, any > > attacker could completely take over your server by > sending you > > carefully concoted cookies). > > Are you referring to the use of pickle for cookie > serialization? In any case, we > didn't use Cookie.py from the stdlib (on the > servers, nearly everything related > to URLs & HTTP was custom-built, with the exception > of urlparse, for the > aforemenioned reasons). > > -Dave > > > ???: John Abel > ??: python-list at python.org > ??: Fri, 20 May 2005 22:24:14 +0100 > ??: Re: Process monitoring > > gsteff wrote: > > >Hey, I'm working on a Python program that will > launch some other > >non-Python process using os.spawn (in the > os.P_NOWAIT mode) and then > >basically wait for it to finish (while doing some > other stuff in the > >interim). Normally, the new process will signal > that it's done by > >writing to a file, but I'd like to also find out if > the new process > >died unexpectedly. Anyone know any preferrable > ways to do this? > > > >Greg Steffensen > > > > > > > If you're using 2.4, have a look at the subprocess > module. > > J > > > -- > http://mail.python.org/mailman/listinfo/python-list I am a beginner,Can you introduce some book about python? I am a student of china _________________________________________________________ Do You Yahoo!? 150??MP3???????????? http://cn.rd.yahoo.com/mail_cn/tag/yisou/music/*http://music.yisou.com/ ??????????????????? http://cn.rd.yahoo.com/mail_cn/tag/yisou/image/*http://image.yisou.com 1G??1000??????????? http://cn.rd.yahoo.com/mail_cn/tag/1g/*http://cn.mail.yahoo.com/event/mail_1g/ From dalke at dalkescientific.com Thu May 12 22:30:39 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Fri, 13 May 2005 02:30:39 GMT Subject: Python features References: <1115536911.106882.166230@z14g2000cwz.googlegroups.com> Message-ID: Peter Dembinski wrote: > If you want to redirect me to Google, don't bother. IMO ninety percent > of writings found on WWW is just a garbage. Sturgeon's law: Ninety percent of everything is crap. Andrew dalke at dalkescientific.com From terjeja at gmail.com Wed May 4 06:49:14 2005 From: terjeja at gmail.com (Terje Johan Abrahamsen) Date: 4 May 2005 03:49:14 -0700 Subject: Regular Expression tools? In-Reply-To: References: Message-ID: <1115203754.733947.143240@z14g2000cwz.googlegroups.com> This is what you are looking for. http://kodos.sourceforge.net/ From tim.peters at gmail.com Fri May 27 01:22:37 2005 From: tim.peters at gmail.com (Tim Peters) Date: Fri, 27 May 2005 01:22:37 -0400 Subject: Python Challenge 10? In-Reply-To: <3fnnn7F8eo6gU1@individual.net> References: <3dg5isF6qe1nhU1@news.dfncis.de> <1f7befae05043000165448b8d@mail.gmail.com> <1f7befae05050313286dd4a254@mail.gmail.com> <874qdjc2lb.fsf@uwo.ca> <3fnnn7F8eo6gU1@individual.net> Message-ID: <1f7befae05052622222eecb0b3@mail.gmail.com> [Greg Ewing] > Can someone give me a hint for No. 10? My MindBlaster > card must be acting up -- I can't seem to tune into > the author's brain waves on this one. There are hints on the site; for level 10, http://www.pythonchallenge.com/forums/viewtopic.php?t=20 > I came up with what I thought was a perfectly good > solution, but apparently it's wrong. :-( The On-Line Encyclopedia of Integer Sequences should be better known -- it's an amazing resource: http://www.research.att.com/~njas/sequences/ It knows about this sequence, so don't use it unless you want the answer given to you. If it doesn't know about your sequence, "perfectly good" is debatable . From mcaloney at cs.queensu.ca Tue May 3 13:58:03 2005 From: mcaloney at cs.queensu.ca (Chris McAloney) Date: Tue, 3 May 2005 13:58:03 -0400 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: References: <3dg5isF6qe1nhU1@news.dfncis.de> <1f7befae05043000165448b8d@mail.gmail.com> Message-ID: Hi all, Okay, so I've been working on level seven for a LONG time now. I've decoded the first message to get the hint for the next level. Using the same tactics, then I decode the hint as well, but there are non-printable characters. I've tried stripping out those characters, quoting them to include in the URL and various anagrams of the printable characters, but nothing works. Does anybody have any suggestions? Thanks, -chris From hello at spamm.er Sun May 8 14:53:10 2005 From: hello at spamm.er (alex goldman) Date: Sun, 08 May 2005 11:53:10 -0700 Subject: Language documentation ( was Re: Computing Industry shams) References: <1115509201.680334.140840@f14g2000cwb.googlegroups.com> <874qdezh76.fsf@kafka.homenet> Message-ID: <1415322.AzhuxSBQdk@yahoo.com> vermicule wrote: > > What is so hard to understand ? > Should be perfectly clear even to a first year undergraduate. > > As for "greedy" even a minimal exposure to Djikstra's shortest path > algorithm would have made the concept intuitive. And from memory, > that is the sort of thing done in Computing 101 and in Data Structures > and Algorithms 101 > > It seems to me that you want the Python doc to be written for morons. > And that is not a valid complaint. He's right actually. If we understand the term "greedy" as it's used in graph search and optimization algorithms, Python's RE matching actually IS greedy. From k04jg02 at kzoo.edu Tue May 10 16:06:33 2005 From: k04jg02 at kzoo.edu (Joseph Garvin) Date: Tue, 10 May 2005 20:06:33 +0000 Subject: Python Args By Reference In-Reply-To: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> Message-ID: <42811449.20706@kzoo.edu> ncf wrote: >Hello all, I was wondering if there was any way to pass arguments >(integer and such) by reference (address of), rather than by value. > >Many thanks in advance. > >-Wes > > > All mutable types in python are passed by reference automatically. From theoryboy at my-deja.com Mon May 23 08:39:36 2005 From: theoryboy at my-deja.com (Peter Saffrey) Date: 23 May 2005 05:39:36 -0700 Subject: Multiple selections in Tix Hlist In-Reply-To: <1116416447.877154.160280@g47g2000cwa.googlegroups.com> References: <1116416447.877154.160280@g47g2000cwa.googlegroups.com> Message-ID: <1116851976.808682.55420@g44g2000cwa.googlegroups.com> To answer my own question: HList(selectmode="extended") does all the work for you. Peter From anuraguniyal at yahoo.com Fri May 20 06:50:11 2005 From: anuraguniyal at yahoo.com (anuraguniyal at yahoo.com) Date: 20 May 2005 03:50:11 -0700 Subject: string formatting quirk? Message-ID: <1116586211.346424.272320@g14g2000cwa.googlegroups.com> Hi, ''%([]) doesn't raise exception but ''%('') does Can anyone explain me why?? rgds Anurag From tlviewerSHRUB at yahooCHENEY.com Sat May 14 13:38:23 2005 From: tlviewerSHRUB at yahooCHENEY.com (tlviewer) Date: Sat, 14 May 2005 17:38:23 GMT Subject: pygame on win32, image.fromstring() References: Message-ID: "Greg Krohn" wrote in message news:AYhhe.379$X92.275 at newsread2.news.pas.earthlink.net... > tlviewer wrote: > > hello, > > hi > > > fp = open( "e:/batch/python/aceclub.bmp", "wt") > > wt? Should this be wb? > > > # gives: ValueError: String length does not equal format and resolution size > > img = gm.image.fromstring(str,(71,96),"P") > > The pygame docs say "P" is for 8bit pallete indices. When I look at the > properties of aceclub.bmp, Windows says it's Bit Depth is 4. I'm not sure if > they're talking about the same thing, though. If so, you could probably use PIL > to convert the depth. Yes, that was the trouble. Based on your suggestion, I now massage the image string with PIL, then fromstring() works! obj =Image.open(StringIO.StringIO(str)) #obj.convert( mode='P') # conversion is implicit, mode is 'P' already img = gm.image.fromstring(obj.tostring(),(71,96),"P") Next I'm going to load all 53 card resources into a list (array) of strings, then write it out, pickled. That should smooth out loading the game when I use 4-6 decks (Blackjack-21). thanks for getting to my post so quickly, tlviewer -- From rune.strand at gmail.com Mon May 9 21:30:49 2005 From: rune.strand at gmail.com (Rune Strand) Date: 9 May 2005 18:30:49 -0700 Subject: Unique Elements in a List In-Reply-To: References: <1115676903.432187.294910@z14g2000cwz.googlegroups.com> <1115678197.064079.28220@o13g2000cwo.googlegroups.com> <1115679662.521731.297510@f14g2000cwb.googlegroups.com> Message-ID: <1115688649.553568.136190@z14g2000cwz.googlegroups.com> You're right. I somehow missed the index part :-o. It's easy to fix though. From martin at v.loewis.de Wed May 11 01:47:17 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Wed, 11 May 2005 07:47:17 +0200 Subject: Trouble saving unicode text to file In-Reply-To: References: <1115500976.571232.76100@z14g2000cwz.googlegroups.com> Message-ID: <42819c66$0$29930$9b622d9e@news.freenet.de> Thomas Bellman wrote: > Fixed-with characters *do* have advantages, even in the external > representation. With fixed-with characters you don't have to > parse the entire file or stream in order to read the Nth character; > instead you can skip or seek to an octet position that can be > calculated directly from N. OTOH, encodings that are free of null bytes and ASCII compatible also have advantages. > And not the least, UTF-32 is *beautiful* compared to UTF-16. But ugly compared to UTF-8. Not only does it have the null byte and the ASCII incompatibility problem, but it also has the endianness problem. So for exchanging Unicode between systems, I can see no reason to use anything but UTF-8 (unless, of course, one end, or the protocol, already dictates a different encoding). Regards, Martin From mefjr75 at hotmail.com Mon May 2 08:01:31 2005 From: mefjr75 at hotmail.com (M.E.Farmer) Date: 2 May 2005 05:01:31 -0700 Subject: MRO problems with diamond inheritance? In-Reply-To: <1115024383.848366.64190@z14g2000cwz.googlegroups.com> References: <1114987828.055744.250090@z14g2000cwz.googlegroups.com> <1115004565.128735.58670@o13g2000cwo.googlegroups.com> <1115008163.017331.306290@o13g2000cwo.googlegroups.com> <1115024383.848366.64190@z14g2000cwz.googlegroups.com> Message-ID: <1115034897.225080.313990@l41g2000cwc.googlegroups.com> Michele Simionato wrote: > M.E. Farmer: > > >You would be surprised how many answers you can squeeze out of that > one > >URL. > >That whole page is worth a month of study( for me anyway ). > > One month only? You must be pretty smart, one could easily extract > a book from that page ;) No, I was being 'conservative'. I am not as smart as the fellow that wrote that MRO paper ;) Honestly, I have had that bookmarked for years... There are some deep conceps on that page and I have not had a 'use case' for most of them. I would gladly welcome the book, you gonna write it!? Something that covers ( with lots of 'real-life' examples ): classes ( I see a lot of questions on c.l.py about basic class use ) special methods and class customization ( putting classes to work ) metaclasses ( what they are and when you might need them ) inheritance ( covering all flavors subclassing,mixin,etc.. ) descriptors ( what are they and why you should care ) types ( creating new ones, subclassing old ones, etc... ) old style / newstyle gotchas for classes / metaclasses and maybe a few pages on decorators. It is all well and good to have advanced OO in the language, but it would be better if there was a 'reason' for it all. > >I am still trying to grasp the 'purpose' of classmethods. > > In my personal opinion classmethods and staticmethods could (and > possibly > should) be removed from the language; a part for that consideration, > the typical > use for classmethods is as object factories, to provide alternative > constructors. > > Michele Simionato Thank you, I had a feeling that it was just extra fluff. But I felt/feel that way about list comprehensions and decorators too ;) M.E.Farmer From lee_cullens at mac.com Mon May 2 02:23:45 2005 From: lee_cullens at mac.com (Lee Cullens) Date: Mon, 2 May 2005 02:23:45 -0400 Subject: MRO problems with diamond inheritance? Message-ID: Michele Simionato: >> M.E.Farmer: > >> Your answer lies somewhere in this page ;) >> http://www.python.org/2.2.2/de?scrintro.html > > Yes, when it refers to > > http://www.python.org/2.3/mro.html > > (section Bad Method Resolution Orders). > > In short, it is a feature, not a bug. I wanted to thank you Michele for for supplying this very informative link (and your work on the piece). I'm just getting into Python and have been "lurking" on this list. I have not yet gotten into a real world problem that involved nontrivial MRO, but recognized (as in intuitive suspicion) that such could be a concern in a complex class pattern design. One of those things that keeps nagging when addressing other issues. Now I can compartmentalize it and make better progress :~) Thanks again, Lee C From mfranklin1 at gatwick.westerngeco.slb.com Tue May 10 05:11:59 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue, 10 May 2005 10:11:59 +0100 Subject: Does TKinter Have A Grid ? In-Reply-To: References: Message-ID: Peter Moscatt wrote: > Does TKinter have a Grid widget ? > If not (as I assume), what is the alternative ? > > Pete > Pete, If by grid you mean Table widget or Spreadsheet type widget then no Tk does not have one (therefore nor does Tkinter) However as luck would have it there are a couple of extensions to Tk that provide a Table widget both Tk 'c' based and Tcl based. for more about this (and lots of other useful stuff!) http://tkinter.unpythonic.net/wiki/Widgets It mentions two Table widgets, Tktable and tablelist both have python (tkinter) wrappers Martin From ivanlan at pauahtun.org Wed May 11 16:28:15 2005 From: ivanlan at pauahtun.org (Ivan Van Laningham) Date: Wed, 11 May 2005 14:28:15 -0600 Subject: Python Documentation (should be better?) References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> Message-ID: <42826ADF.F0698EED@pauahtun.org> Hi All-- The Python docs are not ideal. I can never remember, for instance, where to find string methods (not methods in the string module, but methods with ''), but I can remember a tortured path to get me there (yes, I know, fix my brain; easier said than done). The module index is good, if what you're looking for is in a module. The tutorial is good. I can usually end up where I want to be by picking up my copy of _Python in a Nutshell_. 95% of the time I can find what I want in there or from there. The other 5% is too new, in the _Python Cookbook_ or in a third-party module/lib. Or it's what I'm trying to write;-) Metta, Ivan ---------------------------------------------- Ivan Van Laningham God N Locomotive Works http://www.andi-holmes.com/ http://www.foretec.com/python/workshops/1998-11/proceedings.html Army Signal Corps: Cu Chi, Class of '70 Author: Teach Yourself Python in 24 Hours From mchermside at ingdirect.com Mon May 23 13:06:15 2005 From: mchermside at ingdirect.com (Chermside, Michael) Date: Mon, 23 May 2005 13:06:15 -0400 Subject: line-by-line output from a subprocess Message-ID: <0CFFADBB825C6249A26FDF11C1772AE10132A058@ingdexj1.ingdirect.com> I am using the subprocess module to invoke a command-line utility and process the output. However, I would like to process the output line-by-line as it is generated rather than running the subprocess to completion and THEN processing the results. So, for instance, I'd like to write code like this: all_files = [] import subprocess subp = subprocess.Popen('dir', stdout=subprocess.PIPE) for line in subp.stdout: sys.stdout.print(line) all_files.append(line) ...and have it print the lines to stdout one-by-one until the entire list is collected. (Pretend that 'dir' is VERY slow.) The communicate() method in subprocess blocks until the subprocess has exited... I'm sure there is some good reason for this behavior. But how does one achieve what I am trying to do? (PS: this is on Windows... although I'd rather use an OS-agnostic solution if one exists.) -- Michael Chermside ***************************************************************************** This email may contain confidential or privileged information. If you believe you have received the message in error, please notify the sender and delete the message without copying or disclosing it. ***************************************************************************** From volker_grabsch at v.notjusthosting.com Sat May 14 06:09:14 2005 From: volker_grabsch at v.notjusthosting.com (Volker Grabsch) Date: Sat, 14 May 2005 12:09:14 +0200 Subject: Multiple "cmp"s chained one after another Message-ID: Hello! Ich just found a very nice 'pythonic' solution for an often appearing problem. I didn't find it documented anywhere, so I'm posting it here. If this isn't new in any way, I'd really like to get to know it. Example problem: I have some "datetime" objects and want to sort them, as here: birthdays = [d1,d2,d3,d4] birthdays.sort() However, I don't want to sort them the default way. These are birthdays, so only the month and day do matter, not the year. E.g.: 2003-01-01 should be smaller than 1984-05-01 So I have to write the comparison on my own, e.g. def cmp_birthdays(d1,d2): if d1.month > d2.month: return 1 if d1.month < d2.month: return -1 if d1.day > d2.day: return 1 if d1.day < d2.day: return -1 return 0 ... birthdays.sort(cmp_birthdays) This implementation of cmp_birthdays is very ugly. Image you want to chain more than 2 values in that "cmp_birthdays". I also want to use the builtin "cmp" function, not ">" and "<". After thinking some minutes about it, I found a very nice solution: I have some "cmp"s one aftter another. If one if them return 1 oder -1, it sould be returned. If it returns 0, the next "cmp" is used. In other words: I have a sequence of numbers, and want to get the first one that is not 0. (or return 0, if all numbers were 0) But this is exactly what the "or" operator does, due to short-circuit evaluation. In this example, that means: def cmp_bithdays(d1,d2): return cmp(d1.month,d2.month) or cmp(d1.day,d2.day) The generic pattern is: return cmp(...) or cmp (...) or cmp(...) or ... I'm not sure whether this pattern is already a "common recipe", but I found it to be a very nice idea. :-) Any opinions? Greets, Volker -- Volker Grabsch ---<<(())>>--- \frac{\left|\vartheta_0\times\{\ell,\kappa\in\Re\}\right|}{\sqrt [G]{-\Gamma(\alpha)\cdot\mathcal{B}^{\left[\oint\!c_\hbar\right]}}} From enleverlesO.OmcO at OmclaveauO.com Sun May 22 17:39:59 2005 From: enleverlesO.OmcO at OmclaveauO.com (Do Re Mi chel La Si Do) Date: Sun, 22 May 2005 23:39:59 +0200 Subject: Self-modifying Code References: <1116522647.227661.99290@g43g2000cwa.googlegroups.com> <428cedeb$0$25015$8fcfb975@news.wanadoo.fr> Message-ID: <4290fc6e$0$3129$8fcfb975@news.wanadoo.fr> Hi ! I often use the auto-modification of code, to allow the users to adapt software to the evolution of their needs. When this technique is controlled, and framed well, it presents only few problems. AMHA, to speak about danger, it is the result of a lack of practice and tests. It is a little the same debate as: dynamic language versus static language. @-salutations Michel Claveau From rkern at ucsd.edu Sat May 14 22:19:08 2005 From: rkern at ucsd.edu (Robert Kern) Date: Sat, 14 May 2005 19:19:08 -0700 Subject: Modifying a built-in function for logging purposes In-Reply-To: <1116108841.429602.257380@o13g2000cwo.googlegroups.com> References: <1116098593.970438.219860@g47g2000cwa.googlegroups.com> <1116108841.429602.257380@o13g2000cwo.googlegroups.com> Message-ID: qwweeeit at yahoo.it wrote: > Hi Greg, > thank for your replay, but I didn't succeed in any way. You must > consider however that I'm not a Python "expert"... > IMHO, it must be a script that change part of the interpreter, and > substitute a new module (py) in the place of the standard one (py or > pyc). The standard module must be saved in order to be able to undo the > changes and go back to the normal behaviour. > The problem is that I don't know if the built-in functions like open > (or file) are written in Python or in C and, besides that, if they can > be modified. Short answer: if you don't know stuff like this, then you probably shouldn't mess around with the builtins in production code. Depending on your operating system, there are probably programs that let you list all of the files that have been opened on your system. For example, on OS X, lsof(1) does the trick. > Other solutions which modify the source to be logged, are not > solutions, because it is far simpler to introduce here and there print > statements... -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From gtog at _no___spam_myrealbox.com Thu May 12 10:58:16 2005 From: gtog at _no___spam_myrealbox.com (George) Date: Thu, 12 May 2005 16:58:16 +0200 Subject: Launch file in Notepad In-Reply-To: <1186phdog83fmf6@corp.supernews.com> References: <42835db6$0$1334$5fc3050@dreader2.news.tiscali.nl> <1186phdog83fmf6@corp.supernews.com> Message-ID: <42836fc5$0$1366$5fc3050@dreader2.news.tiscali.nl> Grant Edwards wrote: > On 2005-05-12, Brian van den Broek wrote: > Does Python really look at the string and mess with the slash? > I don't think it needs to, since the Windows system calls have > always accepted forward slashses, haven't they? It did, but now not anymore. I don't understand why, maybe I've changed something in the code. See my other post. George From andymac at bullseye.apana.org.au Wed May 25 06:43:39 2005 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Wed, 25 May 2005 21:43:39 +1100 Subject: IRIX MipsPro compiler chokes on Python.h In-Reply-To: <1116933601.457261@blaat.sara.nl> References: <1116933601.457261@blaat.sara.nl> Message-ID: <429456DB.6000105@bullseye.apana.org.au> Bram Stolk wrote: > Hi there, > > I just built and installed Python-2.4.1 on my Irix machine. > My compiler, the MipsPro compiler, chokes on the Python.h include file, > as demonstrated here: > > > $ CC -v > MIPSpro Compilers: Version 7.41 > $ python -V > Python 2.4.1 > $ cat l.cxx > #include > > int main() > { > return 0; > } > > $ CC -I $HOME/include/python2.4 l.cxx > cc-1311 CC: ERROR File = /usr/include/sys/time.h, Line = 186 > The indicated linkage specification is incompatible with previous "select" > (declared at line 479 of "/usr/include/unistd.h"). > > static int select( > ^ > > 1 error detected in the compilation of "l.cxx". > > Has anyone experienced the same? > How do I solve this? My suspicion would be directed to a #define that is incorrect, as the snippet above suggests that select() appears in two system headers (/usr/include/sys/time.h & /usr/include/unistd.h). That is ./configure got something wrong and may need to be modified for your platform to sort this out properly, but modifying pyconfig.h to correct the incorrect definitions should get you out of trouble. ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From nitrogenycs at web.de Thu May 12 04:51:01 2005 From: nitrogenycs at web.de (nitrogenycs at web.de) Date: 12 May 2005 01:51:01 -0700 Subject: Proxy Design Advice Needed In-Reply-To: References: <1115848303.630570.147840@o13g2000cwo.googlegroups.com> Message-ID: <1115887861.163456.77930@g49g2000cwa.googlegroups.com> Thanks for the hint so far! The recipe shown there does not exactly what I want though, it doesn't do the type() stuff and it hooks up every _ variable which could get crucial if the wrapped object's methods uses them too. So I think my question boils down to how I can make type(Proxy) return type(WrappedObject)? Any hints? -Matthias From philippe at philippecmartin.com Wed May 4 14:34:20 2005 From: philippe at philippecmartin.com (Philippe C. Martin) Date: Wed, 04 May 2005 18:34:20 GMT Subject: python+windows/linux -> write stdout text to always on top text? References: <1115064842.454916.305970@f14g2000cwb.googlegroups.com> Message-ID: I understand you wish to reroute stdout to some object than can write to a window - correct ? If so, this is what I do with tkinter .... class SC_Log_Stdout: #******************************************************************************* def __init__(self, p_log_text): self.__m_log_text = p_log_text #graphics object - would be your game engine I guess #******************************************************************************* def write(self,p_string): try: except: pass . . . . . . sys.stdout = SC_Log_Stdout(.....) #reroute stdout . . . #launch your game flamesrock wrote: > Hi, > > I'm curious if theres a way in python to write stdout text to the > screen (ie top right) the way they do in some FPS games, so that its > always on top, in an invisible window of some set dimensions. No matter > what program is on top. > > Is there a way to make it cross platform? > > I've looked but nothing seems to turn up on the subject. > > -thanks in advance. From rrr at ronadam.com Wed May 18 15:35:24 2005 From: rrr at ronadam.com (Ron Adam) Date: Wed, 18 May 2005 19:35:24 GMT Subject: Sorting x lists based on one list ... maybe an example would make sense: In-Reply-To: <_Nnie.1050$5Z1.166@newssvr30.news.prodigy.com> References: <_Nnie.1050$5Z1.166@newssvr30.news.prodigy.com> Message-ID: <0OMie.27565$VH2.6316@tornado.tampabay.rr.com> Philippe C. Martin wrote: >>Another way would be to merge the three lists into one of 3-tuples, sort, >>and unmerge, similarly to the DSU pattern -- which raises the question: >>why are you using three lists in the first place? > > > :-) Thanks, the lists will evolve and are also stored in 'csv' format in > external files at one point. I cannot use dictionaries because I need to > control the sorting (hash). > > In this specific case, list 1 represents students with their information, > list 2 represents assignments with information such as weight, term, max > grade ... and list 3 the actual grades. > > Regards, > > Philippe Hi Philippe, As Peter suggested this sounds like a database. Especially if it will evolve and grow to the point where it will not all fit in memory. Also data bases already have a lot of ability to query, and generate sorted reports built into them. This is a fairly normal task for a relational data base where you have a transaction list, (grades), that are connected to other lists, (students, and assignments). This saves a lot of space by not duplicating the student information and assignment information for each grade given. It also makes updating student information easier because it only needs to be updated once, and not changed everwhere it's referenced. If your lists are not going to grow larger than what will fit in memory, you can use dictionaries and lists. Loosely like the following... - Read student info from cvs file into dictionary using student_id or number as a key. Names can be used if they are unique. The content of each student file will be a list, with None for missing items. students[student_id] = (name, address, phone, etc....) - Read assignments into dictionary using an assignment_no as key. assignments[assignment_no] = (a_name, description, etc...) - Create a grades list which will contain grade tuples: [(date,student_id,assignment_no,grade), ... more grades ... ] You can sort your grades list however you want. If you want to sort by student name instead of student_id, you would use: # Sort grades list by student name. grades.sort(lambda x,y: cmp(students[x[1]][0], students[y[1]][0])) Assuming the name is in the first field in the student dictionary-value tuple. There are probably other ways to do this that are more readable or faster. The grade list could also be filtered, so if you want to get all the grades for a specific student, or all the grades for a particular assignment you can just loop through grades list and print what you want. An alternative query would be to get all the students who have not completed an assignment: Get a list of all the student who have a grade for the assignment, then use that to get a list from the student dictionary, who are not in the students_completed_assignment list. Anyway, just trying to give you some ideas. Cheers, _Ron From rrr at ronadam.com Sun May 15 11:12:12 2005 From: rrr at ronadam.com (Ron Adam) Date: Sun, 15 May 2005 11:12:12 -0400 Subject: Exception question In-Reply-To: References: Message-ID: <428766CC.30503@ronadam.com> Steven Bethard wrote: > Ron Adam wrote: > >>Do exceptions that take place get stored in a stack or list someplace? > > [snip] > >>I know I can catch the error and store it myself with, >> >> except Exception, exc: >> >>or possibly, >> >> errlist = [] >> errlist.append(sys.exc_info()) >> >>But what I want to know is does the interpreter do that in any way? And >>if so, can I access it? > > > No, but there's been some recent talk about having it do so: > > http://mail.python.org/pipermail/python-dev/2005-May/053672.html > > If that happens though, it's not likely to show up before Python 3.0. > Too backwards incompatible to do now. It also seems that the exact > semantics haven't yet been agreed upon. > > STeVe Thanks Steve, I had actually skimmed over those, but wasn't thinking of this at the time. I reread them. And it clears up a few things. I had read somewhere that exception objects were global, but that wasn't correct, after testing it, they appear to be part of the local frame. So once a function exits, any exceptions objects that happened inside the function are no longer retrievable. And checking exception ID's to see if any new exceptions occurred doesn't work either, as the numbers get reused too frequently in a short period. Conclusion: Exceptions need to be logged or handled as they occur. Cheers, _Ron From martin at v.loewis.de Sat May 7 12:40:08 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Sat, 07 May 2005 18:40:08 +0200 Subject: Q: The `print' statement over Unicode In-Reply-To: References: <427cc8b2$0$26179$9b622d9e@news.freenet.de> Message-ID: <427CEF68.1040607@v.loewis.de> Fran?ois Pinard wrote: > My contributions are not that welcome. If they were, the core team > would not try forcing me into using robots and bug trackers! :-) Ok, then we need to wait for somebody else to contribute a documentation patch. > Thanks. Your kind explanation, above, should make it, as is, somewhere > in the documentation But how will that happen? Unless somebody contributes a documentation patch, the documentation will not change magically! Regards, Martin From doodle4 at gmail.com Mon May 16 15:56:37 2005 From: doodle4 at gmail.com (ashtonn@gmail.com) Date: 16 May 2005 12:56:37 -0700 Subject: optparse global References: <1116264761.204065.15980@g14g2000cwa.googlegroups.com> Message-ID: <1116273397.597407.256760@g49g2000cwa.googlegroups.com> This does not seem to work. I still get the default value 5007 when i run $python txd.py - p5006 $python testme.py ***txd.py*** global options parser = OptionParser() parser.add_option("-p", "--port", dest="port", default=5007, type="int", help="port to connect to for remote interpreter") options, args = parser.parse_args() **testme.py** from txd import options print options.port -Ashton From ojokimu at yahoo.co.uk Sun May 1 22:50:47 2005 From: ojokimu at yahoo.co.uk (John Ridley) Date: Mon, 2 May 2005 03:50:47 +0100 (BST) Subject: gtk/qt scintilla help ! Message-ID: <20050502025047.33234.qmail@web26810.mail.ukl.yahoo.com> fabien wrote on Sun, 01 May 2005 05:40:05 -0700: > Hi, Hello Fabien > I am writing a POV-RAY editor with Python using > either QT or GTK as GUI 'wrapper'. ( I am still trying both ) > > [snip] > > I have also downloaded qscintilla-1.62-gpl-1.5.1. > As for GTK, I also found the LexPOV.cpp file, with > no POV keywords in it and with no POV keywords in > any of the file in the package. > The compilation builds then move the library > libqscintilla.so to /usr/lib/qt3/lib. > > How do I link the newly built library to the folling qt script : > > [snip] QScintilla is a port to Qt of the Scintilla editor control, and PyQt provides the python bindings for it. Scintilla has several dozen lexers (including one for POV), and QScintilla currently provides class wrappers for a small selection of them - but not POV, as you will see from the documentation: http://www.river-bank.demon.co.uk/docs/qscintilla/hierarchy.html Given this, there are two routes you can go down. You could ask the developer of QScintilla to provide support for POV by making a request via the mailing list: http://www.riverbankcomputing.co.uk/pyqt/mailinglist.php Or you could write your own POV lexer class in python using the existing QScintilla APIs. This is not particularly difficult, but it does take some working out. As you already know, a list of POV keywords is required. You will then need to look at the source (LexPOV.cpp and SciLexer.h) to see how the keywords are used and how the lexical states tie up with the SCE_POV enum. QScintilla's lexer classes are mainly wrappers around this information, so once you've worked it out, writing a python class based on QextScintillaLexer is fairly straightforward: >>> class LexerPOV(QextScintillaLexer): >>> def __init__(self, parent, name): >>> QextScintillaLexer.__init__(self, parent, name) >>> def lexer(self): >>> return "pov" >>> def color(self, style): >>> # styles map to (SCE_POV enum) >>> # return your own QColor >>> # or return the base class default >>> return QextScintillaLexer.color(self, style) >>> def keywords(self, set): >>> # if set == 0: >>> # return >>> # elif ... >>> return 0 >>> def description(self, style): >>> # if style == 0: >>> # return self.tr("Default") >>> # elif ... >>> return QString.null Of course, this is a minimal lexer class - it is possible to be a lot more sophisticated than what is suggested here. John Ridley Send instant messages to your online friends http://uk.messenger.yahoo.com From timr at probo.com Fri May 27 00:08:27 2005 From: timr at probo.com (Tim Roberts) Date: Thu, 26 May 2005 21:08:27 -0700 Subject: Trouble with regexes References: Message-ID: Fernando Rodriguez wrote: > >I'm trying to write a regex that matches a \r char if and only if it >is not followed by a \n (I want to translate text files from unix >newlines to windows\dos). > >I tried this, but it doesn't work: >p = re.compile(r'(\r)[^\n]', re.IGNORECASE) > >it still matches a string such as r'\r\n' Hint: the string r'\r\n' contains four characters. It contains neither carriage return nor newline. Bigger hint: the string '\r\n' contains two characters. -- - Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kbk at shore.net Wed May 18 00:12:36 2005 From: kbk at shore.net (Kurt B. Kaiser) Date: Wed, 18 May 2005 00:12:36 -0400 (EDT) Subject: Weekly Python Patch/Bug Summary Message-ID: <200505180412.j4I4CaB1028858@bayview.thirdcreek.com> Patch / Bug Summary ___________________ Patches : 339 open ( +7) / 2838 closed ( +4) / 3177 total (+11) Bugs : 938 open (+11) / 4962 closed ( +3) / 5900 total (+14) RFE : 187 open ( +1) / 157 closed ( +0) / 344 total ( +1) New / Reopened Patches ______________________ Restore GC support to set objects (2005-05-11) http://python.org/sf/1200018 opened by Barry A. Warsaw idlelib patch (2005-05-11) http://python.org/sf/1200038 opened by sowjanya Small optimization for PyDict_Merge() (2005-05-11) CLOSED http://python.org/sf/1200051 opened by Barry A. Warsaw buffer overflow in _cursesmodule.c (2005-05-11) http://python.org/sf/1200134 opened by Jan Michael H?lsbergen patch IDLE to allow running anonymous code in editor window (2005-05-13) http://python.org/sf/1201522 opened by Jeff Shute allow running multiple instances of IDLE (2005-05-13) http://python.org/sf/1201569 opened by Jeff Shute httplib mentions getreply instead of getresponse (2005-05-16) http://python.org/sf/1203094 opened by Robert Brewer workaround deprecated ostat structure in (2005-05-17) http://python.org/sf/1203329 opened by J. J. Snitow Patch for [ 1163563 ] Sub threads execute in restricted mode (2005-05-17) http://python.org/sf/1203393 opened by anothermax Allow larger programs to be frozen under Win32 (2005-05-17) http://python.org/sf/1203650 opened by Gottfried Gan?auge Patches Closed ______________ Small optimization for PyDict_Merge() (2005-05-11) http://python.org/sf/1200051 closed by rhettinger better datetime support for xmlrpclib (2005-02-10) http://python.org/sf/1120353 closed by montanaro Add O_SHLOCK/O_EXLOCK to posix (2005-01-17) http://python.org/sf/1103951 closed by montanaro Fix _tryorder in webbrowser.py (2005-03-20) http://python.org/sf/1166780 closed by rodsenra New / Reopened Bugs ___________________ installation problem with python 2.4.1 on Win2k system (2005-05-11) http://python.org/sf/1199808 opened by mmkobayashi Python 2.4.1 Installer ended prematurely (2005-05-11) http://python.org/sf/1199947 opened by Wai Yip Tung time module ignores timezone changes (2005-05-09) CLOSED http://python.org/sf/1198275 reopened by bcannon Windows msi installer fails on virtual drives (2005-05-11) http://python.org/sf/1200287 opened by bartgrantham SyntaxError raised on win32 for correct files (2005-05-12) http://python.org/sf/1200686 opened by Federico Di Gregorio Wrong word on "raise" page (2005-05-13) CLOSED http://python.org/sf/1201438 opened by Erik Rose Problem with recursion in dict (crash with core dump) (2005-05-13) http://python.org/sf/1201456 opened by Vladimir Yu. Stepanov suspected cPickle memory leak (2005-05-13) http://python.org/sf/1201461 opened by Alan Glossary listing bug (2005-05-14) CLOSED http://python.org/sf/1201807 opened by George Yoshida mimetypes.py does not find mime.types on Mac OS X (2005-05-14) http://python.org/sf/1202018 opened by Stefan H. Holek Description of string.lstrip() needs improvement (2005-05-15) http://python.org/sf/1202395 opened by Roy Smith httplib docs mentioning HTTPConnection.getreply (2005-05-15) http://python.org/sf/1202475 opened by Georg Brandl RE parser too loose with {m,n} construct (2005-05-15) http://python.org/sf/1202493 opened by Skip Montanaro a bunch of infinite C recursions (2005-05-15) http://python.org/sf/1202533 opened by Armin Rigo Problem with abs function (2005-05-16) http://python.org/sf/1202946 opened by ric-b Bugs Closed ___________ time module ignores timezone changes (2005-05-09) http://python.org/sf/1198275 closed by bcannon SystemError: error return without exception set (2005-05-05) http://python.org/sf/1195984 closed by nbajpai Wrong word on "raise" page (2005-05-13) http://python.org/sf/1201438 closed by rhettinger Glossary listing bug (2005-05-14) http://python.org/sf/1201807 closed by rhettinger New / Reopened RFE __________________ enhancing os.chown functionality (2005-05-12) http://python.org/sf/1200804 opened by gyrof From fredrik at pythonware.com Tue May 17 02:38:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 17 May 2005 08:38:14 +0200 Subject: ElemenTree and namespaces References: <1116272957.323777.79090@g44g2000cwa.googlegroups.com> Message-ID: oren.tirosh at gmail.com wrote: > In theory, namespace prefixes are entirely arbitrary and only serve as > a temporary link to the namespace URI. In practice, people tend to get > emotionally attached to their favorite prefixes. XPath also breaks this > theory because it refers to prefixes rather than URIs. if your XPath processor requires you to use the same namespace prefixes in the XPath expression as you're using in the document, that processor is broken. (XPath processors that can only work on expressions embedded in XML documents may be an exception to that rule; they can get the prefix/URI mapping from the execution context) From cam.ac.uk at mh391.invalid Sun May 1 19:26:18 2005 From: cam.ac.uk at mh391.invalid (Michael Hoffman) Date: Mon, 02 May 2005 00:26:18 +0100 Subject: Best way to create temporary file? In-Reply-To: <246a4e07.0505010034.28055fd@posting.google.com> References: <246a4e07.0504290311.7d692401@posting.google.com> <246a4e07.0505010034.28055fd@posting.google.com> Message-ID: Frank Millman wrote: > It is certainly possible to store the entire report in memory, using a > two-dimensional list (page/line), but if a report runs into hundreds of > pages, I am concerned at the amount of memory this would require. > Perhaps I am being old-fashioned - with todays memory of at least 64k, > it would probably fit without a problem - but I would prefer to write > the pages away and read them back when needed. Modern operating systems have a technique for dealing with this. It is called virtual memory. You are only using up more memory, CPU, and disk speed by using temporary files unnecessarily. -- Michael Hoffman From ccurvey at gmail.com Wed May 11 09:37:33 2005 From: ccurvey at gmail.com (Chris Curvey) Date: 11 May 2005 06:37:33 -0700 Subject: FutureWarning in win32com? Message-ID: <1115818653.882851.316090@z14g2000cwz.googlegroups.com> Hi all, When trying to automate IE thru win32com (using PAMIE), I'm getting this message out C:\Program Files\Plone 2\Python\lib\site-packages\win32com\client\dynamic.py:463 : FutureWarning: %u/%o/%x/%X of negative int will return a signed string in Pyth on 2.4 and up debug_attr_print("Getting property Id 0x%x from OLE object" % retEntry.dispid) The underlying code works fine (the browser ends up where it's supposed to), but this warning seems to be actually sent to stdout or stderr -- it's not a raised exception that I can catch. How can I suppress this message? From xah at xahlee.org Thu May 12 22:32:56 2005 From: xah at xahlee.org (Xah Lee) Date: 12 May 2005 19:32:56 -0700 Subject: [perl-python] Range function Message-ID: <1115951576.138445.51080@z14g2000cwz.googlegroups.com> Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah xah at xahlee.org ? http://xahlee.org/ -------------------------- Range Range($iMax) generates the list [1, 2, ... , $iMax]. Range($iMin, $iMax) generates the list [$iMin, ... , $iMax]. Range($iMin, $iMax, $iStep) uses increment $iStep, with the last element in the result being less or equal to $iMax. $iStep cannot be 0. If $iStep is negative, then the role of $iMin and $iMax are reversed. If Range fails, 0 is returned. Example: Range(5); # returns [1,2,3,4,5] Range(5,10); # returns [5,6,7,8,9,10] Range( 5, 7, 0.3); # returns [5, 5.3, 5.6, 5.9, 6.2, 6.5, 6.8] Range( 5, -4, -2); # returns [5,3,1,-1,-3] From jjl at pobox.com Sun May 29 18:12:05 2005 From: jjl at pobox.com (John J. Lee) Date: 29 May 2005 22:12:05 +0000 Subject: Help with choice of suitable Architecture References: <1117299643.380598.5540@g47g2000cwa.googlegroups.com> Message-ID: <87mzqdr8ay.fsf@pobox.com> "Rob Cowie" writes: > Thanks for the comments. > > I kind of get the impression that CGI is the way to go for this > application, and that I should forget about adding client-side > scripting based functionality for the sake of accessibility - which I > understand and kind of agree with. I don't see any intrinsic reason for client-side scripting, or JavaScript in particular, messing up accessibility. One can fall back to vanilla HTML+CSS for people who don't have JS turned on. I don't say it's easy, though. I don't know what you intend the content of your Masters to be, but this seems like an interesting and useful thing to work on, and a fashionable topic to boot: write your app as one piece of code that can run happily with JavaScript (and taking advantage of AJAX) or without (without resort to if statements in your application code, obviously ;-). Personally, I'm anticipating the day I can change an import statement in my Qt GUI applications and run them on the web (== JavaScript + HTML + CSS + HTTP) <0.5 wink>. In the mean time, I recommend Quixote (yes, you can run it on CGI). Lots of people seem to like Twisted, too (nevow has some AJAX support), though perhaps Twisted and CGI don't sensibly go together (and I certainly understand the desire to avoid long-running server processes). If you're interested in new stuff, certainly take a look at Kamaelia (after you've oriented yourself a bit by writing a tiny web app or two!). > I'll look into the problem of concurrent access to an XML file. I may > get back to the group about this! >From my own unpleasant experience, CGI + locking = pain. At least if you don't have full control of the server (even then, do yourself a favour, use a DBMS, and let somebody else worry about some of the hard parts of locking, transactions &c.). Why not keep the XML in a database blob, if somebody insists on an XML-based implementation? Or, more sane, store your data in the DB, then just write out XML, which presumably solves the *real* problem for which XML is the solution (interoperability)? have-the-appropriate-amount-of-fun-ly y'rs, John From hello at spamm.er Tue May 24 01:34:46 2005 From: hello at spamm.er (alex goldman) Date: Mon, 23 May 2005 22:34:46 -0700 Subject: What are OOP's Jargons and Complexities? References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> Message-ID: <1779523.9sBn8HKUcY@yahoo.com> John W. Kennedy wrote: > Strong > typing has been a feature of mainstream programming languages since the > late 1950's. Is Fortran a strongly typed language? I don't think so. Strong typing has been invented in the 70's, if I'm not mistaken, when ML was invented, but strong typing has never been mainstream. From jmccall at houston.rr.com Fri May 20 02:45:18 2005 From: jmccall at houston.rr.com (J. W. McCall) Date: Fri, 20 May 2005 06:45:18 GMT Subject: PyGame and Rotozoom (Sorry if OT) Message-ID: <2Ifje.100148$hu5.2601@tornado.texas.rr.com> I'm not sure if this is off-topic, since it doesn't deal with Python itself, but here goes: I'm messing around with writing a simple "game" where the player (a crudely drawn smiley face) moves by rotating and moving back or forward (think Resident Evil, but from an always-above view). After much hacking, I have it working where left and right rotate the player sprite and up always moves the sprite whichever direction it's facing, while down is reverse. I'm using pygame.transform.RotoZoom(). My problem is that it doesn't rotate smoothly. When it rotates, the corners of the image (just a plain white background) look like they're hitting some barrier and making it move around. Think of an empty box turned diagonally (so that it looks like a diamond, with its open end facing you), and a cube in that box being turned while it's resting in the bottom corner. I want it to rotate smoothly around its center, it's it's not doing that. I'm guessing that it has something to do with me not setting up a Rect right, but I'm not sure. Maybe this is a limitation of Rotozoom/Rotate? Any advice would be greatly appreciated. And yes, I'm a rank PyGame newbie. Thanks, J. W. McCall From jstroud at mbi.ucla.edu Sun May 8 16:39:47 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Sun, 8 May 2005 13:39:47 -0700 Subject: Language documentation ( was Re: Computing Industry shams) In-Reply-To: <1415322.AzhuxSBQdk@yahoo.com> References: <1115509201.680334.140840@f14g2000cwb.googlegroups.com> <874qdezh76.fsf@kafka.homenet> <1415322.AzhuxSBQdk@yahoo.com> Message-ID: <200505081339.47460.jstroud@mbi.ucla.edu> http://www.developer.com/lang/article.php/10924_3330231_3 On Sunday 08 May 2005 11:53 am, alex goldman wrote: > He's right actually. If we understand the term "greedy" as it's used in > graph search and optimization algorithms, Python's RE matching actually IS > greedy. -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From peter at engcorp.com Thu May 26 23:06:27 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 26 May 2005 23:06:27 -0400 Subject: Case Sensitive, Multiline Comments In-Reply-To: <1117154013.092736.298310@g14g2000cwa.googlegroups.com> References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> <8664x5y92g.fsf@guru.mired.org> <429654DA.9050903@lexicon.net> <1117154013.092736.298310@g14g2000cwa.googlegroups.com> Message-ID: <4qCdnfQ-paWWEgvfRVn-og@powergate.ca> Elliot Temple wrote: > Thanks for the link on case sensitivity. I'm curious about the person > who found case sensitivity useful though: what is it useful for? I wasn't that person, but I do find case sensitivity very useful. Mainly it's useful in that it allows me not to spend any time at all worrying that I just might have a collision in my naming of various entities that are conceptually in different spaces but which -- due to the nature of the language I'm using -- happen to co-exist in the same namespace. For example, although this contrived example suggests poor imagination in picking names, I think it demonstrates the point. INVENTORYCODE = 5 # in effect one item in a constant "enum" class InventoryCode: '''Might represent something to do with inventory codes... duh''' def myfunc(): inventoryCode = someOtherFunction() In other words, I have a CONSTANT, a Class, and an instance, and if the set of code involved were large enough, these three things might be defined far enough apart that the potential collision wouldn't be as obvious as it is here. More to the point, there might not be any relationship between these things in my mind as I'm programming, and having to deal with an error message from a compiler or, worse, a run time error resulting from this collision would really annoy me. Case sensitivity might not be something we should be deliberately exercising on a daily basis, but there's no good reason (in my opinion) for not having it available to allow one freedom in naming (assuming one is sane and uses consistent convention for the case of things like constants, classes, and instances) without the worry of pesky collisions. -Peter From gandalf at geochemsource.com Wed May 18 09:18:01 2005 From: gandalf at geochemsource.com (Laszlo Zsolt Nagy) Date: Wed, 18 May 2005 15:18:01 +0200 Subject: super() and automatic method combination In-Reply-To: <7xvf5gra9z.fsf_-_@ruckus.brouhaha.com> References: <7xvf5gra9z.fsf_-_@ruckus.brouhaha.com> Message-ID: <428B4089.8070904@geochemsource.com> > >I have the impression that this is supposed to call the f method >in both A and B, so it should print > > Not really true. The first parameter of 'super' should be a type, not an instance. > A > B > C >or maybe > B > A > C >depending on the resolution order. However, it only calls A.f and not B.f. > >I also notice that if I say > > > class B(object): > def f(self): > super(B,self).f() > print 'b' > >then > test(B) >raises an exception since B has no superclass with an f method. > Correct. When you use super(B,self) it accesses the current instance as the class B. If it has no method named 'f' then this will end up in an exception. >That doesn't seem like such a good thing necessarily. > > But yes, it is. When you try to call a nonexistent method, it should raise an exception. >Anyway, is there a preferred way of writing this example so that C.f >automatically calls both A.f and B.f? > > I do not know a preferred way. However, I made this example for you, I hope it helps. class CallSupersMixin(object): def callsupers(self,fname,*args,**kwargs): l = self.__class__.__bases__ for cls in l: if hasattr(cls,fname): getattr(cls,fname)(self,*args,**kwargs) elif cls == CallSupersMixin: pass else: raise AttributeError("Base class %s does not have a method named %s " % ( str(cls),fname ) ) class A(object): def f(self): print 'A.f called' class B(object): def f(self): print 'B.f called' class AB(A,B,CallSupersMixin): def f(self,*args,**kwargs): self.callsupers('f',*args,**kwargs) ab = AB() ab.f() Of course you can remove the "raise AttributeError" part. Then it will call only the classes that have the given method. I know it is not a very good example but you can go from here. Best, Laci 2.0 -- _________________________________________________________________ Laszlo Nagy web: http://designasign.biz IT Consultant mail: gandalf at geochemsource.com Python forever! From aa at hanmail.net Mon May 30 00:17:14 2005 From: aa at hanmail.net (´º½º66) Date: Mon, 30 May 2005 13:17:14 +0900 Subject: test sorrry Message-ID: aaa From jason.mobarak at gmail.com Mon May 9 03:46:44 2005 From: jason.mobarak at gmail.com (Jason Mobarak) Date: 9 May 2005 00:46:44 -0700 Subject: Python Pseudo-Switch References: <1115527801.791201.310760@g14g2000cwa.googlegroups.com> Message-ID: <1115624804.448449.91830@g14g2000cwa.googlegroups.com> # -*- python -*- import sys def switchFor (target): sw = '__switch_table__' # please pretend the frame hack is not here, # it happens to work for classes and messing with # frame stack in a try/except is probably okay try: raise Exception() except: defs = sys.exc_info()[2].tb_frame.f_back.f_locals if sw not in defs: defs[sw] = {} table = defs[sw] def _(meth): table[target] = meth return meth return _ class SwitchMixin (object): def __init__ (self): self.__switch_table__ = self.__switch_table__.copy() def switchOn (self, target, *args, **kw): return self.__switch_table__[target](self, *args, **kw) if __name__ == '__main__': class SwitchTest(SwitchMixin): @switchFor("foo") def switch (self, arg): print arg * 3 @switchFor("bar") def switch (self, arg): print "__%s__" % (arg,) @switchFor("baz") def switch (self, arg): print arg + ''.join(reversed(arg)) st = SwitchTest() st.switchOn("foo", "oof") st.switchOn("bar", "rab") st.switchOn("baz", "zab") From pinard at iro.umontreal.ca Tue May 10 09:21:48 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Tue, 10 May 2005 09:21:48 -0400 Subject: pyvm -- faster python In-Reply-To: <42807E22.5050100@ceid.upatras.gr> References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <42807E22.5050100@ceid.upatras.gr> Message-ID: <20050510132148.GB20928@alcyon.progiciels-bpi.ca> [Stelios Xanthakis] > I'm afraid this may end up dead before unborn too. So it depends what > people want. If nobody cares, [...] People might not care so much about what could be done about your project, unless you give them proper and complete means for evaluating the state of affairs. Your project is very likely to die if you keep your sources closed, and yourself loose interest in the project. Opening your sources is no guarantee either that the community will adopt your project. But this might give your project a better chance. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From remi at cherrypy.org Wed May 4 11:12:39 2005 From: remi at cherrypy.org (remi at cherrypy.org) Date: 4 May 2005 08:12:39 -0700 Subject: ANN: CherryPy-2.0-final released Message-ID: <1115219559.776437.200250@o13g2000cwo.googlegroups.com> Hello everyone, I am happy to announce the first stable release of CherryPy-2. CherryPy-2 is a pythonic, object-oriented web development framework. CherryPy-2 is a redesign of CherryPy-1 (the unpythonic features have been removed): no more compilation step, pure python source code (no more "CherryClass"). Here is a sample Hello, World in CherryPy-2: # from cherrypy import cpg # class HelloWorld: # @cpg.expose # def index(self): # return "Hello world!" # cpg.root = HelloWorld() # cpg.server.start() Main properties: - this code starts a multi-threaded HTTP server that dispatches requests to methods - requests like "http://domain/dir/page?arg1=val1&arg2=val2" are mapped to "dir.page(arg1='val1', arg2='val2')" - CherryPy also supports "positional" arguments in URLs like http://domain/book/science/9 - requests are mapped to an object tree that is "mounted" on cpg.root (for instance: "cpg.root.user", "cpg.root.user.remi", ...) - method must be explicitely exposed with a decorator "@cpg.expose" (or "index.exposed = True" for Python-2.3) - methods can return a generator instead of a string (useful when generating big pages) Here is a non-exhaustive list of CherryPy-2 features: multi-threaded HTTP server, XML-RPC server, sessions, form handling, authentication, unicode support, gzip-compression, virtual hosting, WSGI adapter The design of CherryPy-2 allows to easily write/use pluggable "filters" or "modules": - filters perform operations on the request/response such as gzip-compression or string encoding - modules are web applications (like a blog or a web forum) than can be easily "mounted" anywhere you want in your website CherryPy-2 is already used in production by many sites and is supported by an active community. Remi. http://www.cherrypy.org From m at m.com Mon May 2 09:09:54 2005 From: m at m.com (monkey) Date: Mon, 2 May 2005 21:09:54 +0800 Subject: Is python support jxta now? References: <42760108$1_2@rain.i-cable.com> Message-ID: <4276269f_3@rain.i-cable.com> > Bittorrent, one of the most actively used p2p protocols is _written_ in > python. > > Diez B. Roggisch Hey man, no, the jxta p2p protocols is not mean the bittorrent stuff. It is a fully decentralized network protocol, not confine to file transfer. From bcarey at ix.netcom.com Tue May 24 14:25:51 2005 From: bcarey at ix.netcom.com (bc) Date: 24 May 2005 11:25:51 -0700 Subject: pygame 1.6 for windows (python2.4) Message-ID: <1116959151.370529.261690@g49g2000cwa.googlegroups.com> Hi All, Does anyone have any info concerning the windows pygame 1.6 for python2.4? It doesn't seem to be available yet. Will pygame1.6 for python23 work with python24? Thanks for any help concerning this. BC From flupke at nonexistingdomain.com Thu May 12 03:14:36 2005 From: flupke at nonexistingdomain.com (flupke) Date: Thu, 12 May 2005 07:14:36 GMT Subject: subclass dialog or put in the resource files? Message-ID: I'm using wxPython and design the gui via wxglade. One of the gui components is a simple dialog class that gets displayed when a user exits the program. I want to use the same dialog but with a different text for closing certain dialogs in the program. (it's a pure "do you want to exit " dialog) What would i better use, knowing the rest of the gui is in a resource (xrc) file: 1. Find some way to put a standard exit dialog in the resource file and then somehow try to set the message to the correct one. 2. Make a simple dialog class that accepts the message to be displayed. I could even use glade to generate the python code for a start. What would be the better/cleaner/logical way to do this? Thanks, Benedict From bcarey at ix.netcom.com Tue May 24 17:11:38 2005 From: bcarey at ix.netcom.com (bc) Date: 24 May 2005 14:11:38 -0700 Subject: pygame 1.6 for windows (python2.4) In-Reply-To: <429380c5$0$24449$da0feed9@news.zen.co.uk> References: <1116959151.370529.261690@g49g2000cwa.googlegroups.com> <429380c5$0$24449$da0feed9@news.zen.co.uk> Message-ID: <1116969098.442603.193670@g43g2000cwa.googlegroups.com> Thanks for the reply, Will... I have been to the site, but I get a "URL not found error" when I try the pygame 1.6 for python24 link; I guess I will just keep trying until the HTML is fixed. From poisondart985 at gmail.com Sat May 28 19:48:44 2005 From: poisondart985 at gmail.com (poisondart) Date: 28 May 2005 16:48:44 -0700 Subject: Software licenses and releasing Python programs for review In-Reply-To: References: <1117245014.218831.317750@g14g2000cwa.googlegroups.com> Message-ID: <1117324124.350474.136600@g14g2000cwa.googlegroups.com> Thanks for the replies. They have been very helpful. I'll have to read through the licenses you've listed in more detail, but the creative commons license of which James William Pye mentions seems to be what I'll be using. The reason why I need people to review my code and also the ideas behind the code is mostly for academic interest...but not necessarily reserved to an academic audience...which is why I don't want people to make profit from it. It uses ideas from a language--which would be ridiculous (to me) for anybody to make profit from selling the mechanics of a natural language. The NLTK mailing list seems to be what I was looking for...I'll start checking that out. Thanks for the link. From dalke at dalkescientific.com Tue May 31 03:58:39 2005 From: dalke at dalkescientific.com (Andrew Dalke) Date: Tue, 31 May 2005 07:58:39 GMT Subject: pickle alternative References: <1117520276.417970.207680@g14g2000cwa.googlegroups.com> <1117524878.988878.181820@g44g2000cwa.googlegroups.com> Message-ID: simonwittber wrote: >>From the marhal documentation: > Warning: The marshal module is not intended to be secure against > erroneous or maliciously constructed data. Never unmarshal data > received from an untrusted or unauthenticated source. Ahh, I had forgotten that. Though I can't recall what an attack might be, I think it's because the C code hasn't been fully vetted for unexpected error conditions. > Any idea how this might be solved? The number of bytes used has to be > consistent across platforms. I guess this means I cannot use the struct > module? How do you want to solve it? Should a 64 bit machine be able to read a data stream made on a 32 bit machine? What about vice versa? How are floats interconverted? You could preface the output stream with a description of the encoding used: version number, size of float, size of int (which should always be sizeof float these days, I think). Read these then use that information to figure out which decode/dispatch function to use. Andrew dalke at dalkescientific.com From peter at engcorp.com Wed May 25 09:38:24 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 25 May 2005 09:38:24 -0400 Subject: Just remember that Python is sexy In-Reply-To: References: <1116899839.323185.58350@g49g2000cwa.googlegroups.com> Message-ID: Sion Arrowsmith wrote: > But can you come up with a method for remembering which way > round str.find() and str.index() are? Don't use "str" and you won't have anything to remember: 'foo bar baz'.find('spam') 'spanish inquisition'.index('parrot') -Peter From querypk at gmail.com Fri May 6 15:44:38 2005 From: querypk at gmail.com (querypk at gmail.com) Date: 6 May 2005 12:44:38 -0700 Subject: min max of a list In-Reply-To: <427bc292$1_2@newspeer2.tds.net> References: <1115245476.036508.273930@g14g2000cwa.googlegroups.com> <427bac26$1_3@newspeer2.tds.net> <1115406819.884785.52080@o13g2000cwo.googlegroups.com> <427bc292$1_2@newspeer2.tds.net> Message-ID: <1115408678.867849.87500@z14g2000cwz.googlegroups.com> oh yes its the same case. even [0,4,9,2,0] as a set [2,6] and may be not [2,7]. Its not that you are wrong its jus that I was not clear. Sorry about that. From exarkun at divmod.com Fri May 27 15:42:44 2005 From: exarkun at divmod.com (Jp Calderone) Date: Fri, 27 May 2005 19:42:44 GMT Subject: Problem: using signal.alarm() to stop a run-away os.system() command In-Reply-To: 0 Message-ID: <20050527194244.559.72959310.divmod.quotient.11289@ohm> On 27 May 2005 12:09:39 -0700, mkent at webmd.net wrote: >I'm trying to use signal.alarm to stop a run-away os.system command. >Can anyone exlain the following behavior? > >Given following the trivial program: > >import os >import signal > >def timeoutHandler(signum, frame): > print "Timeout" > raise ValueError > > >signal.signal(signal.SIGALRM, timeoutHandler) >signal.alarm(5) > >os.system("yes") > >signal.alarm(0) > > >What I expect is that the Linux/UNIX 'yes' command (which runs until >terminated) would be stopped after 5 seconds, when the timeoutHandler >is called, thus raising a ValueError and terminating this example >program. Instead, the 'yes' command run until it is terminated (by, >say, a kill command), at which time the timeoutHandler is called. In >other words, the running of the 'yes' command acts like it is blocking >the SIGALRM signal until it terminates, at which time the SIGALRM >signal is raised. This is quite surprising, and totally defeats my >ability to catch a run-away process. Can anyone see what I'm doing >wrong? CPython only delivers signals to Python programs in between bytecodes. Since your program is hanging around in the system(3) call, it isn't executing any bytecode, so CPython never gets an opportunity to deliver the signal. Try using a pipe (popen() or the new subprocess module) and select() with a timeout of 5. Jp From just at xs4all.nl Mon May 2 10:11:37 2005 From: just at xs4all.nl (Just) Date: Mon, 02 May 2005 16:11:37 +0200 Subject: pop3proxy References: <4276329a$0$289$636a15ce@news.free.fr> Message-ID: In article <4276329a$0$289$636a15ce at news.free.fr>, BrokenClock wrote: > Here is a python newbie! I've choose it to make a pop3 proxy - I want to > filter content between a pop3 client and a pop3 server, and I have no > control on the server... > First, I wanted to do an non-filtering, just logging, mono-thread proxy > to make some test.. Not directly helpong with your problem, but perhaps some example code helps: the spambayes project contains a working pop3 proxy. Just From grante at visi.com Wed May 18 15:25:25 2005 From: grante at visi.com (Grant Edwards) Date: Wed, 18 May 2005 19:25:25 -0000 Subject: speeding up Python script References: <3evgolF56gtkU3@individual.net> Message-ID: <118n5l557ften8a@corp.supernews.com> On 2005-05-18, Luis P. Mendes wrote: > I have a 1000 line python script that takes many hours to > finish. It is running with six inside 'for' loops. [...] > How can I dramatically improve speed? In probably order of efficacy: 1) Use a better algorithm 2) Replace 'for' loops with vector operations or list comprehensions 3) Install more RAM 4) Install a faster disk drive 5) Use a faster CPU 6) Rent DVDs to watch while program is running. Before you do anything, you should profile your program to see where the time is being spent. -- Grant Edwards grante Yow! Hand me a pair of at leather pants and a CASIO visi.com keyboard -- I'm living for today! From gene.tani at gmail.com Tue May 10 21:11:27 2005 From: gene.tani at gmail.com (gene.tani at gmail.com) Date: 10 May 2005 18:11:27 -0700 Subject: A Faster Way... In-Reply-To: References: Message-ID: <1115773887.690435.19590@f14g2000cwb.googlegroups.com> hmm, there's lots of ways, huh? you can use itertools.zip instead of builtin zip, or do: map(None, list1, list2) , which will pad the shorter one to match the longer one. From exarkun at divmod.com Tue May 10 15:49:08 2005 From: exarkun at divmod.com (Jp Calderone) Date: Tue, 10 May 2005 19:49:08 GMT Subject: Put a file on an ftp server over ssl In-Reply-To: <1115749959.870607.20720@o13g2000cwo.googlegroups.com> Message-ID: <20050510194908.15422.1488198378.divmod.quotient.30738@ohm> On 10 May 2005 11:32:39 -0700, Daniel Santa Cruz wrote: >I looked briefly at this option, but it seems to me that I would have >to learn a whole architecture just to put a file on an ftp server. >Seems like a bit much, don't you think? (In the absence of any quoted material, assuming this is directed at my suggestion to use Twisted) Depends how important getting the file onto the server is to you :) You might want to consider future tasks which could be aided by the knowledge of Twisted and treat this as a good opportunity to get some exposure. Or maybe it's really not worth it to you. Only you can decide, I suppose. Jp From bokr at oz.net Wed May 4 14:25:22 2005 From: bokr at oz.net (Bengt Richter) Date: Wed, 04 May 2005 18:25:22 GMT Subject: Data smoothing algorithms? - Thank you all References: <000c01c54c38$313eb580$0201a8c0@mcuf7> Message-ID: <42790da4.665619460@news.oz.net> On Wed, 04 May 2005 16:01:07 GMT, Dennis Lee Bieber wrote: >On Tue, 03 May 2005 16:28:34 GMT, Dennis Lee Bieber > declaimed the following in comp.lang.python: > > >> It's not going to be easy, though... > > Yes, talking to myself... I crawled through one of my texts (at >work) yesterday. This is incomplete -- I wasn't going to copy the entire >chapter -- but may serve as an example of some of the complexity that >goes into some of the entries found in almanacs: > >From: "Spherical Astronomy" [Robin M. Green; 1985 Cambridge University] > >"The 1980 theory of nutation contains 106 terms both in longitude and >the obliquity" > >Displacement of true celestial pole from mean pole, /principal/ terms >only -- lunar caused nutation > >Nutation in longitude = -17".1996 sin omega > -1".3187 sin (2F - 2D + 2 omega) > -0".2274 sin (2F - 2 omega) >Nutation in obliquity = 9".2025 cos omega > + 0".5736 cos (2F - 2D + 2 omega) > + 0".0927 cos (2F - 2 omega) > >Where: > omega = mean longitude of the node (I presume of the moon) > F = mean argument from node (moon) > D = mean elongation from sun (moon) > >Periods of interest: >18.6 year lunar (movement of the node), >6 month solar, >14 day lunar... > >26000 year luni-solar precession > I wonder why the original post, which I presume was http://mail.python.org/pipermail/python-list/2005-April/278752.html doesn't show up in google groups, but can seemingly only be found indirectly by google search on "smoothing algorithms" site:python.org giving one main post http://mail.python.org/pipermail/python-list/2005-April/278871.html which is a reply with no immediate apparent parent. And then going to the sorted-by-thread index, where you can find the original. Maybe it's because there was an html attachment (which I didn't "wget" to investigate)? Anyway, the original post sounds like the OP was really just looking for better numbers than in some text tables he found, and not really for a way of estimating better numbers based on flawed data (though that was what he apparently thought his best option was, using the rounded text tables as data). I'd bet that is not his best option, especially since distributions of actual roundoff errors can be weird. There must be tons of telescope-pointing and planetarium-driving software out there that can do similar stuff. And if that's not accurate enough, the relevant newsgroup crowd will be able to advise, I'd bet. Regards, Bengt Richter From 550283447739-0001 at t-online.de Tue May 17 07:50:41 2005 From: 550283447739-0001 at t-online.de (Oliver Albrecht) Date: Tue, 17 May 2005 13:50:41 +0200 Subject: Image.putpalette(Colors)? Message-ID: Has somebody a example-script how i can put a other palette to a image? (after this the image should have similar outlook) From swaroopch at gmail.com Tue May 3 13:30:20 2005 From: swaroopch at gmail.com (Swaroop C H) Date: Tue, 3 May 2005 23:00:20 +0530 Subject: python+windows/linux -> write stdout text to always on top text? In-Reply-To: <1115138497.567243.308570@z14g2000cwz.googlegroups.com> References: <1115064842.454916.305970@f14g2000cwb.googlegroups.com> <1115138497.567243.308570@z14g2000cwz.googlegroups.com> Message-ID: <351e887105050310307c92f227@mail.gmail.com> On 3 May 2005 09:41:37 -0700, flamesrock wrote: > I'm writing a multiplayer component to an existing closed source game, > and I'd like users to be able to see whats going on in the chat while > playing the game. > Is it possible? I do not have much knowledge in this area but your query is regarding the abilities of the game engine itself and not much to do with Python. One suggestion is to look up any documentation of that game engine's for this capability. Another suggestion is to look at how Doom 2 or some other open source game engines achieve the same. HTH, -- Swaroop C H Blog: http://www.swaroopch.info Book: http://www.byteofpython.info From t-meyer at ihug.co.nz Thu May 19 18:49:58 2005 From: t-meyer at ihug.co.nz (Tony Meyer) Date: Fri, 20 May 2005 10:49:58 +1200 Subject: problem uploading ZIP file tp PyPI In-Reply-To: Message-ID: >>>> setup.py sdist --format=zip >>> >>> Try without the --format arg. The code is being too paranoid. >> >> Result: (A) produces a zip file with only minor differences >> (presumably a timestamp): > > Oh, so even without --format, a ZIP source dist file is > produced anyway? If this is the case, please file a bug against PyPI. How is this a bug? sdist is meant to produce a zip file on Windows if --format isn't used. If "upload" overrides this for some reason, then the documentation should say so (and, IMO, it would be a mistake for that to be the case). =Tony.Meyer From peter at engcorp.com Wed May 11 10:07:56 2005 From: peter at engcorp.com (Peter Hansen) Date: Wed, 11 May 2005 10:07:56 -0400 Subject: Replacing open builtin In-Reply-To: <1115819159.865288.238650@g49g2000cwa.googlegroups.com> References: <1115816164.517116.124070@g14g2000cwa.googlegroups.com> <1115819159.865288.238650@g49g2000cwa.googlegroups.com> Message-ID: <_9qdnT1T7fmRjx_fRVn-1Q@powergate.ca> rmm at iname.com wrote: > I had a quick look at the python source code and fileobject.c is one of > the core classes which, I would imagine, is why a reference can be > obtained. The other classes (method, dictionaries etc) don't look so > much of a liability. I'll maybe try disabling the fopen calls in > fileobject and see if it breaks anything (I've no need to open/close > files using the standard libraries). > > Are there any other holes you can think of in the following scenario- > I disable all builtins except import which I protect in my 'Isolate' > class, I then only allow import to import a single module name. You *really* ought to be checking the list archives for the *many* past discussions of this, and the many ways in which it is nowhere near as easy as you seem to think it might be, as well as for the variety of partially completed efforts -- some of which closely resemble your approach -- which have been abandoned after it was demonstrated how the could not work. On the other hand, after reading all that, you just might be the one to come up with the solution that combines just enough of each approach to solve the problem once and for all, and the community would be very grateful to you. But I doubt you'll solve this by asking Jp to review (and, inevitably, shoot down) each idea you come up with. Give him a break until you've read some of the archived material on this. :-) -Peter From simon.brunning at gmail.com Thu May 5 08:25:13 2005 From: simon.brunning at gmail.com (Simon Brunning) Date: Thu, 5 May 2005 13:25:13 +0100 Subject: [newbie] how to look up functions In-Reply-To: <4I4S42$89a@bbs.wretch.cc> References: <4I4S42$89a@bbs.wretch.cc> Message-ID: <8c7f10c6050505052533f6096d@mail.gmail.com> On 05 May 2005 06:27:14 GMT, slayer wrote: > Hi all, > I am a python newbie. I need some help to loop up about API, or reference. > If any web that Java API Document, I will try it. Is there some one like it > or other ways? http://www.google.com/search?q=python+documentation -- Cheers, Simon B, simon at brunningonline.net, http://www.brunningonline.net/simon/blog/ From pinard at iro.umontreal.ca Thu May 12 10:32:32 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Thu, 12 May 2005 10:32:32 -0400 Subject: pyvm -- faster python In-Reply-To: <7xis1pqdt0.fsf@ruckus.brouhaha.com> References: <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> <1115791624.856252.247890@z14g2000cwz.googlegroups.com> <7x1x8el18e.fsf@ruckus.brouhaha.com> <3eg2vnF2psplU1@individual.net> <7xis1pqdt0.fsf@ruckus.brouhaha.com> Message-ID: <20050512143232.GA7551@phenix.progiciels-bpi.ca> [Paul Rubin] > It's true that CPython doesn't have a compiler and that's > a serious deficiency. Hi, Paul. I did not closely follow all of the thread, so maybe my remark below, only repeats what others might have said and I missed? Deep down, why or how not having a [traditional, to-native-code] compiler is a deficiency for CPython? We already know that such a beast would not increase speed so significantly, while using much more memory. It is true that a standard traditional compiler for CPython would allow one would be to check the box: [x] has a compiler in the fashion of the day language information sheet, and for some readers, not having that box checked is a deficiency in itself. :-) So far, it seems that the only way to get speed is to attach static type information to some variables. Some compilation avenues do it through information added either in Python source code or in extraneous declarative files, other approaches do it by delaying compilation until such information is discovered at run-time. The former taints the purity of real CPython as the only source. The later often shows spectacular speed gain, but not always, and may bloat size unboudedly. -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From utabintarbo at gmail.com Sat May 7 10:54:22 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 7 May 2005 07:54:22 -0700 Subject: globbing multiple wildcards Message-ID: <1115477662.937084.260270@g14g2000cwa.googlegroups.com> I have a path spec similar to '/home/*/.mozilla/*/*/cache*/*' (this will probably look familiar to *nix users) with multiple wildcards. I am finding it difficult gathering ALL file pathnames which match this spec. Can anyone shed some light on this for a python noob? TIA Bob From rbt at athop1.ath.vt.edu Fri May 27 11:07:56 2005 From: rbt at athop1.ath.vt.edu (rbt) Date: Fri, 27 May 2005 11:07:56 -0400 Subject: cpu usage limit In-Reply-To: <1117206216.695085.282510@g44g2000cwa.googlegroups.com> References: <1117206216.695085.282510@g44g2000cwa.googlegroups.com> Message-ID: mf wrote: > Hi. > > My problem: > How can I make sure that a Python process does not use more that 30% of > the CPU at any time. I only want that the process never uses more, but > I don't want the process being killed when it reaches the limit (like > it can be done with resource module). > > Can you help me? > > Thanks in advance. > > Best regards, > Markus > Are you looping during a cpu intensive task? If so, make it sleep a bit like this: for x in cpu_task: time.sleep(0.5) do(x) From f.geiger at vol.at Wed May 18 15:41:39 2005 From: f.geiger at vol.at (F. GEIGER) Date: Wed, 18 May 2005 21:41:39 +0200 Subject: [pysqlite] pysqlite2.dbapi2.OperationalError: cannot commit transaction - SQL statements in progress Message-ID: I've troubles to let my app take off using pysqlite. What I wonder most for now is that "pysqlite2.dbapi2.OperationalError: cannot commit transaction - SQL statements in progress" when I do this: t = time.time() n = len(self) while len(self): del self[0] self.commit() print "%d items deleted in %.3f secs. " % (n, time.time() - t) self is of class DbTable which lets db tables be used like ordinary Python objects (after an idea of Scott Scriven): def __len__(self): self._query_("select count(*) from %s %s" % (self._name, self._whereClause)) r = int(self._dbc.fetchone()[0]) return r and def __delitem__(self, i): '''Enables you to remove rows this way: del movies[58] ''' q = "select %s from %s %s %s limit %s, 1" % (self._nameOfIdCol, self._name, self._whereClause, self._orderClause, i) self._query_(q) rid = self._dbc.fetchone()[0] q = "delete from %s where %s='%s'" % (self._name, self._nameOfIdCol, rid) self._query_(q) return So it boils down to SELECT and DELETE statements called in a loop. After that a commit is made. What does pysqlite try to tell me here? Kind regards Franz GEIGER PS.: I use pysqlite 2.0.1 on Python 2.3.4 From Bernd.Nawothnig at t-online.de Sun May 15 13:27:01 2005 From: Bernd.Nawothnig at t-online.de (Bernd Nawothnig) Date: Sun, 15 May 2005 19:27:01 +0200 Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <1116102355.715816.192840@z14g2000cwz.googlegroups.com> <42866cb8.177725696@news.oz.net> <1116109657.494997.315650@o13g2000cwo.googlegroups.com> <2g7jl2-qf8.ln1@Bernd.Nawothnig.dialin.t-online.de> <1116176591.072516.71020@g43g2000cwa.googlegroups.com> Message-ID: <5cdkl2-5o1.ln1@Bernd.Nawothnig.dialin.t-online.de> On 2005-05-15, M.E.Farmer wrote: >> No. You claimed > > This will only create a tuple in memory > > That is not what I said please do not edit my words and call it a > quote! Again the whole sentence: Message-ID: <1116093118.599403.35940 at g14g2000cwa.googlegroups.com> | This will only create a tuple in memory that has no name to reference | it by! Please check it out. I did only cut the sentence. But that did not change the sense of the part I quoted. (As I understood it, correct me if I'm wrong, I'm not a native English speaker). >> But we just learned that this is not the case. > Yes it seems I was proven wrong and have learned much from the > discussion ;) That is why I am here to learn from others and help if > I can ( sometimes I am just plain wrong and I get the help ) I know that very well. I often learned much from such discussions too. >> Reduced to this argument I have no objection. > Glad to hear it. >> Lisp is far from being ugly ;-) > Your words not mine.I never said it was ugly. > Lisp is beautiful but Python isn't Lisp, and the () *are* getting > overloaded. Understood and accepted. Bernd -- Those who desire to give up freedom in order to gain security, will not have, nor do they deserve, either one. [T. Jefferson] From mwooden at dtptypes.com Fri May 27 08:59:41 2005 From: mwooden at dtptypes.com (Malcolm Wooden) Date: Fri, 27 May 2005 12:59:41 +0000 (UTC) Subject: Strings for a newbie References: <42970d69@news.eftel.com> <42971235.9000805@lexicon.net> Message-ID: my actual code is: for x in range(len(l)): h = string.split(l[x]) where the sentence string is in an array of one element 'l' Error is: Traceback (most recent call last): File "", line 34, in ? File "", line 27, in SentenceText File "C:\PYTHON22\lib\string.py", line 122, in split return s.split(sep, maxsplit) AttributeError: 'list' object has no attribute 'split' "John Machin" wrote in message news:42971235.9000805 at lexicon.net... > Malcolm Wooden wrote: >> Sorry John but that don't do it for me. Just get errors comming back >> >> >> "John Machin" wrote in message >> news:42970d69 at news.eftel.com... >> > >>> >>>>>>s = "This is a sentence of words" >>>>>>a = s.split() >>>>>>a >>> >>>['This', 'is', 'a', 'sentence', 'of', 'words'] >>> > > Malcolm, > > What errors did you get? Please post a copy of what you see on your > screen; my palantir is on the fritz :-) > > Cheers, > John From jstroud at mbi.ucla.edu Thu May 12 21:17:06 2005 From: jstroud at mbi.ucla.edu (James Stroud) Date: Thu, 12 May 2005 18:17:06 -0700 Subject: tkFileDialog question In-Reply-To: <1115937784.883303.131080@f14g2000cwb.googlegroups.com> References: <1115937784.883303.131080@f14g2000cwb.googlegroups.com> Message-ID: <200505121817.06722.jstroud@mbi.ucla.edu> I think you are better off not binding a button like you are doing. Use the "command" option to get the behavior you want. E.g: class MyApp: def __init__(self, parent): self.myParent = parent self.myContainer1 = Frame(parent) self.myContainer1.pack() self.entry = Entry(self.myContainer1) self.entry.grid(row=0,column=0, columnspan=2) self.button1 = Button(self.myContainer1, command=(lambda: self.button1Click(self))) self.button1.configure(text="...") self.button1.grid(row=0, column=2) self.button1.bind("", self.button1Click) def button1Click(self, event): filePick = tkFileDialog.askopenfilename() James On Thursday 12 May 2005 03:43 pm, jaime.suarez at crossmatch.net wrote: > I am creating a very simple GUI with one Entry widget and > one Button. The purpose of the Button widget is to Browse for > a file using tkFileDialog.askopenfilename(). > > I bind the button to a handler which spawns a tkFileDialog. This > works but the button __stays depressed__ after the handler returns! > Any ideas why? > > class MyApp: > def __init__(self, parent): > self.myParent = parent > self.myContainer1 = Frame(parent) > self.myContainer1.pack() > > self.entry = Entry(self.myContainer1) > self.entry.grid(row=0,column=0 columnspan=2) > > self.button1 = Button(self.myContainer1) > self.button1.configure(text="...") > self.button1.grid(row=0, column=2) > self.button1.bind("", self.button1Click) > self.button1.bind("", self.button1Click) > > > def button1Click(self, event): > filePick = tkFileDialog.askopenfilename() -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ From mwm at mired.org Thu May 12 00:52:56 2005 From: mwm at mired.org (Mike Meyer) Date: Wed, 11 May 2005 23:52:56 -0500 Subject: Problems with csv module References: <17026.15830.303909.792010@montanaro.dyndns.org> <4n8581hlta0e1jbp0nidliuam6fmb08nv1@4ax.com> Message-ID: <86psvxkpuf.fsf@guru.mired.org> John Machin writes: > The CSV format is not defined at all, AFAIK. Just for the record, . You'll also see application that deal with the application/csv MIME type. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From percivall at gmail.com Sat May 7 06:28:34 2005 From: percivall at gmail.com (Simon Percivall) Date: 7 May 2005 03:28:34 -0700 Subject: handling more databases with ZEO References: Message-ID: <1115461714.504146.288450@f14g2000cwb.googlegroups.com> You should take a look at http://www.zope.org/Wikis/ZODB/FrontPage/guide/index.html From rrr at ronadam.com Sat May 14 11:45:38 2005 From: rrr at ronadam.com (Ron Adam) Date: Sat, 14 May 2005 11:45:38 -0400 Subject: Quick Reference from module doc strings. Message-ID: <42861D22.6000701@ronadam.com> Does anyone have suggestions on how to improve this further? Cheers, Ron_Adam def getobjs(object, dlist=[], lvl=0, maxlevel=1): """ Retrieve a list of sub objects from an object. """ if object not in dlist: dlist.append(object) if lvl200: s = object[0:200]+"......" else: s = object outtext.append(obj+'=') if '\n' in s: quotes='"""' else: quotes ='"' if len(s)>60: print outtext.append(quotes+s+quotes+'\n\n') elif (isinstance(object,str) or isinstance(object,int) or isinstance(object,bool) or isinstance(object,tuple) or isinstance(object,list) or isinstance(object,dict)): s = str(object) if len(s)<200: outtext.append(obj+'='+s+'\n\n') else: outtext.append(obj+'='+s[0:200]+'......\n\n') if hasattr(object,'__doc__'): if object.__doc__ != type(object).__doc__: outtext.append(str(object.__doc__)+'\n\n') return ''.join(outtext) def quick_ref(name): """ quick_ref(module_name) -> printable string Generate a sorted quick reference guide from an objects doc strings. The module_name is a string with the name of the module or class to get documents string from. Example: import os print quick_ref('os') """ objlist = getobjs(name) return printdoc(objlist) if __name__ == "__main__": #import module before calling in most cases. print quick_ref('__builtins__') From grante at visi.com Tue May 31 15:44:53 2005 From: grante at visi.com (Grant Edwards) Date: Tue, 31 May 2005 19:44:53 -0000 Subject: working with pointers References: Message-ID: <119pfllqklchb20@corp.supernews.com> On 2005-05-31, Michael wrote: > except numbers?? Um, no? Unless you provide some context, how are we supposed to know what you're asking about? Numbers are immutable, so there is no practical difference. -- Grant Edwards grante Yow! Are we THERE yet? My at MIND is a SUBMARINE!! visi.com From programmer.py at gmail.com Tue May 3 10:22:01 2005 From: programmer.py at gmail.com (Jaime Wyant) Date: Tue, 3 May 2005 09:22:01 -0500 Subject: Any decent IM protocol implementations (icq or aim) Message-ID: Can anyone recommend one? Google isn't giving me much. jw From roy at panix.com Fri May 27 09:14:25 2005 From: roy at panix.com (Roy Smith) Date: Fri, 27 May 2005 09:14:25 -0400 Subject: write to the same file from multiple processes at the same time? References: Message-ID: gabor wrote: > so, how does one synchronizes several processes in python? This is a very hard problem to solve in the general case, and the answer depends more on the operating system you're running on than on the programming language you're using. On the other hand, you said that each process will be writing a single line of output at a time. If you call flush() after each message is written, that should be enough to ensure that the each line gets written in a single write system call, which in turn should be good enough to ensure that individual lines of output are not scrambled in the log file. If you want to do better than that, you need to delve into OS-specific things like the flock function in the fcntl module on unix. From sesquile at gmail.com Fri May 27 14:46:26 2005 From: sesquile at gmail.com (mh) Date: 27 May 2005 11:46:26 -0700 Subject: Determine if windows drive letter is hard drive or optical from python? Message-ID: <1117219586.001829.74220@g49g2000cwa.googlegroups.com> Hi Folks- I'm trying to do a simple emulation of unix "locate" functionality in python for windows. Problem is I don't want to crawl/index optical drives. Do any of the windows people out there know how I can determine: 1. How many drives are on the system? (I could just iterate over the alphabet os.path.exists("%s:\\"%letter) ... is there a "windows" way of doing it?) 2. More importantly for those drives that exist, how do I determine if it is actually a harddrive? thanks matt From gabor at nekomancer.net Mon May 30 08:28:11 2005 From: gabor at nekomancer.net (gabor) Date: Mon, 30 May 2005 14:28:11 +0200 Subject: write to the same file from multiple processes at the same time? In-Reply-To: References: Message-ID: <32e45$429b073a$3eb01f24$23675@news.flashnewsgroups.com> gabor wrote: > Jp Calderone wrote: > >> To briefly re-summarize, when you want to acquire a lock, attempt to >> create a directory with a well-known name. When you are done with it, >> delete the directory. This works across all platforms and filesystems >> likely to be encountered by a Python program. > > > thanks... > > but the problem now is that the cgi will have to wait for that directory > to be gone, when he is invoked.. and i do not want to code that :) > i'm too lazy.. > > so basically i want the code to TRY to write to the file, and WAIT if it > is opened for write right now... > > something like a mutex-synchronized block of the code... > ok, i ended up with the following code: def syncLog(filename,text): f = os.open(filename,os.O_WRONLY | os.O_APPEND) fcntl.flock(f,fcntl.LOCK_EX) os.write(f,text) #FIXME: what about releasing the lock? os.close(f) it seems to do what i need ( the flock() call waits until he can get access).. i just don't know if i have to unlock() the file before i close it.. gabor From mj at zopatista.com Wed May 4 18:19:54 2005 From: mj at zopatista.com (Martijn Pieters) Date: Thu, 05 May 2005 00:19:54 +0200 Subject: Python Challenge ahead [NEW] for riddle lovers In-Reply-To: <9Ibee.81433$AX1.5235770@phobos.telenet-ops.be> References: <1114924100.296223.114020@g14g2000cwa.googlegroups.com> <1114927892.321086.60190@z14g2000cwz.googlegroups.com> <8764y29x3m.fsf@uwo.ca> <877jihc7qv.fsf@uwo.ca> <9Ibee.81433$AX1.5235770@phobos.telenet-ops.be> Message-ID: <42794A8A.6040402@zopatista.com> Roel Schroeven wrote: > You don't really need the remember the solution; it's more the process > that led you to find the solution. Yup, I do remember the process, and it hasn't been any help so far.. no adjustable URLs leading to interesting files, no 'dealable' images, no nada. Martijn Pieters -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 264 bytes Desc: OpenPGP digital signature URL: From hancock at anansispaceworks.com Wed May 11 12:01:16 2005 From: hancock at anansispaceworks.com (Terry Hancock) Date: Wed, 11 May 2005 11:01:16 -0500 Subject: Python Args By Reference In-Reply-To: References: <1115769308.136143.74080@f14g2000cwb.googlegroups.com> Message-ID: <200505111101.16735.hancock@anansispaceworks.com> On Wednesday 11 May 2005 08:43 am, Peter Hansen wrote: > Roy Smith wrote: > > The most common immutable objects you'll see are strings and tuples, and > > the main reason they're immutable is to allow them to be dict keys. > > And ints. Strings, tuples and ints are the *three* most common > immutable objects you'll see... And floats. Floats, strings, tuples, and ints art the *four* most common immutable objects you'll see... Time to break out the comfy chair. ;-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com From flyaflya at gmail.com Tue May 10 10:59:07 2005 From: flyaflya at gmail.com (flyaflya) Date: Tue, 10 May 2005 22:59:07 +0800 Subject: why this happend using model random? In-Reply-To: References: Message-ID: flyaflya wrote: > Robert Kern wrote: > >> flyaflya wrote: >> >>> from random import * >>> >>> col = [0 for i in range(10)] >>> a = [col for i in range(10)] >> >> >> >> This is the problem. The list "a" now has ten references to the same >> object "col". They are not copied. >> >>> seed() >>> for i in range(10): >>> for j in range(10): >>> a[i][j] = randint(0, 100) >> >> >> >> So every time you index into "a[i][j]" you are always getting "col[j]". >> > thanks,I see,I know about reference and copy,but when is it a copy?when > a reference?how can I get a copy when need? I find the answer on chapter4.5,it's a practical book for the newbies like me,maybe many newbie using c/c++ would make such mistake From dieter at handshake.de Fri May 6 14:15:20 2005 From: dieter at handshake.de (Dieter Maurer) Date: 06 May 2005 20:15:20 +0200 Subject: Tons of stats/opens to non-existing files increases Python's startupon loaded NFS servers References: <20050505211519.52192.qmail@web60008.mail.yahoo.com> Message-ID: "Fredrik Lundh" writes on Fri, 6 May 2005 00:08:36 +0200: > > ... lots of "no such file or directory ... > > Whoa!! After looking at what is being stat'd or > > open'd, it looks like 'encodings' is new in 2.4 and, > > even "worse", everything is looked for as a zip first. > > so why not build that ZIP? We, too, saw this problem -- and we had the "*.zip" files already... Python is a bit stupid in its import logic. When, e.g., a package "P" defined in a zip archive "zzz.zip" contains an "import os", then Python checks whether "zzz.zip" contains "P.os" (that is okay). *But*, usually "zzz.zip" does not define "P.os" (as "os" is a builtin module) and then Python checks in the file system for "zzz.zip/P/os{,.py,pyc,.so,} and "zzz.zip/P/osmodule.so". Of course, all of them fail as "zzz.zip" is a Zip archive and "zzz.zip/something" is not meaningfull as a file system reference. I improved on this by patching Python's "import.c" with the attached patch. The patch implements that a "path_hook" declaring itself to be responsible for a path is authoritative for both negative as well as positive "find_module" responses. Earlier, a negative "find_module" response caused Python to try the default module lookup. Furthermore, it is vital that your "sys.path" is as small as possible because a single module lookup can cause file system lookups in the order of 4 times the number of path elements. The standard extension of "sys.path" often contains far more path elements than necessary (if you defined "python24.zip", you should remove all other python library directories that do not contain shared objects). Dieter -------------- next part -------------- A non-text attachment was scrubbed... Name: import.pat Type: text/x-path Size: 817 bytes Desc: Patch for Python 2.4.1 to prevent meaningless fs checks for zip archive members URL: From mwm at mired.org Thu May 12 18:25:56 2005 From: mwm at mired.org (Mike Meyer) Date: Thu, 12 May 2005 17:25:56 -0500 Subject: pyvm -- faster python References: <1115561483.741761.212140@f14g2000cwb.googlegroups.com> <7xvf5qbir1.fsf@ruckus.brouhaha.com> <7xpsvymlse.fsf@ruckus.brouhaha.com> <1115791624.856252.247890@z14g2000cwz.googlegroups.com> <7x1x8el18e.fsf@ruckus.brouhaha.com> <3eg2vnF2psplU1@individual.net> <7xis1pqdt0.fsf@ruckus.brouhaha.com> <7xbr7g8cni.fsf@ruckus.brouhaha.com> Message-ID: <86y8akgjyj.fsf@guru.mired.org> Paul Rubin writes: > Andrew Dalke writes: > >> Years ago, presented at one of the Python conferences, was a program >> to generate C code from the byte code.... The conclusion I recall >> was that it wasn't faster - at best a few percent - and there was a >> big memory hit because of all the duplicated code. One thought was >> that the cache miss caused some of the performance problems. Does >> that count as a compiler? > > I would say it counts as a compiler and that other languages have > used a similar compilation approach and gotten much better speedups. > For example, Java JIT compilers. The DEC Scheme-to-C translator > and Kyoto Common Lisp also produced C output from their compilers > and got really significant speedups. Part of the problem may be > with the actual Python language. The DEC Scheme->C compiler (yes, it was an honest to gods compiler - it just generated C instead of machine code) doesn't sound very similar to generating C code from byte code. The latter sounds like a straightforward translation of byte code to C. The Scheme->C compiler, on the other hand, used all the optimizations known to LISP compiler writers. It would, with the right settings, produce code that was comparable to hand-coded C. So unless the Python compiler that produced the byte code in the first place does all those optimizations (which I don't know), you're not going to get results that compare with the Scheme->C system. > Despite the shrieks of the "Python is not Lisp!" crowd, Python > semantics and Lisp semantics aren't THAT different, and yet compiled > Lisp implementations com completely beat the pants off of interpreted > Python in terms of performance. I don't think Python can ever beat > carefully coded C for running speed, but it can and should aim for > parity with compiled Lisp. There are people out there who claim that compiling carefully coded LISP can compete with compiling carefully coded C. They use such systems in real-world, time-critical applications. The thing is, to get that performance, they had to go back and tell the compiler what the types of all the variables are, and disable all the runtime type checking. So if this is a real goal, you now have some idea of what to look forward to in Python's future. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From no-mail-please at nospam.com Sun May 1 13:32:43 2005 From: no-mail-please at nospam.com (Robert Oschler) Date: Sun, 1 May 2005 13:32:43 -0400 Subject: compare two voices References: <1114916457.795332.45220@f14g2000cwb.googlegroups.com> Message-ID: <9rSdnWJ8Fer3jOjfRVn-tw@adelphia.com> "Qiangning Hong" wrote in message news:1114916457.795332.45220 at f14g2000cwb.googlegroups.com... > I want to make an app to help students study foreign language. I want > the following function in it: > > The student reads a piece of text to the microphone. The software > records it and compares it to the wave-file pre-recorded by the > teacher, and gives out a score to indicate the similarity between them. > > This function will help the students pronounce properly, I think. > > Is there an existing library (C or Python) to do this? Or if someone > can guide me to a ready-to-implement algorithm? > How about another approach? All modern speech recognition systems employ a phonetic alphabet. It's how you describe to the speech recognition engine exactly how the word sounds. For each sentence read, you create a small recognition context that includes the sentence itself, AND subtle variations of the sentence phonetically. For example (using English): You want them to say correctly: "The weather is good today". You create a context with the following phrases which include the original sentence, and then alternative sentences that dithers (varies) the original sentence phonetically. Sample context: (*) The weather is good today Da wedder is god tuday The weether is good towday Etc. Then submit the context to the speech recognition engine and ask the user to say the sentences. If the original sentence (*) comes back as the speech recognition engine's best choice, then they said it right. If one of the other choices comes back, then they made a mistake. You could even "grade" their performance by tagging the variations by closeness to the original, for example: (*) The weather is good today (100) Da wedder is god tuday (80) Ta wegger es gid towday (50) In the example above, the original sentence gets a 100, the second choice which is close gets an 80, and the last option which is pretty bad gets 50. With a little effort you could automatically create the "dithered" phonetic variations and auto-calculate the score or closeness to original too. Thanks, Robert http://www.robodance.com Robosapien Dance Machine - SourceForge project From pinard at iro.umontreal.ca Wed May 4 09:02:49 2005 From: pinard at iro.umontreal.ca (=?iso-8859-1?Q?Fran=E7ois?= Pinard) Date: Wed, 4 May 2005 09:02:49 -0400 Subject: How To Reply In-Reply-To: References: Message-ID: <20050504130249.GA1264@alcyon.progiciels-bpi.ca> [Peter Hansen] > You are forced to cut and paste if you want to get the messages in a > digest. I doubt any mail program has been designed to know how to do > anything smarter, Lars Magne Ingebrigtsen's wonderful Gnus (a much boosted, combined news/mail reader, running within or over Emacs) knows about digests. (Moreover, with not so much trickery, it is Python extensible. I vaguely remember having written one or two Python backends for Gnus.) -- Fran?ois Pinard http://pinard.progiciels-bpi.ca From duncan.booth at invalid.invalid Fri May 27 11:32:47 2005 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 27 May 2005 15:32:47 GMT Subject: Case Sensitive, Multiline Comments References: <1117137316.140791.210430@g14g2000cwa.googlegroups.com> <8664x5y92g.fsf@guru.mired.org> <429654DA.9050903@lexicon.net> <1117154013.092736.298310@g14g2000cwa.googlegroups.com> <119eccdgjtaru5d@news.supernews.com> Message-ID: John Roth wrote: > Doing case translations in Unicode following all of > the rules for all of the world's languages is, for want of a better > world, a real bitch. > Fair point, although that is true for anything, not just case translations. Fortunately, unlike Ecmascript, Python doesn't allow arbitrary unicode characters in identifiers. From cal_2pac at yahoo.com Fri May 20 11:57:35 2005 From: cal_2pac at yahoo.com (cal_2pac at yahoo.com) Date: 20 May 2005 08:57:35 -0700 Subject: How to receive events (eg. user mouse clicks) from IE In-Reply-To: <428d0e75$1_2@spool9-west.superfeed.net> References: <1116476411.853695.235670@g14g2000cwa.googlegroups.com> <428c3cbe$1_1@spool9-west.superfeed.net> <1116529345.146032.91880@f14g2000cwb.googlegroups.com> <428cf5a9$1_1@spool9-west.superfeed.net> <1116537405.495521.252570@f14g2000cwb.googlegroups.com> <428d0e75$1_2@spool9-west.superfeed.net> Message-ID: <1116604655.431664.261430@g49g2000cwa.googlegroups.com> Thanks for the response again. The solution is pretty close but not yet complete This is what I observed. a) I tried to use the delay mechanism as suggested below ie. ie.Navigate('www.google.com') while ie.ReadyState !- 4 time.sleep(0.5) d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) IE *fails* to load the webpage b) Then I changed the delay to a specified time interval eg ie.Navigate('www.google.com') time.sleep(60) #wait for a minute d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) IE loads the web page *after* 60 seconds c) Then I used raw_input() eg ie.Navigate('www.google.com') raw_input() d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) IE now loads the webpage and prompts the user. If I click on the web page *before* clicking ok on the raw_input prompt - then it correctly invokes the Doc_Events method Ononactivate method. >From these observations, it seems that there is some kind of a race condition / timing issue happening. Can you please comment (or maybe point me to other sources of info that I can investigate). I am running Python 2.3 on Windows 2k machine. Roger Upole wrote: > Usually you get that error if you try to access the Document object > before the page has loaded. Try adding a delay after ie.Navigate, > something like > > while ie.ReadyState<>4: > time.sleep(0.5) > There are some constants that show up in win32com.client.constants > that represent the ReadyState's, but I can't remember the names offhand. > > The only real reference for the Html objects (other than reading the > generated module) is MSDN. Google turned this up: > http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/events/htmlanchorevents/htmlanchorevents.asp > > Roger > > > wrote in message > news:1116537405.495521.252570 at f14g2000cwb.googlegroups.com... > > Thanks for your prompt responses and the code. > > However, when I run the code I get com error > > d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) > > File "C:\Python23\lib\site-packages\win32com\client\__init__.py", > > line 199, in __getattr__ > > return getattr(self._obj_, attr) > > File "C:\Python23\lib\site-packages\win32com\client\__init__.py", > > line 455, in __getattr__ > > return self._ApplyTypes_(*args) > > File "C:\Python23\lib\site-packages\win32com\client\__init__.py", > > line 446, in _ApplyTypes_ > > return self._get_good_object_( > > com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, > > 0, -2147467259), None) > > > > I am a newbie to python(started coding a few months ago). > > This appears to be a fairly common error when COM objects are not > > hooked up properly. Though I have not been able to find a solution or > > the reason for this. > > Thanks again for the explanation.All the information that I had > > acquired now seems to fall into place. I was not aware about > > doc_mod.HTMLAnchorEvents. Where can I find more documentation about > > this? > > > > Roger Upole wrote: > >> Here's a few more lines that hook the document's onactivate event. > >> > >> import win32com.client > >> > >> > > ie_mod=win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' > > > >> ,0, 1, 1) > >> > > doc_mod=win32com.client.gencache.EnsureModule('{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}' > > > >> ,0 ,4, 0) > >> class IE_Events(ie_mod.DWebBrowserEvents2): > >> def OnNavigateComplete2(self, pDisp, URL): > >> print 'OnNavigateComplete2:', URL > >> > >> class Doc_Events(doc_mod.HTMLAnchorEvents): > >> def Ononactivate(self): > >> print 'onactivate', self.activeElement.outerHTML > >> > >> > > ie=win32com.client.DispatchWithEvents('InternetExplorer.Application',IE_Events) > >> ie.Visible=1 > >> ie.Navigate('http://www.google.com') > >> > >> d=win32com.client.DispatchWithEvents(ie.Document, Doc_Events) > >> > >> Roger > >> > >> > >> wrote in message > >> news:1116529345.146032.91880 at f14g2000cwb.googlegroups.com... > >> > Hi > >> > Thanks for the response and for the code. > >> > However, I want to trap events like mouse click on the HTML > > document > >> > loaded by the web browser control. The code mentioned below > > provides > >> > events from the web browser control. I need to find out on which > >> > particular HTML tag did the user click for example. > >> > How do I find that out? There should be some way to refer to a > > document > >> > from a given web browser control and start receiving events from it > >> > > >> > > >> > Roger Upole wrote: > >> >> The two you'll need to run makepy for are Microsoft Internet > > Controls > >> > and > >> >> Microsoft HTML object Library. If you run them manually, you > > should > >> > be > >> >> able to look at the generated code to get the guids. > >> >> Here's a minimal example: > >> >> > >> >> import win32com.client > >> >> > >> >> > >> > > > ie_mod=win32com.client.gencache.EnsureModule('{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}',0, > >> > > >> >> 1, 1) > >> >> class IE_Events(ie_mod.DWebBrowserEvents2): > >> >> def OnNavigateComplete2(self, pDisp, URL): > >> >> print 'OnNavigateComplete2:', URL > >> >> > >> >> > >> > > > ie=win32com.client.DispatchWithEvents('InternetExplorer.Application',IE_Events) > >> >> ie.Visible=1 > >> >> ie.Navigate('http://www.google.com') > >> >> > >> >> hth > >> >> Roger > >> >> > >> >> > >> >> wrote in message > >> >> news:1116476411.853695.235670 at g14g2000cwa.googlegroups.com... > >> >> >I am trying to trap events from internet explorer eg. when user > >> > clicks > >> >> > on an html link - I need to get notified for that event. > >> >> > > >> >> > After looking through the newgroups / internet and reading > > through > >> >> > various sections in programming python on win32 - I understand > > that > >> >> > this can be done using DispatchWithEvents. > >> >> > I have also referred to discussions on comp.lang.python > >> >> > > >> > > > http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/a3c502d06412a5f8/0ee3083e71316da7?q=dispatchwithevents&rnum=43#0ee3083e71316da7 > >> >> > > >> >> > and > >> >> > > >> >> > > >> > > > http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1da0668794851296/5bcec1fda216c598?q=dispatchwithevents&rnum=19#5bcec1fda216c598 > >> >> > > >> >> > So far - none of the newgroups postings report that IE events > > were > >> >> > trapped successfully (at least I could not find any). However, > >> > there is > >> >> > enough evidence that it can be done. > >> >> > My problems at the moment: > >> >> > a) The examples use early binding. However, I cannot get Python > >> > makepy > >> >> > to generate the code to force makepy process at run time - since > >> > COM > >> >> > makepy utility that I invoke from python win 32 does not have > > any > >> > entry > >> >> > for internet explorer. > >> >> > I tried to find the CLSID for IE > >> > 3050F613-98B5-11CF-BB82-00AA00BDCE0B > >> >> > but I get an exception > >> >> > b) Also one of the examples suggest that following code should > > work > >> >> > > >> >> >> mod = EnsureModule(...) > >> >> > > >> >> >> class MyEvents(mod.IDocumentEvents): > >> >> >> # your methods here.... > >> >> > > >> >> >> handler = MyEvents(ie.document) > >> >> > > >> >> >> # handler should start recieving events. > >> >> > > >> >> > however, what CLSID is to be used in EnsureModule... . I tried > > with > >> > a > >> >> > few but I always get the error 'NoneType' object has no > > attribute > >> >> > 'IDocumentEvents' > >> >> > > >> >> > > >> >> > An example that 'works' will be very useful > >> >> > > >> >> > >> >> > >> >> > >> >> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure > > Usenet > >> > News==---- > >> >> http://www.newsfeeds.com The #1 Newsgroup Service in the World! > >> > 120,000+ Newsgroups > >> >> ----= East and West-Coast Server Farms - Total Privacy via > > Encryption > >> > =---- > >> > > >> > >> > >> > >> > >> ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet > > News==---- > >> http://www.newsfeeds.com The #1 Newsgroup Service in the World! > >>100,000 Newsgroups > >> ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- > > > > > > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups > ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- From mbbx6spp at gmail.com Fri May 27 13:44:01 2005 From: mbbx6spp at gmail.com (mbbx6spp at gmail.com) Date: 27 May 2005 10:44:01 -0700 Subject: Does Python have a Template::Extract equivalent from Perl's CPAN Message-ID: <1117215841.123847.234300@o13g2000cwo.googlegroups.com> Hi All, I already searched this newsgroup and google groups to see if I could find a Python equivalent to Perl's Template::Extract, but didn't find anything leading to a Python module that had similar functionality. I am a big fan of Python as an OO language and use it for many system admin utilities, webdev and even MS Excel AddIn development, but I have found that Perl's Template::Extract is so invaluable to my web scraping utilities that I can not migrate this very old code base over to Python yet since there is nothing that I can easily port it over to without making my web scrapers very brittle to website redesigns. I while I think Perl is a wonderful language in its own right I would rather just code more of my codebase in Python than Perl to make my coding more efficient. If anyone knows of a Python module that has the same features of Template::Extract please let me (and maybe the group) know. If nobody is not aware of any module, I would be interested in developing one for the Python public. Please let me know if anyone else is interested and I can setup a sf.net project to get this rolling (unless anyone knows of an sf.net like website that offers Subversion instead of CVS?). Thanks! From vinay_sajip at yahoo.co.uk Tue May 17 02:02:35 2005 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Tue, 17 May 2005 06:02:35 +0000 (UTC) Subject: RotatingFileHandler in Python 2.3.5 References: Message-ID: new pip gmail.com> writes: > > Is the RotatingFileHandler (from the logging module) available in > Python 2.3.5? I'm getting a "AttributeError: 'module' object has no > attribute 'RotatingFileHandler'" error message when trying to use it. The handler is in the logging.handlers module, not in the logging module itself. If you are using a configuration file, use "handlers.RotatingFileHandler" rather than just "RotatingFileHandler". Vinay Sajip From tzot at sil-tec.gr Fri May 27 05:52:30 2005 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Fri, 27 May 2005 12:52:30 +0300 Subject: Encryption with Python? References: <1115324411.952821.150780@o13g2000cwo.googlegroups.com> <001301c552db$dd19d3e0$0201a8c0@mcuf7> <6vh881d59bbecnc45fojknt0rohgt27crl@4ax.com> <7xsm09br0n.fsf@ruckus.brouhaha.com> Message-ID: On 26 May 2005 14:45:28 -0700, rumours say that Paul Rubin might have written: >> That's all. I see you took up the challenge and indirectly replied to >> my last question, and in good spirit I say you earned a little respect >> from me, at least for standing up to your words. Now I hope no-one >> gives a try to your data (for your own sake :) >I don't think the challenge was really accepted. The algorithm >changed between when you issued the challenge, and when the sensitive >data went up. A good algorithm doesn't need to change depending on >the data. I agree with the poster who said that the strength of >either one of the algorithms is irrelevant, if the keyspace is just 32 >bits. You are correct; the algorithm changed, and the OP admitted it himself in the post with the encrypted credit card data. However, on a practical level: before posting, I did a quick comparison, and the only effective change to OP's algorithm was a the addition of a `random.shuffle(sequence)', which AFAIU has no practical consequences as to whether his algorithm is unbreakable or not. I could say that "hey, you changed the algorithm, and that means your previous declaration of unbreakability wasn't." but honestly I was overwhelmed by the audacity (and foolishness, if these are truly his credit card data) of Frederic. ObSF: DNA; The Restaurant At The End Of The Universe; Marvin the paranoid android faces a gigantic black tank in the H2G2 HQ. -- TZOTZIOY, I speak England very best. "Be strict when sending and tolerant when receiving." (from RFC1958) I really should keep that in mind when talking with people, actually... From sakesun at boonthavorn.com Mon May 9 02:15:41 2005 From: sakesun at boonthavorn.com (Sakesun Roykiattisak) Date: Mon, 09 May 2005 13:15:41 +0700 Subject: Fredrik Lundh In-Reply-To: References: Message-ID: <427F000D.2020103@boonthavorn.com> >google for logix site:pythonware.com He's announced plenty non-python >stuff that is of interest to python users, including plenty of marketing >for his own software. > > IMHO, Pythonware.com does not have to be about python. It can be anything the maintainer want it to be. Get the point ? BTW, I'm one of python users who is NOT INTERESTED in BOOO. And prefer Daily-python to stay what it is. From http Fri May 27 18:10:16 2005 From: http (Paul Rubin) Date: 27 May 2005 15:10:16 -0700 Subject: write to the same file from multiple processes at the same time? References: <7x1x7siy3b.fsf@ruckus.brouhaha.com> Message-ID: <7xacmgnwvr.fsf@ruckus.brouhaha.com> Peter Hansen writes: > And PySQLite conveniently wraps the relevant calls with retries when > the database is "locked" by the writing process, making it roughly a > no-brainer to use SQLite databases as nice simple log files where > you're trying to write from multiple CGI processes like the OP wanted. Oh, ok. But what kind of locks does it use? From utabintarbo at gmail.com Sat May 7 11:55:54 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 7 May 2005 08:55:54 -0700 Subject: globbing multiple wildcards In-Reply-To: References: <1115477662.937084.260270@g14g2000cwa.googlegroups.com> Message-ID: <1115481354.357281.240920@g14g2000cwa.googlegroups.com> OK, I guess it WAS that easy. :-P Thanks for the replys. Bob From gvanrossum at gmail.com Mon May 2 13:25:55 2005 From: gvanrossum at gmail.com (Guido van Rossum) Date: Mon, 2 May 2005 10:25:55 -0700 Subject: How to kill a SocketServer? In-Reply-To: <17014.21449.421677.445431@montanaro.dyndns.org> References: <7xwtqj1lh1.fsf@ruckus.brouhaha.com> <7xpswa4wfu.fsf@ruckus.brouhaha.com> <17013.25972.965219.254879@montanaro.dyndns.org> <7xekcq75av.fsf@ruckus.brouhaha.com> <1115046280.413931.16970@g14g2000cwa.googlegroups.com> <17014.21449.421677.445431@montanaro.dyndns.org> Message-ID: [Skip Montanaro] > I stumbled on a somewhat cleaner way to do this using socket timeouts: > > class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer): > pause = 0.25 > allow_reuse_address = True > > def __init__(self, server_address, RequestHandlerClass): > SocketServer.TCPServer.__init__(self, server_address, > RequestHandlerClass) > self.socket.settimeout(self.pause) > self.serving = 1 > ... > > def serve_forever(self): > while self.serving: > self.handle_request() > > As far as my simple testing went (a trivial little xmlrpc server exposing > only "noop" and "exit" methods), the above worked fine. I was mildly > surprised that I didn't have to catch socket.timeout exceptions. I think this would cause timeouts in the middle of handling request whenever a client is slow. -- --Guido van Rossum (home page: http://www.python.org/~guido/) From piet at cs.uu.nl Mon May 23 05:40:44 2005 From: piet at cs.uu.nl (Piet van Oostrum) Date: Mon, 23 May 2005 11:40:44 +0200 Subject: Python on a public library computer In-Reply-To: <1116592130.314355.202930@g44g2000cwa.googlegroups.com> (Anton Vredegoor's message of "20 May 2005 05:28:50 -0700") References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> <87r7g6rbz0.fsf@pobox.com> <1116330665.197293.198950@o13g2000cwo.googlegroups.com> <861x858qav.fsf@guru.mired.org> <1116417677.506240.261730@g47g2000cwa.googlegroups.com> <1116464373.016279.13030@f14g2000cwb.googlegroups.com> <1116592130.314355.202930@g44g2000cwa.googlegroups.com> Message-ID: There are several ssh and telnet applets on the web. Of course it depends on the Java support in your IE. -- Piet van Oostrum URL: http://www.cs.uu.nl/~piet [PGP] Private email: piet at vanoostrum.org From martin at v.loewis.de Fri May 20 12:20:09 2005 From: martin at v.loewis.de (=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=) Date: Fri, 20 May 2005 18:20:09 +0200 Subject: circular imports In-Reply-To: <1116599898.308012.71220@g47g2000cwa.googlegroups.com> References: <1116599898.308012.71220@g47g2000cwa.googlegroups.com> Message-ID: <428e0e3a$0$26404$9b622d9e@news.freenet.de> qhfgva at gmail.com wrote: > So I thought I'd just add the necessary __init__.py files and then > things would just work. Unfortunately trying this exposed a large > number of circular imports which now cause the files to fail to load. You didn't describe you you created the necessary __init__.py files. If they are not empty, there is a good chance that you made some error in creating these files. What is the error that you get with the circular imports? > Any ideas why the sys.path.append method has no problem with circular > imports whereas doing thing the "right way" chokes. One reason is that there could be duplicate module names, e.g. overlaps with the standard library. When you fully-qualified the modules, you actually changed the program, which would now import the user-provided modules instead of the predefined ones. Regards, Martin From asmir.mehic at gmail.com Wed May 11 04:38:46 2005 From: asmir.mehic at gmail.com (asmir.mehic at gmail.com) Date: 11 May 2005 01:38:46 -0700 Subject: A Faster Way... In-Reply-To: References: Message-ID: <1115800725.970214.299160@g43g2000cwa.googlegroups.com> For efficient string concatenation in python look at: http://www.skymind.com/~ocrow/python_string From newsgroups at jhrothjr.com Fri May 27 15:17:43 2005 From: newsgroups at jhrothjr.com (John Roth) Date: Fri, 27 May 2005 13:17:43 -0600 Subject: distutils, 'scripts' and Windows References: Message-ID: <119esir5c2l2923@news.supernews.com> "George van den Driessche" wrote in message news:d77ml7$cus$1$8300dec7 at news.demon.co.uk... > Hi folks, > > I'm looking at packaging a project I'm working on using distutils. The > project is for Windows and contains a COM server which needs registration, > so the installer needs to be a little more complicated than usual. Looking > at the options for the bdist_wininst command to distutils, I see it's > possible to specify > --install-script= > which ought to do the trick. But to use this, myinstallscript itself must > first be installed by passing > scripts='myinstallscript' > to distutils.core.setup in setup.py. That will copy myinstallscript into a > particular location (C:\Python24\Scripts in my case) and leave it there > forever. Which raises a couple of questions: > > - Why is myinstallscript left there forever? The documentation makes some > vague reference to needing it for uninstalling packages, but then I can't > actually find a way to uninstall packages. > > - What is the use of the Scripts directory on Windows? It's not added to > my PATH, so unless I do that myself it won't do anything like it's meant > to on other platforms. > > - Should I supply myinstallscript, or myinstallscript.py? I suspect the > latter, since that's the only way to give files types on Windows. > > - Is there some other better way to perform post-installation actions? > Would it work out of a binary generated from bdist_wininst? What I found, thanks to Martin Fuzzey, is that if you assign the result of the setup() function to a variable, you can access all sorts of interesting stuff after setup() completes. You need to do some source reading, but it's quite instructive. Also, if you check the parms after setup completes for "install" or whatever other subcommand you're using to install the stuff, you can then do pretty much whatever you want without having to have another script. I convert line endings on all of my scripts manually since distutils doesn't seem to do it. I should also convert line endings on the documentation. Sigh. > - Should I even be using distutils? It doesn't really matter that much > where the files are installed because the COM server can register itself > to run out of whatever location it happens to be in. I personally find distutils to be an absurd fit for my application (PyFit). It does way more than I need, and doesn't do a lot of other stuff that I need, and makes lots of assumptions about file locations that are simply, um, well ... Unfortunately, it's also the standard installation engine, so there's no getting around it if you want to be consistent with what everyone else is doing and future enhancements to the installation process through the Python Package Index, eggs and a lot of other stuff that's coming down the pike. John Roth > > Thanks, > George > From roccomoretti at hotpop.com Fri May 13 10:26:51 2005 From: roccomoretti at hotpop.com (Rocco Moretti) Date: Fri, 13 May 2005 09:26:51 -0500 Subject: Python Documentation (should be better?) In-Reply-To: <428467b1$0$5860$626a14ce@news.free.fr> References: <5C99C308457E6D4EA5448EA52A66004A675A6E@or.mxim.com> <17026.26789.592527.975821@montanaro.dyndns.org> <428276e8$0$318$626a14ce@news.free.fr> <428467b1$0$5860$626a14ce@news.free.fr> Message-ID: bruno modulix wrote: > > I fail to see why would it would be better to have to open a browser, go > to python.org, go to the doc, find the right link etc instead of just > typing dir(xxx) and/or help(xxx). Well, for those with Windows machines, the documentation is a simple Start->All Programs->Python->Python Manuals. I'm somewhat amused that the Docs don't come standard with other platforms. I guess they figure if you're compiling from source, you'd download them to the local machine separately. That said, I have no clue if PHP provides a local copy of the docs. It seems doubtful, given how people have trumpeted the user-supplied comments aspect of the PHP docs. From http Sat May 21 00:42:10 2005 From: http (Paul Rubin) Date: 20 May 2005 21:42:10 -0700 Subject: first release of PyPy References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116644536.741250.249860@g44g2000cwa.googlegroups.com> Message-ID: <7xoeb5favx.fsf@ruckus.brouhaha.com> Christian Tismer writes: > PyPy is just a completely new approach to interpreted languages, > almost based upon known compiler technology, but applying this in a > consequent manner, that has no comparable prior example. Is there a web page describing what's new? Compile-and-go interactive languages have been around for decades. From jonasmg at softhome.net Wed May 18 06:25:07 2005 From: jonasmg at softhome.net (Jonas Melian) Date: Wed, 18 May 2005 11:25:07 +0100 Subject: Python forum In-Reply-To: References: Message-ID: <428B1803.80509@softhome.net> Markus Weihs wrote: > > If you speak German, there is a forum at www.python-forum.de . > There is also an english one at http://python-forum.org/py/index.php, > but as you can see, there's not much traffic :-/ > There are few messages because they are not known. I believe that they would be due to add in the resources of python.org From admin at statcounter.com Sat May 14 21:41:16 2005 From: admin at statcounter.com (admin at statcounter.com) Date: Sun, 15 May 2005 01:41:16 UTC Subject: Paranoider Deutschenmoerder kommt in Psychiatrie Message-ID: Lese selbst: http://brandenburg.rz.fhtw-berlin.de/poetschke.html From fperez.net at gmail.com Wed May 11 17:27:25 2005 From: fperez.net at gmail.com (Fernando Perez) Date: Wed, 11 May 2005 15:27:25 -0600 Subject: Python Graphing Utilities. References: <-dadnS0X7IVccR3fRVn-uQ@entouch.net> <797fe3d405051010392c00011f@mail.gmail.com> <87psvycqej.fsf@wilson.rwth-aachen.de> <87mzr17flh.fsf@wilson.rwth-aachen.de> Message-ID: Torsten Bronger wrote: > Hall?chen! > > Fernando Perez writes: > >> [...] >> >> Well, it's true that the latex-type (called mathtext) support in >> matplotlib is not really up to par with true latex (kerning is off >> in places, mixed text/math doesn't work well, etc). I've been >> willing to live with it so far, but an alternative option is to >> use the PS backend and then play psfrag tricks. > > The problem is that mostly, you'll have a *lot* to substitute. > >> I've yet to experiment with it, but it might (with some additional >> handywork) give final results identical to those of the pslatex >> backend in gnuplot. > > What do you mean with this? Do you want to mimic TeX's quality as a > typesetter, or do you think the goal should be output in real LaTeX > format (like pslatex does)? The latter would be more useful in my > opinion, and much easier, too. Easier... psfrag tricks can be done right now, while full latex output requires writing a new matplotlib backend. It would certainly be a _great_ project, but not one I'm about to undertake, while it's reasonable for me to use psfrag to fix a few labels here and there to use proper latex. So while I agree with you that in the long run a latex backend would be ideal, as a stop-gap solution I can live with psfrag. >> [...] But there are a number of things it simply can't offer due >> to its design as a standalone program, which matplotlib (being a >> library/widget collection) can do much better. [...] I finally >> made the switch and I'm extremely happy. > > I'm not a fanatic Gnuplot user either. I use it for 11 years, and I > like exactly two things about it: its simplicity and the pslatex > backend. I think for my thesis I'll still use it, because its > integration in a batch process that builds my thesis is much easier > than to write Python programs. well, unless your batch process _is_ in python :) Mine was, so my make_plots.py was a single script, which ironically (for this discussion) was all gnuplot.py-based, since this was a few years ago. Cheers, f From phillip.watts at anvilcom.com Tue May 3 12:09:10 2005 From: phillip.watts at anvilcom.com (phil) Date: Tue, 03 May 2005 11:09:10 -0500 Subject: How To Reply Message-ID: <4277A226.9020403@anvilcom.com> I get a digest several times a day. When I wish to respond to an item I must cut and paste the item and the subject line. Is there something to click on for a simple reply? Using an old mozilla mail. Thanks From rkern at ucsd.edu Wed May 11 18:18:36 2005 From: rkern at ucsd.edu (Robert Kern) Date: Wed, 11 May 2005 15:18:36 -0700 Subject: Finding startup files In-Reply-To: <200505111807.16833.jeffelkins@earthlink.net> References: <1115829176.541687.22090@z14g2000cwz.googlegroups.com> <1184dj36mp5sdc6@corp.supernews.com> <200505111807.16833.jeffelkins@earthlink.net> Message-ID: jeff elkins wrote: > On Wednesday 11 May 2005 04:44 pm, Grant Edwards wrote: > >>On 2005-05-11, hemagician at gmail.com wrote: >> >>>The following script demonstrates a method that should work for you. I >>>believe it is entirely cross-platform. >>> >>>#! /usr/bin/python >>> >>>import sys >>>import os >>> >>>print os.path.abspath(os.path.dirname(sys.argv[0])) >> >>That will probably work most of the time, but... >> >> 1) you're not gauranteed that argv[0] contains the application >> path/filename. >> >> 2) the directory containing the executable is not where >> configuration files are supposed to be stored under >> Unix/Linux. > > Thanks Grant, > > I live and develop in Linux, but unfortunately, 99.99% of the users of this > particular application (analysis of medical laboratory data) will be working > with Windows. > > I'm totally new to Python (obvious,yes?) so how might argv[0] fail? If I make a symbolic link to the executable script and run it using that link, sys.argv[0] will give the filename of that link, not the real file it points to. -- Robert Kern rkern at ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter From pc at p-cos.net Thu May 26 03:33:04 2005 From: pc at p-cos.net (Pascal Costanza) Date: Thu, 26 May 2005 09:33:04 +0200 Subject: What are OOP's Jargons and Complexities? In-Reply-To: <2225581.h9zeA6l3zh@yahoo.com> References: <1116843761.619249.144790@g47g2000cwa.googlegroups.com> <3584469.Aerji1NdQr@yahoo.com> <2225581.h9zeA6l3zh@yahoo.com> Message-ID: <3flcdiF8c343U1@individual.net> alex goldman wrote: > John McGrath wrote: > >>Unfortunately, there is no >>consensus as to what the term means. > > If the language allows the programmer to write programs from the 'slack' > domain, by saying "just trust me on this", then it's not strongly typed. > > What other meanings are there? I wasn't aware of the lack of consensus. There is a difference between getting a core dump when you invoke undefined behavior on some object, or just getting an exception. You can programmatically react to an exception to do something meaningful but not to a core dump. Some people use the term weak typing to refer to languages that potentially core dump whereas they use the term strong typing for languages that don't. Pascal -- 2nd European Lisp and Scheme Workshop July 26 - Glasgow, Scotland - co-located with ECOOP 2005 http://lisp-ecoop05.bknr.net/ From bokr at oz.net Sat May 7 12:48:27 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 07 May 2005 16:48:27 GMT Subject: Need help subclassing Borg References: Message-ID: <427ce14c.916411409@news.oz.net> On Sat, 07 May 2005 22:28:34 +1000, Steven D'Aprano wrote: >I've been working with the Borg design pattern from here: >http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 > >and I'm having problems subclassing it. > >I'm a newbie, so I've probably missed something obvious. > >I want two Borg-like classes where all instances share state within each >class, but not between them. This is what I tried: > >py> class Borg: >py> _shared_state = {} >py> def __init__(self): >py> self.__dict__ = self._shared_state >py> >py> class Duck(Borg): >py> def __init__(self): >py> Borg.__init__(self) >py> self.covering = "feathers" # all ducks are feathered >py> >py> class Rabbit(Borg): >py> def __init__(self): >py> Borg.__init__(self) >py> self.covering = "fur" # all rabbits are furry >py> >py> bugs = Bunny(); daffy = Duck() >py> daffy.covering >'feathers' >py> bugs.covering >'feathers' > >Not what I wanted or expected. What I wanted was for the subclasses Rabbit >and Duck to each inherit Borg-like behaviour, but not to share state with >any other Borgs. In other words, all Ducks share state, and all Rabbits >share state, but Ducks and Rabbits do not share state with each other. > >I now see why Ducks and Rabbits are sharing state: they both share the >same __dict__ as all Borg instances. But I don't see how to get the >behaviour I want. (Except by cutting and pasting the Borg code into each >one.) Can anyone help? > If you are using old-style classes (which you need for this Borg), then you could keep different shared state dicts within a _shared_states dict, e.g. based on the name of the subclassed classes, e.g., >>> class Borg: ... _shared_states = {} #note plural ... def __init__(self): ... self.__dict__ = self._shared_states.setdefault(self.__class__.__name__, {}) ... >>> class Duck(Borg): ... def __init__(self): ... Borg.__init__(self) ... self.covering = "feathers" # all ducks are feathered ... >>> class Rabbit(Borg): ... def __init__(self): ... Borg.__init__(self) ... self.covering = "fur" # all rabbits are furry ... >>> bugs = Bunny(); daffy = Duck() Traceback (most recent call last): File "", line 1, in ? NameError: name 'Bunny' is not defined Hm, where'd that Bunny come from? >>> bugs = Rabbit(); daffy = Duck() >>> daffy.covering 'feathers' >>> bugs.covering 'fur' >>> vars(Borg) {'__module__': '__main__', '__doc__': None, '__init__': , '_sha red_states': {'Rabbit': {'covering': 'fur'}, 'Duck': {'covering': 'feathers'}}} >>> donald = Duck() >>> donald.covering 'feathers' >>> roger = Rabbit() >>> roger.covering 'fur' >>> Borg._shared_states['Duck'] {'covering': 'feathers'} >>> Borg._shared_states['Rabbit'] {'covering': 'fur'} Since you are calling Borg.__init__(self), you could specify some other classifier than the implicit class name, e.g., Borg.__init__(self, 'feathered') vs Borg.__init__(self, 'furred') and use that as the key in the setdefault call. As mentioned in the recipe discussion, new style classes differ somewhat, but you can accomplish the same functionality, just that if you have special things like __slots__ or descriptors, you may have to think about how they might interact with your shared state access. Regards, Bengt Richter From aa at hanmail.net Mon May 30 00:18:01 2005 From: aa at hanmail.net (Çϳª·Î) Date: Mon, 30 May 2005 13:18:01 +0900 Subject: test from hanaro sorry Message-ID: From peter at engcorp.com Tue May 10 09:16:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 May 2005 09:16:51 -0400 Subject: The first programming riddle on the net. Python-challenge In-Reply-To: References: Message-ID: Sara Khalatbari wrote: > Hey guys! > Thanks for helping me find time&date. > > Have you seen this? > This is the first programming riddle on the net with > 20 levels! > > http://www.pythonchallenge.com/ Yes, there's been "a bit" of discussion since this was announced a week or two ago: http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7a755219ea1a5cec/7c98f7717c030b12?q=riddle&hl=en#7c98f7717c030b12 From jasondrew72 at gmail.com Fri May 20 13:07:55 2005 From: jasondrew72 at gmail.com (Jason Drew) Date: 20 May 2005 10:07:55 -0700 Subject: Convert from numbers to letters In-Reply-To: <6_udnUizapsdnhPfRVn-vw@comcast.com> References: <1116511005.900715.107260@o13g2000cwo.googlegroups.com> <1116519193.037429.93560@o13g2000cwo.googlegroups.com> <1116529140.470352.129690@z14g2000cwz.googlegroups.com> <1116535087.901874.167870@g43g2000cwa.googlegroups.com> <1116541217.303770.314860@f14g2000cwb.googlegroups.com> <1116596845.792019.40340@g14g2000cwa.googlegroups.com> <6_udnUizapsdnhPfRVn-vw@comcast.com> Message-ID: <1116608875.145410.308690@g14g2000cwa.googlegroups.com> Hey, that's good. Thanks Steve. Hadn't seen it before. One to use. Funny that Pythonwin's argument-prompter (or whatever that feature is called) doesn't seem to like it. E.g. if I have def f(tupl): print tupl Then at the Pythonwin prompt when I type f( I correctly get "(tupl)" in the argument list pop-up box. But if I have def f((a, b)): print a, b then when I type f( I just get "(.0)" in the argument list pop-up box. Or with def f(p, q, (a, b)): pass Pythonwin prompts with "(p, q, .4)" However in each case the help() function correctly lists all the arguments. Strange. I'll check if it's a known "feature". This is with "PythonWin 2.4 (#60, Feb 9 2005, 19:03:27) [MSC v.1310 32 bit (Intel)] on win32." From jean_seb at videotron.ca Tue May 17 11:49:36 2005 From: jean_seb at videotron.ca (=?ISO-8859-1?Q?Jean-S=E9bastien_Guay?=) Date: Tue, 17 May 2005 11:49:36 -0400 Subject: Problem listing services with wmi In-Reply-To: <9A28C052FF32734DACB0A288A3533991EBB815@vogbs009.gb.vo.local> References: <9A28C052FF32734DACB0A288A3533991EBB815@vogbs009.gb.vo.local> Message-ID: <428A1290.8050607@videotron.ca> Hello Tim, thanks for replying, >For your >information, what the code is doing behind the scenes is the following: > > > >import win32com.client > >c = win32com.client.GetObject ( > "winmgmts:{impersonationLevel=Impersonate,authenticationLevel=Default}/root/cimv2" >) >for service in c.ExecQuery ("SELECT * FROM Win32_Service"): > if service.Properties_ ("State").Value == "Stopped": > print service.Properties_ ("Caption").Value > print service.Properties_ ("State").Value > > > > Running this code seems to go through the 87 first services in the list returned by ExecQuery, then stops with the following error : Traceback (most recent call last): File "", line 1, in ? File "G:\Python-2.4\Lib\site-packages\win32com\client\util.py", line 83, in next return _get_good_object_(self._iter_.next()) pywintypes.com_error: (-2147217398, 'OLE error 0x8004100a', None, None) Could there be such a thing as a "null pointer" in the list at position 88? Or is that not possible in Python? Would the iterator just stop at a null value? As I said, I'm pretty new to Python so I'm just throwing around ideas here. > > >set wmi = GetObject ("winmgmts:{impersonationLevel=impersonate}") >set ServiceSet = wmi.InstancesOf ("Win32_Service") >for each Service in ServiceSet > WScript.Echo Service.Description >Next > > > > This gives me the first 87 services as well, and then stops with this message : C:\Documents and Settings\guayj\Desktop\bob.vbs(7, 1) (null): 0x8004100A So it would seem that the 3 methods give the same result. As to which service it has gotten to when it gets to position 88 in the list, obviously I can't find out with a script, and it seems that the list isn't in any order I can see, so I couldn't even venture a guess... I'll try looking if there's a service in my list that isn't valid (points to an uninstalled program for example) or something like that... But if you have other ideas please let me know. >PS I realise that by now you've probably moved on from >this approach, but if you did manage to pin down a problem >we could address, I'd be very glad to address it. > > Not at all, this is a small project I'm using to try and learn Python... I'm currently on summer break before I start my Masters, so I have the luxury of keeping this on the back burner until I find a fix... Thanks for your help! J-S -- ___________________________________________ Jean-S?bastien Guay jean_seb at videotron.ca http://whitestar02.webhop.org/ From rambam at bigpond.net.au Sat May 7 20:23:35 2005 From: rambam at bigpond.net.au (vermicule) Date: Sun, 08 May 2005 00:23:35 GMT Subject: Language documentation ( was Re: Computing Industry shams) References: <1115509201.680334.140840@f14g2000cwb.googlegroups.com> Message-ID: <874qdezh76.fsf@kafka.homenet> "Xah Lee" writes: > A|B, where A and B can be arbitrary REs, creates a regular expression > that will match either A or B. An arbitrary number of REs can be > separated by the "|" in this way. This can be used inside groups (see > below) as well. As the target string is scanned, REs separated by "|" > are tried from left to right. When one pattern completely matches, that > branch is accepted. This means that once A matches, B will not be > tested further, even if it would produce a longer overall match. In > other words, the "|" operator is never greedy. To match a literal "|", > use \|, or enclose it inside a character class, as in [|]. > > --end quote-- > > Note: In other words, the "|" operator is never greedy. > > Note the need to inject the high-brow jargon "greedy"here as a > latch on sentence. What is so hard to understand ? Should be perfectly clear even to a first year undergraduate. As for "greedy" even a minimal exposure to Djikstra's shortest path algorithm would have made the concept intuitive. And from memory, that is the sort of thing done in Computing 101 and in Data Structures and Algorithms 101 It seems to me that you want the Python doc to be written for morons. And that is not a valid complaint. From gigi-s at bigfoot.com Mon May 30 12:12:56 2005 From: gigi-s at bigfoot.com (Gigi) Date: Mon, 30 May 2005 09:12:56 -0700 Subject: __getattribute__ and __getattr__ In-Reply-To: References: Message-ID: <429B3B88.3080401@bigfoot.com> Terry Reedy wrote: > "Gigi" wrote in message > news:d7dgd4$29v$1 at sea.gmane.org... > >>Hi, >>In the Python documentation regarding __getattribute__ (more attribute >>access for new style classes) it is mentioned that if __getattribute__ >>is defined __getattr__ will never be called (unless called explicitely). >>Here is the exact citation: > > > Discrepancy reported in > > https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1204734&group_id=5470 > > Guido declared behavior right and doc wrong and in need of correction. > > Terry J. Reedy > > > Thanks for your reply. It definitely clears the issue. I'm writing an article to Dr. Dobbs about the Python object model and I wouldn't want to be inaccurate. I fill a little like Leibnitz :-) . It's a curious coincidence that two separate people notice the same documentation issue that lingere for such a long time in such a short time span. Thanks, Gigi From alainpoint at yahoo.fr Tue May 17 07:58:33 2005 From: alainpoint at yahoo.fr (alainpoint at yahoo.fr) Date: 17 May 2005 04:58:33 -0700 Subject: Bug in Elementtree/Expat Message-ID: <1116331113.765085.281490@g47g2000cwa.googlegroups.com> Hello, I use Elementtree to parse an elementary SVG file (in fact, it is one of the examples in the "SVG essentials" book). More precisely, it is the fig0201.svg file in the second chapter. The contents of the file are as follows (i hope it will be rendered correctly): Default User Coordinates Shows a rectangle on a grid in default user coordinates The parsing fails in the following way: Traceback (most recent call last): File "C:\privatedata\myapp.py", line 60, in ? root = ElementTree(file=infile).getroot() File "c:\python23\lib\site-packages\elementtree\ElementTree.py", line 554, in __init__ self.parse(file) File "c:\python23\lib\site-packages\elementtree\ElementTree.py", line 594, in parse parser.feed(data) File "c:\python23\lib\site-packages\elementtree\ElementTree.py", line 1171, in feed self._parser.Parse(data, 0) xml.parsers.expat.ExpatError: unbound prefix: line 6, column 1 The problem seems to lie with the xlink:href tag. If i remove the xlink namespace, it then does not produce a traceback. Thank you for helping Alain From xah at xahlee.org Fri May 13 05:52:34 2005 From: xah at xahlee.org (Xah Lee) Date: 13 May 2005 02:52:34 -0700 Subject: function with variable arguments Message-ID: <1115977954.266898.141150@g49g2000cwa.googlegroups.com> i wanted to define a function where the number of argument matters. Example: def Range(n): return range(n+1) def Range(n,m): return range(n,m+1) def Range(n,m,step): return range(n,m+1,step) this obvious doesn't work. The default argument like Range(n=1,m,step=1) obviously isn't a solution. can this be done in Python? or, must the args be changed to a list? Xah xah at xahlee.org ? http://xahlee.org/ From pyguy2 at gmail.com Wed May 25 17:16:42 2005 From: pyguy2 at gmail.com (pyguy2 at gmail.com) Date: 25 May 2005 14:16:42 -0700 Subject: SSL (HTTPS) with 2.4 In-Reply-To: <1116808438.811166.49180@g49g2000cwa.googlegroups.com> References: <1116392416.139727.84630@g49g2000cwa.googlegroups.com> <428AD4D1.8030405@v.loewis.de> <1116396878.995648.206820@g49g2000cwa.googlegroups.com> <1116406256.213128.68180@f14g2000cwb.googlegroups.com> <1116422715.320683.228810@g49g2000cwa.googlegroups.com> <1116424363.953180.79260@g47g2000cwa.googlegroups.com> <1116424660.917136.79680@g47g2000cwa.googlegroups.com> <428b7bc5$0$7346$9b622d9e@news.freenet.de> <1116463961.944713.210860@g49g2000cwa.googlegroups.com> <1116524774.606167.98240@f14g2000cwb.googlegroups.com> <1116550788.207740.171780@o13g2000cwo.googlegroups.com> <1116627976.845517.268370@z14g2000cwz.googlegroups.com> <1116808438.811166.49180@g49g2000cwa.googlegroups.com> Message-ID: <1117055802.770863.195480@g14g2000cwa.googlegroups.com> After failed attempts at trying to get my code to work with squid. I did some research into this and came up with some info. http://www.python.org/peps/pep-0320.txt "- It would be nice if the built-in SSL socket type could be used for non-blocking SSL I/O. Currently packages such as Twisted which implement async servers using SSL have to require third-party packages such as pyopenssl. " My guess is that the squid proxy server uses non-blocking sockets which python ssl does not support. And, of course after looking at the squid site, I found this: "Unlike traditional caching software, Squid handles all requests in a single, non-blocking, I/O-driven process." Now, I haven't had time to verify this. But, it can explain why the non-ssl proxy authentication works and the ssl partially works. And, also why I get success with a different type of proxy server. For a clue as to why there is this problem I would also recommend looking at http://www.openssl.org/support/faq.html, specifically the section on non-blocking i/o. It looks like pyopenssl would be an option: http://pyopenssl.sourceforge.net/ It's docs comment that it was written because m2crypto error handeling was not finished for non-blocking i/o: http://pyopenssl.sourceforge.net/pyOpenSSL.txt The reason this module exists at all is that the SSL support in the socket module in the Python 2.1 distribution (which is what we used, of course I cannot speak for later versions) is severely limited. When asking about SSL on the comp.lang.python newsgroup (or on python-list at python.org) people usually pointed you to the M2Crypto package. The M2Crypto.SSL module does implement a lot of OpenSSL's functionality but unfortunately its error handling system does not seem to be finished, especially for non-blocking I/O. I think that much of the reason for this is that M2Crypto^1 is developed using SWIG^2. This makes it awkward to create functions that e.g. can return both an integer and NULL since (as far as I know) you basically write C functions and SWIG makes wrapper functions that parses the Python argument list and calls your C function, and finally transforms your return value to a Python object. john From rhall at thiess.com.au Thu May 19 03:35:33 2005 From: rhall at thiess.com.au (Bloke) Date: 19 May 2005 00:35:33 -0700 Subject: urllib2 EOF occurred in violation of protocol with proxy Message-ID: <1116488133.633861.169860@g49g2000cwa.googlegroups.com> I want to connect to a https server through an authenticating proxy like this: import urllib2 proxy_info = { 'user' : 'me', 'pass' : 'password', 'host' : 'mycompany.com.au', 'port' : 8008 } # build a new opener that uses a proxy requiring authorization proxy_support = urllib2.ProxyHandler({"https":"https://%(user)s:% (pass)s@%(host)s:%(port)d" % proxy_info}) opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler) # install it urllib2.install_opener(opener) # use it f = urllib2.urlopen('https://www.securewebsite.com.au') print f.headers print f.read() f.close() If I modify the 'https' to 'http' it works fine. But in https mode it returns: URLError: The site works fine if I do not go through the proxy, so it appears the proxy is not returning an EOF. I been searching for an answer, and found many other sites where people have had the same problem. Some have suggested m2crypto. Is there a work around using the standard 2.4.1 installation? From peter at engcorp.com Tue May 10 11:41:51 2005 From: peter at engcorp.com (Peter Hansen) Date: Tue, 10 May 2005 11:41:51 -0400 Subject: Library Naming Conventions. In-Reply-To: <1115739023.302545.109300@o13g2000cwo.googlegroups.com> References: <1114851378.781754.194030@z14g2000cwz.googlegroups.com> <1114860766.488589.152380@o13g2000cwo.googlegroups.com> <1115739023.302545.109300@o13g2000cwo.googlegroups.com> Message-ID: chris.lyon at spritenote.co.uk wrote: > quoting: > > Modules should have short, lowercase names, without underscores. > > this still doesn't explain Cookie. Sure it does. The subject line says "conventions", and a convention isn't a firm rule, just something many people agree on. Obviously the author of Cookie has different preferences. Nobody is bound by a convention. The PEP describes what is widespread but not universal preference, that's all. -Peter From dan at dontspammecauseidontlikit.com Thu May 5 05:11:08 2005 From: dan at dontspammecauseidontlikit.com (Dan) Date: Thu, 05 May 2005 17:11:08 +0800 Subject: Sockets Message-ID: <7nnj71thsiv0pnd316imovuobnbbeqnjrq@4ax.com> I have a problem and I don't quite know how to implement the solution. I'll have a server application that will listen on a tcp port and make many similtaneous connections to remote clients. From time to time, I'll need to write a small amount of data on one of those sockets. A notification to write to one of the sockets will come from another program/process. I think that the best way to send the notification to this server application is via a udp message. Alternatively, I could use tcp, but I don't think I'll need the extra complexity for what I want to do. (Other suggestions welcome.) The server application will multiplex the connections using 'select', so much of the time it will be blocked on 'select'. My problem is how to also listen on a udp port while the process is blocked by 'select'. Should I run a separate thread? And if so can I share the socket connection across the two threads? (Thread 1 will be accepting client connections, thread 2 will we writing data to it.) Or should I simply let 'select' time out after some period? I'm a bit lost as to how to do this, I hope someone can put me on the right track. Any solution that I use should be applicable on Linux and Windows platforms. Thanks Dan From peter at engcorp.com Fri May 13 14:43:44 2005 From: peter at engcorp.com (Peter Hansen) Date: Fri, 13 May 2005 14:43:44 -0400 Subject: stop a thread safetely In-Reply-To: References: Message-ID: Ivan Voras wrote: > Peter Hansen wrote: > >> call to recv() does not guarantee that the full 608 bytes of data is > > Does read() have that guarantee? Assuming you mean read() on the file object that would be returned by calling makefile() on the socket, then the docs imply that this is the case, but I wouldn't call that a "guarantee". Someone who knows the inner workings might have a comment on that (in which case it might make a good patch to the docs to clarify this issue...). -Peter From gsakkis at rutgers.edu Sun May 1 07:59:17 2005 From: gsakkis at rutgers.edu (George Sakkis) Date: 1 May 2005 04:59:17 -0700 Subject: Numeric/Numarray equivalent to zip ? References: <1114849922.518669.105590@l41g2000cwc.googlegroups.com> Message-ID: <1114948757.585835.8180@z14g2000cwz.googlegroups.com> "Peter Otten" <__peter__ at web.de> wrote: > George Sakkis wrote: > > > What's the fastest and most elegant equivalent of zip() in > > Numeric/Numarray between two equally sized 1D arrays ? That is, how to > > combine two (N,)-shaped arrays to one (N,2) (or (2,N)) shaped ? I > > expect the fastest and the most elegant idiom to be identical, as it is > > usually the case in this excellent library, but if not, both would be > > useful to know. Thanks, > > >>> import Numeric as nu > >>> a = nu.array(range(3)) > >>> nu.array([a, a]) > array([[0, 1, 2], > [0, 1, 2]]) > >>> nu.transpose(nu.array([a, a])) > array([[0, 0], > [1, 1], > [2, 2]]) > > Or am I missing something? As to speed, it seems to be the fastest to > write... Though not the fastest to execute; using concatenate instead of initializing an array from a list [a,a] is more than 2,5 time faster in my system (~4.6 vs 11.8 usec per loop according to timeit.py), and it's not harder either. One difference is that the equivalent expression for concatenate expects arrays of shape (1,len(a)) instead of 1D arrays os shape (len(a),): >>> a = reshape(range(5), (1,5)) >>> a array([ [0, 1, 2, 3, 4]]) >>> concatenate((a,a)) array([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]) George From slick_mick_00 at hotmail.com Sat May 28 09:24:19 2005 From: slick_mick_00 at hotmail.com (Michael) Date: Sat, 28 May 2005 13:24:19 +0000 (UTC) Subject: Is there a better way of doing this? Message-ID: Hi, I'm fairly new at Python, and have the following code that works but isn't very concise, is there a better way of writing it?? It seems much more lengthy than python code i have read..... :-) (takes a C++ block and extracts the namespaces from it) def ExtractNamespaces(data): print("Extracting Namespaces") p = re.compile( 'namespace (?P[\w]*)[\n\t ]*{') subNamespaces = [] newNS = p.search(data) while( newNS ): print "\t" + newNS.group("name") OPCount = 1 Offset = newNS.end() while(OPCount > 0): if( data[Offset] == "}" ): OPCount = OPCount -1; elif( data[Offset] == "{" ): OPCount = OPCount + 1; Offset = Offset+1; #Extract Data: newNSData = data[newNS.end():Offset-1] data = data[0:newNS.start()] + data[Offset:] newNamespace = [newNS.group("name"), newNSData]; subNamespaces.append(newNamespace) #Perform NewSearch newNS = p.search(data) return [subNamespaces,data] From superprad at gmail.com Tue May 31 19:55:21 2005 From: superprad at gmail.com (superprad at gmail.com) Date: 31 May 2005 16:55:21 -0700 Subject: Swig compile errors Message-ID: <1117583720.968040.230380@g47g2000cwa.googlegroups.com> Hi I am trying to write a python wrapper for a C code I have using swig. when i try to compile the _wrap.c i get a bunch of these warnings and errors can anyone help Steps I followed : $swig -python test_hk.c this generates test_hk.py and test_hk_wrap.c then i compile it as $gcc -Wall -std=c99 test_hk.c test_hk_wrap.c -I/usr/include/python2.3/ /usr/lib/gcc-lib/i486-linux/3.3.5/../../../crt1.o(.text+0x18): In function `_start': ../sysdeps/i386/elf/start.S:98: undefined reference to `main' /tmp/ccayOWVb.o(.text+0xb6f): In function `PySwigObject_repr': : undefined reference to `PyString_FromFormat' /tmp/ccayOWVb.o(.text+0xbe1): In function `PySwigObject_str': : undefined reference to `PyString_FromString' /tmp/ccayOWVb.o(.text+0xc22): In function `PySwigObject_long': : undefined reference to `PyLong_FromUnsignedLong' /tmp/ccayOWVb.o(.text+0xc87): In function `PySwigObject_oct': : undefined reference to `PyOS_snprintf' and a bunch of them.............. : undefined reference to `PyModule_GetDict' collect2: ld returned 1 exit status do I have to include any libraries or whats it that I am missing. From meh1963 at gmail.com Wed May 11 13:28:04 2005 From: meh1963 at gmail.com (Matt Hayden) Date: 11 May 2005 10:28:04 -0700 Subject: Jesus said, "I am the way, the truth and the life: no one can come to the Father(God)(in Heaven), but by me." (John 14:6) This means that if you die without trusting in Jesus Christ as your Lord and Saviour you will die in your sins and be forever sepa In-Reply-To: <3eeta6F2m45kU1@individual.net> References: <1115824563.613661.169620@g47g2000cwa.googlegroups.com> <3eeta6F2m45kU1@individual.net> Message-ID: <1115832484.237918.53830@o13g2000cwo.googlegroups.com> MC05 wrote: > "don freeman" wrote in message > news:M%qge.1317047$Xk.244810 at pd7tw3no... > > The truth is, Jesus should never have torn down the fig tree. He got so > > pissed off at the fig tree for not having figs, even though it wasn't > > fig season. This was not the action of someone who has even a little > > truth and light. > > > > Imagine if Jesus came back now. I'd hate to see his road rage. > > I'm sure he'd drive fine. > > But if a fig tree pulled in front of him.......woof!! > > What if a fig leaf pulled off in front of him? From pdemb at gazeta.pl Mon May 16 12:30:47 2005 From: pdemb at gazeta.pl (Peter Dembinski) Date: Mon, 16 May 2005 18:30:47 +0200 Subject: question about the id() References: <428809fc.62d7a08a.1cfe.ffffd7ef@mx.gmail.com> Message-ID: <873bsnxhe0.fsf@hector.domek> Skip Montanaro writes: > kyo> Can someone explain why the id() return the same value, and > kyo> why these values are changing? > > Instance methods are created on-the-fly. So, the interpreter creates new 'point in address space' every time there is object-dot-method invocation in program? -- http://www.peter.dembinski.prv.pl From bokr at oz.net Sat May 14 16:27:48 2005 From: bokr at oz.net (Bengt Richter) Date: Sat, 14 May 2005 20:27:48 GMT Subject: A new to Python question References: <1116088663.428932.130860@g43g2000cwa.googlegroups.com> <1116093118.599403.35940@g14g2000cwa.googlegroups.com> <26thl2-5q5.ln1@Bernd.Nawothnig.dialin.t-online.de> Message-ID: <42865bd1.173398754@news.oz.net> On Sat, 14 May 2005 20:38:26 +0200, Bernd Nawothnig wrote: > >> On 2005-05-14, M.E.Farmer wrote: > >> (x,y,dotp,sumx,maxv) = abc(x,y,dotp,sumx,maxv) >> This will only create a tuple in memory that has no name to reference >> it by! > >Maybe. But it does not seem to hurt. And I am not sure the tupel _is_ >really created in that situation. > One way to get insight into what a statement does is to disassemble its code, e.g., >>> import dis >>> dis.dis(compile('(x,y,dotp,sumx,maxv) = abc(x,y,dotp,sumx,maxv)','','exec')) 1 0 LOAD_NAME 0 (abc) 3 LOAD_NAME 1 (x) 6 LOAD_NAME 2 (y) 9 LOAD_NAME 3 (dotp) 12 LOAD_NAME 4 (sumx) 15 LOAD_NAME 5 (maxv) 18 CALL_FUNCTION 5 21 UNPACK_SEQUENCE 5 24 STORE_NAME 1 (x) 27 STORE_NAME 2 (y) 30 STORE_NAME 3 (dotp) 33 STORE_NAME 4 (sumx) 36 STORE_NAME 5 (maxv) 39 LOAD_CONST 0 (None) 42 RETURN_VALUE In the context of a function or module scope, those loads and stores will change to optimized byte code ops like LOAD_FAST and STORE_FAST etc, but you can see what's happening above. I.e., on return from the function call, the returned sequence (we know it's a tuple in your example, but it could be some other sequence thing) is upacked and its elements are bound to the individual names, just as individual "assignments" would do. Regards, Bengt Richter From peter at engcorp.com Thu May 19 09:52:39 2005 From: peter at engcorp.com (Peter Hansen) Date: Thu, 19 May 2005 09:52:39 -0400 Subject: socket programming and port scans In-Reply-To: References: Message-ID: rbt wrote: > I don't fully understand sockets, I just know enough to be dangerous. > The below is not detected by nmap, but is affected by iptables or ipsec. > Can anyone explain why that is? > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((ip_param, port_param)) > while 1: > s.listen(5) This, by the way, is wrong. s.listen(5) just tells the stack that you would like to allow a backlog of up to 5 waiting-to-be-connected connection attempts while you are accepting another. The call doesn't block and needn't be called repeatedly. You could just as well do the call to listen first, then have an empty "while 1: pass" loop (but note that in either case it is a "busy wait", consuming 100% CPU while it runs). What you are looking for is more like this: s.listen(5) while 1: s.accept() # wait for connection, and ignore it If you want to simulate a little server to allow multiple connections, you would of course need to use the value returned by accept() and probably call close() on the client socket right away. -Peter From combinational.logic at soc-ip.com Fri May 27 13:36:33 2005 From: combinational.logic at soc-ip.com (combinational.logic $ soc-ip.com) Date: 27 May 2005 10:36:33 -0700 Subject: Inheritance, polymorphism, and introspection in Python Message-ID: <1117215393.387579.121910@g43g2000cwa.googlegroups.com> The following website (http://www.soc-ip.com/weblog) has an example of inheritance, polymorphism, and introspection in Python. The example shows a simple classification system for microprocessors. Hopefully someone will find this interesting / useful. From utabintarbo at gmail.com Sat May 7 18:27:58 2005 From: utabintarbo at gmail.com (utabintarbo at gmail.com) Date: 7 May 2005 15:27:58 -0700 Subject: globbing multiple wildcards In-Reply-To: <1115481354.357281.240920@g14g2000cwa.googlegroups.com> References: <1115477662.937084.260270@g14g2000cwa.googlegroups.com> <1115481354.357281.240920@g14g2000cwa.googlegroups.com> Message-ID: <1115504878.558146.327440@f14g2000cwb.googlegroups.com> Is there any way to make this recursive? That is what I was looking for. Sorry I wasn't too clear before. Bob From kraus at hagen-partner.de Fri May 27 09:20:23 2005 From: kraus at hagen-partner.de (Wolfram Kraus) Date: Fri, 27 May 2005 15:20:23 +0200 Subject: Strings for a newbie In-Reply-To: References: <42970d69@news.eftel.com> <42971235.9000805@lexicon.net> Message-ID: Malcolm Wooden wrote: > my actual code is: > > for x in range(len(l)): > h = string.split(l[x]) > > where the sentence string is in an array of one element 'l' > Error is: > > Traceback (most recent call last): > File "", line 34, in ? > File "", line 27, in SentenceText > File "C:\PYTHON22\lib\string.py", line 122, in split > return s.split(sep, maxsplit) > AttributeError: 'list' object has no attribute 'split' > What is l[x]? Are you sure that l[x] is a string? Do a print before the split to see what l[x] is. Oh, and no need for range here, if l is a list: for x in l: print x h = x.split() HTH, Wolfram From tzot at sil-tec.gr Tue May 17 10:15:33 2005 From: tzot at sil-tec.gr (Christos TZOTZIOY Georgiou) Date: Tue, 17 May 2005 17:15:33 +0300 Subject: Python on a public library computer References: <1116069664.779281.320540@g47g2000cwa.googlegroups.com> Message-ID: On 14 May 2005 04:21:04 -0700, rumours say that "anton.vredegoor at gmail.com" might have written: >I'm typing this in a public library on a computer with OS windows 2000 >server. I can run Internet explorer, word, excel and powerpoint, that's >it. Maybe java, but it seems to be flaky. > >I want to run python scripts from this computer. I am not sure I will help you (uncertainty based on the part I snipped), but the part so far can be easilly solved if you install Python for single user inside the "Documents and settings\" folder (or whatever it is called). I did in a similar case. End of reply here; and now for some completely minor python success story. Some months ago, I happened to be for full workdays at a client's site, with strict security rules enforced (no domain login == no access even to web proxy) but I needed to access my company's internal mail server from my laptop (which I do by ssh forwarding usually). I could plug in my laptop to their network, get an address, but that was all (local network access only). So I asked permission from an employee there (working on a computer logged on to the domain) if I could run a putty session with forwarding enabled. He said he'd ask their BOFH; now, the BOFH was strictly a windows person (I somehow connect "strictly- persons" with lack of resourcefulness, as if these people have 7 bits per byte :), and he thought that my case was hopeless, since the employee's account had only access to a web proxy, and CONNECT requests were only allowed to port 443, but he said ok anyway (in his place, I wouldn't; but then again, what do I know? ;). After a call to a colleague in order to redirect connections to port 443 (from the client's network) of an underused computer at my site to port 22, I set up putty to connect through their web proxy, but that didn't work (since no authentication was given as requested). Then it was that I downloaded python, installed it in the employee's documents folder, and created a 'sniffer' between the web browser and web proxy to find out the authentication headers. After testing them by hand, I wrote a script to pretend it's the web browser requesting a CONNECT from the web proxy, and putty would connect to my script which would just pass data back and forth. It didn't work. I quickly found out that their web proxy did NOT let anything come and go, unless its client had sent at least 4 octets (and that was also a security measure they had taken which I was not told about-- they wanted only protocols where the client talks first, ie (pun intended) typically HTTP). So putty was waiting for the ssh server to announce its version before announcing itself, but the announcement of the server would not come through until putty sent something. So I changed the middle-server [midsrv]: as soon as putty connected to the listening port of midsrv, it opened the connection to the web proxy, and instantly sent the putty announcement to the ssh server, consuming it when putty sent it normally, and happily moving octets around for the rest of the connection. From my laptop, I could get my emails with plain POP3. That was in 34 minutes time (debugging time included). When the network guy dropped by a couple of hours later to ask me if I needed any help, I just thanked him for letting me connect. He scratched his head, tried to understand what happened (didn't realise that the python app was important even though he absent-mindedly passed over it checking running tasks), so I let him think over it for several minutes before explaining to him what I did. He was most impressed with the python program when I showed it to him, gave a warning to the employee: "ok, run his program, but don't let him touch your computer again!", and then came to the following conclusion (much similar to a Python motto): "If Python can do this, it {Python} should be forbidden..." PS Unfortunately, I could not charge "security consulting" fees. -- TZOTZIOY, I speak England very best. "Be strict when sending and tolerant when receiving." (from RFC1958) I really should keep that in mind when talking with people, actually... From f.geiger at vol.at Fri May 27 15:29:46 2005 From: f.geiger at vol.at (F. GEIGER) Date: Fri, 27 May 2005 21:29:46 +0200 Subject: [pysqlite 2.0.2] UnicodeDecodeError: 'utf8' codec can't decode bytes in position 44-45: invalid data Message-ID: A fetchall() call causes the above error. There must be some non-utf8 chars in the table in question and - indeed - there very likely are: The table contains pathnames of files on the harddisk of a German "speaking" PC. What I have already done to try to overcome this is: - Inserted "# coding: iso-8859-1" (w/o the quotes) in (hopefully) every file of my project - All strings I could find prefixed with "u" (w/o the quotes) - Changed plain calls to execute(q) into execute(unicode(q)) Alas, I am not sure if this all makes really sense, and, obviously it doesn't. What else has to be done? Many thanks in advance and kind regards Franz GEIGER From tismer at stackless.com Sat May 21 00:20:51 2005 From: tismer at stackless.com (Christian Tismer) Date: Sat, 21 May 2005 06:20:51 +0200 Subject: first release of PyPy In-Reply-To: <1116644536.741250.249860@g44g2000cwa.googlegroups.com> References: <1116629407.638782.145950@g47g2000cwa.googlegroups.com> <1116644536.741250.249860@g44g2000cwa.googlegroups.com> Message-ID: <428EB723.8050606@stackless.com> beliavsky at aol.com wrote: > Kay Schluehr wrote: > >>holger krekel wrote: >> >>>Welcome to PyPy 0.6 >>>-------------------- >>> >>>*The PyPy Development Team is happy to announce the first >>>public release of PyPy after two years of spare-time and >>>half a year of EU funded development. The 0.6 release >>>is eminently a preview release.* >> >>Congratulation to You and Your team! >> >>PyPy is really awesome and if it succeeds in speed demands after the >>translation phase I believe that the project will shift the power >>within the Python community on the long run. > > > Could you please explain this statement? Who will gain power, and who > will lose it? The Python community will gain power, and nobody will loose some. The big win is that we gain a new flexibility that did not exist before, even if PyPy should completely miss its speed promises. Having an extremely flexible implementation in a very high-level language (which happens to be Python) enables possibilities which have not been seen, before. There is of course a chance for some community of C programmers to loose interest, if PyPy really gets as efficient as we hope for. But this is a) still a long, uncertain path and b) not a real danger, but more likely an advantage for the involved people. > Are you suggesting that CPython and PyPy developers are > competing? No idea how we could get onto this track. If there is a competition, then only if PyPy gets into a position where it is comparable with CPython. This is not the case, at least not in a well-ordered manner. It is not really faster, but it is definately much more flexible. Comparisons are not suitable at all, bcause there are too many qualities to compare about. And I see no point for any competition in any future. We all love Python. It is a language, and languages are communities. If a particular implementation gets more interest for some reasons, then because it ibetter s more efficient or more interesting, whatever reasoning gives it popularity. But we are all with Python! Surely we are comparing our performance with CPython's. This is not the real point. Note also, that many of the PyPy team members belong to CPython core developers, as well. This is not a competition, but a huge new branch, exploring what is doable and what not. You might also give our website a try which is quite informative and gives you an insight into what we are aiming for. http://codespeak.net/pypy PyPy is just a completely new approach to interpreted languages, almost based upon known compiler technology, but applying this in a consequent manner, that has no comparable prior example. I wish to repeat the congratulations to the team for the first release! ----------------------------------------------------------------------- ciao -- chris -- Christian Tismer :^) tismerysoft GmbH : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ From not at home.com Sun May 1 16:18:39 2005 From: not at home.com (John Smith) Date: Sun, 01 May 2005 20:18:39 GMT Subject: Whats the best Python Book for me Message-ID: I already know C/C++ programming and now wish to learn Python to do scripting for some games that are coming out. What book would you recommend. I am thinking Teach Your Self Python in 24 Hours is probably the best place to start... From mwm at mired.org Mon May 2 21:45:43 2005 From: mwm at mired.org (Mike Meyer) Date: Mon, 02 May 2005 20:45:43 -0500 Subject: So many things that need to be decided.... References: Message-ID: <86sm1584l4.fsf@guru.mired.org> "Heather Stovold" writes: > Wow - deciding to program in python sure requires a lot of decisions! It wasn't for me. > So far: > > I've decided on python for the programming language. > I've decided on wxpython for the GUI.... Hmm. I started writing CGI apps, so I didn't need to choose a GUI - at least not until later. I finally settled on PyQT, though I've used TkInter as well. > I've decided on DrPython for the Editor.... An editor for each language? Is that the kind of tower you get when you start using IDEs? I just kept right on using the same text editor I'd been using for the last 20 (now 30) years. > I still need to decide on a database........ I've really only used Access, > and my SQL skills aren't that great. It would also need to be free.... > Any suggestions?? Access is just a way of talking to a database. Which is what most Python database tools are - ways to talk to a back-end database. If you're going to be writing fairly traditional applications, this is probably overkill. Doing web back ends, I needed to deal with simultaneous access, so had to go this route. I chose PostGreSQL, but I've worked with MySQL as well. You might be better off with something that doesn't require a separate server. Gadfly appears to qualify. There are probably other packages that give you a DB-API or SQL interace to an internal database that will serve your purpose. I've worked with the berkeley db modules, which provides a way of storing arbitrary chunks of memory on disk, using arbitrary chunks of memory as a key. That may well be enough. The shelve module is the easy way to use this. > Am I going to need a program/package for a report writer? or that might > depend on the database I use? That won't depend on the database. It will depend on what you want your applications to do when it comes to generating reports - assuming you generate any at all. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. From steven.bethard at gmail.com Thu May 26 10:22:49 2005 From: steven.bethard at gmail.com (Steven Bethard) Date: Thu, 26 May 2005 08:22:49 -0600 Subject: __init__() not called automatically In-Reply-To: <1117095907.393269.87540@g44g2000cwa.googlegroups.com> References: <1117081917.760603.82610@z14g2000cwz.googlegroups.com> <1117095907.393269.87540@g44g2000cwa.googlegroups.com> Message-ID: Sriek wrote: > maybe like this: > we can have the default behaviour as calling the default constructor > ( with default arguements where required ). Along with this, keep the > option open to call constructors explicitly. Ok, so here's another example: def init(self): print "An __init__ method, but in what class?!!" print "Oh, this class: %s" % type(self).__name__ class C(object): pass C.__init__ = init So how would the compiler know that init() is a constructor for the C object? (You can figure that out at runtime, but I don't see how you can generally figure that out at compile time.) STeVe From vamsee_k at nospam.students.iiit.ac.in Sat May 28 07:22:17 2005 From: vamsee_k at nospam.students.iiit.ac.in (Vamsee Krishna Gomatam) Date: Sat, 28 May 2005 16:52:17 +0530 Subject: search/replace in Python (solved) References: Message-ID: Leif K-Brooks wrote: > Oliver Andrich wrote: > > > For real-world use you'll want to URL encode and entityify the text: > > import cgi > import urllib > > def google_link(text): > text = text.group(1) > return '%s' % (cgi.escape(urllib.quote(text)), > cgi.escape(text)) > > re.sub(r"(.*)", google_link, "foo bar) Thanks a lot for your reply. I was able to solve it this way: text = re.sub( "([^<]*)", r'\1', text ) GVK From timothy at open-networks.net Thu May 12 01:47:58 2005 From: timothy at open-networks.net (Timothy Smith) Date: Thu, 12 May 2005 15:47:58 +1000 Subject: urllib download insanity Message-ID: <4282EE0E.1080100@open-networks.net> ok what i am seeing is impossible. i DELETED the file from my webserver, uploaded the new one. when my app logs in it checks the file, if it's changed it downloads it. the impossible part, is that on my pc is downloading the OLD file i've deleted! if i download it via IE, i get the new file. SO, my only conculsion is that urllib is caching it some where. BUT i'm already calling urlcleanup(), so what else can i do? here is the code LastModified = urllib2.urlopen('http://x.x.x.x/library.zip') LastModified = LastModified.headers['Content-Length'] LocalFile = os.stat('library.zip') LocalFile = int(LocalFile.st_size) if LocalFile != int(LastModified): urllib.urlcleanup() urllib.urlretrieve('http://x.x.x.x/library.zip','library.zip') as a test i got someone in the office to login and try it - worked properly for them. i'm on a different ISP to them however, so my other idea is that possibly my isp has a transparent proxy setup that urllib is using, but IE isn't??? From prashanthellina at gmail.com Sun May 29 05:03:03 2005 From: prashanthellina at gmail.com (Prashanth Ellina) Date: 29 May 2005 02:03:03 -0700 Subject: Xml writing in Python and verifying using XSD In-Reply-To: References: <1117188065.742367.219360@o13g2000cwo.googlegroups.com> Message-ID: <1117357383.213236.289580@g44g2000cwa.googlegroups.com> Diez B. Roggisch wrote: > Use StringIO to capture the output of your writings, and use a > xsd-validating parser (not sure which one, but google should help) to > reread that. Or a temporary file. Thank you very much. I'll try that. From martin at v.loewis.de Fri May 20 19:58:44 2005 From: martin at v.loewis.de (=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=) Date: Sat, 21 May 2005 01:58:44 +0200 Subject: processing a large utf-8 file In-Reply-To: References: Message-ID: <428e79b4$0$29980$9b622d9e@news.freenet.de> Ivan Voras wrote: > Since the .encoding attribute of file objects are read-only, what is the > proper way to process large utf-8 text files? You should use codecs.open, or codecs.getreader to get a StreamReader for UTF-8. Regards, Martin From megahrtz at gte.net Tue May 10 14:04:52 2005 From: megahrtz at gte.net (Alex N) Date: 10 May 2005 11:04:52 -0700 Subject: Need a little parse help In-Reply-To: <1115748050.760878.44510@f14g2000cwb.googlegroups.com> References: <1115748050.760878.44510@f14g2000cwb.googlegroups.com> Message-ID: <1115748292.224139.71050@f14g2000cwb.googlegroups.com> That worked! Thank you so much! From saravanan.d at siemens.com Mon May 9 04:32:25 2005 From: saravanan.d at siemens.com (Saravanan D) Date: Mon, 9 May 2005 14:02:25 +0530 Subject: Exception in Python 2.3.3 Interpreter References: <1114434259.853654.272420@z14g2000cwz.googlegroups.com> Message-ID: Hello, The crash occured at the following line : c = strcmp(vname, wname) (object.c) Please note that the dump has been taken with the help of adplus. # ChildEBP RetAddr Args to Child 00 023ffa58 1e05c6da 055b1250 00637470 00000000 python23!default_3way_compare(struct _object * v = 0x053f2bfc, struct _object * w = 0x00000001)+0x102 [F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 689] 01 023ffa74 1e05c5ee 055b1250 00637470 00000000 python23!do_richcmp(struct _object * v = 0x1e0b9fb8, struct _object * w = 0x00000000, int op = 0)+0x4a 02 023ffa94 1e0174d9 055b1250 00637470 00000000 python23!PyObject_RichCompare(struct _object * v = 0x053f2bfc, struct _object * w = 0x00000001, int op = 0)+0x1ae [F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 1044] 03 023ffaa4 1e013182 00000000 055b1250 00637470 python23!cmp_outcome(int op = 88026108, struct _object * v = 0x00000001, struct _object * w = 0x00000000)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880] 04 023ffb18 1e016ba4 014f3318 00000002 0099f170 python23!eval_frame(struct _frame * f = 0x053f2bfc)+0x542 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 1965] 05 023ffb30 1e016a69 0099f170 023ffb7c 00000002 python23!fast_function(struct _object * func = , struct _object *** pp_stack = , int n = , int na = , int nk = )+0x94 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520] 06 023ffb5c 1e014b65 00a280d0 00000002 00000008 python23!call_function(struct _object *** pp_stack = 0x00000001, int oparg = 0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458] 07 023ffbcc 1e016ba4 006ea160 00000001 0099f1b0 python23!eval_frame(struct _frame * f = )+0x1f25 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117] 08 023ffbe4 1e016a69 0099f1b0 023ffc30 00000001 python23!fast_function(struct _object * func = , struct _object *** pp_stack = , int n = , int na = , int nk = )+0x94 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520] 09 023ffc10 1e014b65 00a280d0 00000001 00000000 python23!call_function(struct _object *** pp_stack = 0x00000000, int oparg = 0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458] 0a 023ffc80 1e015b6f 006cf6d0 00000000 00a1df9c python23!eval_frame(struct _frame * f = )+0x1f25 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117] 0b 023ffcac 1e040978 0096b720 00000001 006cf6d0 python23!PyEval_EvalCodeEx(struct PyCodeObject * co = , struct _object * globals = , struct _object * locals = , struct _object ** args = , int argcount = , struct _object ** kws = , int kwcount = , struct _object ** defs = , int defcount = , struct _object * closure = )+0x70f [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2663] 0c 023ffcf0 1e0078ec 009788b0 00a1df90 00000000 python23!function_call(struct _object * func = 0x1e0baa50, struct _object * arg = 0x0096b720, struct _object * kw = 0x00954390)+0x138 [F:\Python-2.3.3\Python-2.3.3\Objects\funcobject.c @ 512] 0d 023ffd04 1e01be03 009788b0 00a1df90 00000000 python23!PyObject_Call(struct _object * func = 0x1e0d7608, struct _object * arg = 0x00000001, struct _object * kw = 0x00a280d0)+0x1c [F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755] 0e 023fff24 1e0078ec 00a20f08 00671030 00000000 python23!instancemethod_call(struct _object * func = 0x1e0d7608, struct _object * arg = 0x00000001, struct _object * kw = 0x00a280d0)+0x133 [F:\Python-2.3.3\Python-2.3.3\Objects\classobject.c @ 2433] 0f 023fff38 1e016827 00a20f08 00671030 00000000 python23!PyObject_Call(struct _object * func = 0x77e4a990, struct _object * arg = 0x01415bd8, struct _object * kw = 0x00000000)+0x1c [F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755] 10 023fff50 1e080c77 00a20f08 00671030 00000000 python23!PyEval_CallObjectWithKeywords(struct _object * func = 0x77e4a990, struct _object * arg = 0x01415bd8, struct _object * kw = 0x00000000)+0xa7 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3346] 11 023fff70 1e080675 013d8ba0 00000000 014161a8 python23!t_bootstrap(void * boot_raw = 0x77e4a990)+0x37 [F:\Python-2.3.3\Python-2.3.3\Modules\threadmodule.c @ 183] 12 023fff84 77bc90a2 0086f32c 00000000 00000000 python23!PyThread_get_thread_ident(void)+0x5 [F:\Python-2.3.3\Python-2.3.3\Python\thread_nt.h @ 213] 13 023fffb8 77e4a990 01415bd8 00000000 00000000 msvcrt!_endthread+0xa6 14 023fffec 00000000 77bc9032 01415bd8 00000000 kernel32!BaseThreadStart+0x34 - Saravanan D "Saravanan" wrote in message news:1114434259.853654.272420 at z14g2000cwz.googlegroups.com... > Hello, > > Im running Python Application as a Windows Service (using windows > extensions). But, sporadically the application crashes (crash in > Python23.dll) and this stops the service. This problem cann't be > reproduced easily in my system and the call stack generated by the > application is given below. > > > Occurrence: 2005/4/22 23:24:57 > Process Id: 3072 > Process Name : D:\Python23\lib\site-packages\win32\PythonService.exe > Thread Id: 292 > Exception code: C0000005 ACCESS_VIOLATION > Fault address: 1E05C202 01:0005B202 C:\WINDOWS\system32\python23.dll > > Registers: > EAX:1E0E2EAC > EBX:00732EA8 > ECX:1E03E500 > EDX:016EC200 > ESI:00000000 > EDI:00732EA8 > CS:EIP:001B:1E05C202 > SS:ESP:0023:025FFA3C EBP:00637470 > DS:0023 ES:0023 FS:003B GS:0000 > Flags:00010246 > > Call stack: > Address Frame > 1E05C202 00637470 0001:0005B202 C:\WINDOWS\system32\python23.dll > 016EC29C 00000003 0000:00000000 > > The thread which throws the exception is from the Python-Core and not > from the application logic. > > The above call stack points to PyObject_Compare function in object.c. > > Any clue about the problem? > > Thanks in Advance. > > Saravanan D > From mwm at mired.org Sat May 28 16:19:30 2005 From: mwm at mired.org (Mike Meyer) Date: Sat, 28 May 2005 15:19:30 -0500 Subject: Help with choice of suitable Architecture References: <1117299643.380598.5540@g47g2000cwa.googlegroups.com> <1117311160.307176.216430@o13g2000cwo.googlegroups.com> Message-ID: <86acmfumr1.fsf@guru.mired.org> "Rob Cowie" writes: > Paul..... I agree that client-side scripting increases the level of > compexity, but did it really go out of fashion with pop-ups? It seems > to be just getting started. Google use it to great effect.... maps, > suggest etc. I wasn't thinking of using it to deal with any 'business > logic', just to add some dynamism to the interface - use > XMLhttprequests, a bit of DOM scripting etc. It's clearly not gone. Just remember, that people do turn it off for security reasons. Doing so also does a good job of killing popups and the like. I normally run with JavaScript off, and the local city government has installed IE with it disabled on all their desktops. So make sure the functionality of the site doesn't require javascript to be enabled. This may require duplicating functionality, but you can save your design by hiding the non-javascript version of the functionality in a