module error for elementtree
#!/usr/bin/env python from elementtree import ElementTree as Element tree = et.parse("testxml.xml") for t in tree.getiterator("SERVICEPARAMETER"): if t.get("Semantics") == "localId": t.set("Semantics", "dataPackageID") tree.write("output.xml") Hi, For the above code to work elementtree is imported in first line ,but when running it says : ImportError: No module named elementtree.ElementTree Does thie module exists as default or a patch is needed? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: High resolution sleep (Linux)
John a écrit : > Anyways, what I need is high resolution sleep, not high resolution > timing. Installing a real time OS seems like overkill. IDEA Maybe try creating threading.Event and waiting for it with a timeout. -- http://mail.python.org/mailman/listinfo/python-list
Re: module error for elementtree
On May 11, 12:05 am, [EMAIL PROTECTED] wrote: > #!/usr/bin/env python > > from elementtree import ElementTree as Element > tree = et.parse("testxml.xml") > > for t in tree.getiterator("SERVICEPARAMETER"): > if t.get("Semantics") == "localId": > t.set("Semantics", "dataPackageID") > > tree.write("output.xml") > > Hi, > For the above code to work elementtree is > imported in first line ,but when running it says : > ImportError: No module named elementtree.ElementTree > Does thie module exists as default or a patch is needed? > Thanks http://groups.google.com/group/comp.lang.python/browse_frm/thread/e095cc79d1efb99/a4523a6e9b7061af?rnum=1#a4523a6e9b7061af Read carefully. -- http://mail.python.org/mailman/listinfo/python-list
Re: Change serial timeout per read
<[EMAIL PROTECTED]> wrote: > What I actually want to do is to respond immediately if the expected > string comes in, but not raise a timeout unless it takes longer than > the maximum time. So if the device I'm communicating with usually > responds in a second, but _can_ take up to 20 seconds, I don't want to > do a sleep(20) then read the port since this will slow everything down > a lot in an average world. I want to keep checking for the expected > string, and act upon it as soon as I've got it, only raising a timeout > if I haven't got it after 20 seconds. I guess to do this using non- > blocking calls I have to do something like: > timesofar = 0 > returnstring = port.read(1) > while len(returnstring) if timesofar >= timeout: > raise SerialException('Timeout') > time.sleep(checkportinterval) > timesofar += checkpointinterval > returnstring += port.read(1) > > This seems rather messy. What I've tried this morning is to produce a > modified version of uspp with a second optional timeout parameter in > its read() function. If this is present, the timeout given is sent to > the port using SetCommTimeouts(). If it's not present, the timeouts > specified when the port was opened are sent. At first sight, with > minimal testing on Windows, this seems to be working, and will leave > my application code a lot cleaner than the non-blocking plus sleep > approach. Of course I don't know whether my method will work on Linux, > and there may be problems I haven't found yet. If it works it works - no problem with that - fight the dragons as you meet them, one at a time. I normally put something like this in a read function (from memory, not tested): error = 0 k = '' try: k = port.read(1) except IoError: error = 1 return error,k For this to work, you have to first unblock the port using fcntl: def unblock(f): """given file f sets unblock flag to true""" fcntl.fcntl(f.fileno(),f.F_SETFL, os.O_NONBLOCK) Then you put a call to the read in a loop, and use time.time() to do your time out, resetting a start_time variable at the start, and every time you get a char, and using short sleeps (millisec or so) after unsuccessful calls to make it less of a busy loop. The side benefit of this is that once you have received a char, you can change gears and use a shorter time out to detect the end of message, in a protocol and state agnostic way. - when the device has stopped sending chars for a little while it has finished saying what it wants to say. - so its easy to write a get_a_reply routine with variable time out, moving the action from the char to the message level: start_time=time.time() s = '' while time.time()-start_time < time_out: error,k = get_a_char(port) if error: time.sleep(0.001) continue s += k # keep the first char start_time = time.time() while time.time() - start_time < 0.005: # inter char time out status,k = get_a_char(port) if error: time.sleep(0.001) continue s +=k start_time = time.time() break return s # return empty string or what was received Something similar works for me on Suse Linux - not sure if fcntl works on windows. And no it isn't pretty. - but then very little of what I write is... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: High resolution sleep (Linux)
Bart <[EMAIL PROTECTED]> wrote: > What about C module with usleep,nanosleep? Unlikely to help! It is an linux OS limit that the minimum sleep time is 1/HZ. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: how to refer to partial list, slice is too slow?
In <[EMAIL PROTECTED]>, 人言落日是天涯,望极天涯不见家 wrote: > I make a sample here for the more clearly explanation > > s = " . - this is a large string data - ..." > > def parser1(data) > # do some parser > ... > # pass the remainder to next parser > parser2(data[100:]) > > def parser2(data) > # do some parser > ... > # pass the remainder to next parser > parser3(data[100:]) > > def parser3(data) > # do some parser > ... > # pass the remainder to next parser > parser4(data[100:]) > > ... Do you need the remainder within the parser functions? If not you could split the data into chunks of 100 bytes and pass an iterator from function to function. Untested: def iter_chunks(data, chunksize): offset = chunksize while True: result = data[offset:offset + chunksize] if not result: break yield result def parser1(data): chunk = data.next() # ... parser2(data) def parser2(data): chunk = data.next() # ... parser3(data) # ... def main(): # Read or create data. # ... parser1(iter_chunks(data, 100)) Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question about string(passing by ref)
lazy <[EMAIL PROTECTED]> wrote: > I want to pass a string by reference. I understand that strings are > immutable, but Im not > going to change the string in the function, just to aviod the overhead > of copying(when pass-by-value) because the > strings are long and this function will be called over and over > again. You'll find it is pretty hard to get Python to copy a string even if you wanted it to. About the only way is to break it apart and then construct a new string with the same value from it. >>> s = "some long string" >>> id(s) 12944352 >>> copyofs = s[:] >>> id(copyofs) 12944352 >>> copyofs = s[:-1]+s[-1:] >>> id(copyofs) 12944992 >>> def fn(foo): print id(foo) return foo >>> fn(s) 12944352 'some long string' >>> id(fn(s)) 12944352 12944352 And sometimes two strings created separately magically become the same string (not that should you assume this will happen, just that it might, and the behaviour will vary according to a lot of factors): >>> s1 = "abc" >>> id(s1) 12956256 >>> s2 = "abc" >>> id(s2) 12956256 >>> s1 = "pqr stu" >>> id(s1) 12956288 >>> s2 = "pqr stu" >>> id(s2) 12956192 -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Tkinter Progress Bar
On Fr, 11.05.2007, 08:42, Gurpreet Singh wrote: > Hi > > I am a newbie in Python > > I am creating a simple Tkinter based application. > I have written Tkinter GUI source code and the > programme logic in the same .py file. > > I am searching for a way to implement a simple > Progress bar for my application. > > Are there any simple ways of doin it. > > > > > > Yahoo! > oneSearch: Finally, mobile search > that gives answers, not web links. > http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC > -- > http://mail.python.org/mailman/listinfo/python-list > > Please see this: http://tkinter.unpythonic.net/wiki/ProgressBar -- http://mail.python.org/mailman/listinfo/python-list
checking if hour is between two hours
Hi all, i'm again working on my script of parsing logfiles :) I putted a new function to disable the rule of error between a certain hours, cause i want to use it as a monitoring script that run every 5 minutes and to disable error in hours of maintenance. But i have some "problems" to check it. In the rule-file i have HHMM(start) and HHMM(stop) - 0 0 to disable hours check (i can't check the timestamp in logfile cause not all the logfiles that i need to check have a timestamp in it). In the script i wrote: Actualtime=datetime.datetime.today().strftime("%H%M") if (start>end): if (Actualtime>start): end=int(Hcheck)+1 else: if (int(Actualtime)int(end)) or ((start=="0") and (end=="0")) ): rule=error ...blablabla else: rule=skip blablabla Why i don't use the complete date with YYMMDDHHMM? Think about a rule that need to be disabled from hours 20:00 to 04:00. If i use also yymmdd, in the rule file i need to write a 2000 and 0400+1, the +1 to tell the script that the end is in the day after, to add a day. But it will work just till the , hour in witch the day will change. The script work, but is not so "clean"i just would like some advice to make it more clean, if possible. Like always, thanks in advance for the helps :) -- http://mail.python.org/mailman/listinfo/python-list
Re: 4 byte integer
On May 11, 2007, at 4:25 AM, Paul D Ainsworth wrote: > Greetings everyone. I'm a relative newcomer to python and I have a > technical > problem. > > I want to split a 32 bit / 4 byte unsigned integer into 4 separate > byte > variables according to the following logic: - > > bit numbers 0..7 byte 1 > bit numbers 8..15 byte 2 > bit numbers 16..23 byte 3 > bit numbers 24..31 byte 4 > > Each of these byte variables to contain integer data from 0 to 255 > (or 0 to > FF in hex mode) > > I had thought that struct.unpack with an input message format of > 'I' would > be the way to do it, but its reporting an error that it doesn't > want to > accept an integer. > > Please can anyone advise? Have a look at http://aspn.activestate.com/ASPN/Cookbook/Python/ Recipe/113799 -- http://mail.python.org/mailman/listinfo/python-list
Jessica Reveals all "Again"
http://jessicasboobs.blogspot.com/ - Download snazzy jessica images (I bet you will find her naked) -- http://mail.python.org/mailman/listinfo/python-list
Re: Erlang style processes for Python
Jacob Lee wrote: > Funny enough, I'm working on a project right now that is designed for > exactly that: PARLEY, http://osl.cs.uiuc.edu/parley . Have you seen Kamaelia? Some people have noted that Kamaelia seems to have a number of similarities to Erlang's model, which seems to come from a common background knowledge. (Kamaelia's model is based on a blending of what I know from a very basic recasting of CSP, Occam, unix pipelines and async hardware verification). Home: http://kamaelia.sourceforge.net/Home Intros: http://kamaelia.sourceforge.net/Introduction http://kamaelia.sourceforge.net/t/TN-LinuxFormat-Kamaelia.pdf http://www.bbc.co.uk/rd/pubs/whp/whp113.shtml * http://kamaelia.sourceforge.net/t/TN-LightTechnicalIntroToKamaelia.pdf http://kamaelia.sourceforge.net/Docs/NotationForVisualisingAxon The one *'d is perhaps the best at the moment. Detail: http://kamaelia.sourceforge.net/Cookbook http://kamaelia.sourceforge.net/Components Michael. -- http://mail.python.org/mailman/listinfo/python-list
Re: searching algorithm
On May 10, 2007, at 12:26 PM, Gigs_ wrote: > Hi all! > > I have text file (english-croatian dictionary) with words in it in > alphabetical > order. > This file contains 17 words in this format: > english word: croatian word > > I want to make instant search for my gui > Instant search, i mean that my program search words and show words > to user as > user type letters. > yes, it needs to be fast > > Can someone give me some points (approaches) how to make this > Should i make indexes and go with file.seek > > or should breake dictionary in peaces and put words that start with > a in one and > with b in another... > ? > > So if i have this words > ... > > if user type: "abs" program should list all words above in english > and in croatian > if user type: "absorb" than program should list last 3 words in > english and in > croatian > > > > > > any help would be appreciate! > my apologies for bad english Here's an idea: use a rats' nest of dictionaries and do all the lookup work up front when you build the rats' nest. Maybe something like this: #! /usr/bin/env python import pprint dictionary = """absinth:pelin absinthe:pelin absolute:apsolutan absolute:apsolutni kod absolute:apsolutno absolute:čist absolute:nesumnjiv absolute:potpun absolute:savrsen absolute coordinates:apsolutne koordinate absolute frequency:apsolutna učestalost absolute gap:apsolutni jaz absolute line spacing:apsolutni međurazmak linija absolute majority:apsolutna većina absolute pointing device:apsolutni pokazivački uređaj absolute quantity:apsolutni udio absolute value:apsolutna vrijednost absolute zero:apsolutna nula absolutely:apsolutno absolutely:bezuvjetno absolutely:nezavisno absolutely:potpuno absolutely:samostalno absolutely:sasvim absolution:odrjesenje absolution:oprostaj absolutism:apsolutizam absolve:odrijesiti absolve:osloboditi absorb:absorbirati absorb:apsorbirati absorb:crpsti""" lookup = {'words':{}, 'letters':{}} for translation in dictionary.split('\n'): english, croatian = translation.split(':') if english in lookup['words']: lookup['words'][english].append(croatian) else: lookup['words'][english] = [croatian] for position, letter in enumerate(english): if position == 0: youAreHere = lookup['letters'] if letter not in youAreHere: youAreHere[letter] = {'words':[]} youAreHere[letter]['words'].append(lookup['words'][english]) youAreHere = youAreHere[letter] def tryit(partial): youAreHere = lookup['letters'] for letter in partial: youAreHere = youAreHere[letter] return youAreHere['words'] if __name__ == '__main__': pprint.pprint(tryit('abso')) Hope this helps, Michael --- The Rules of Optimization are simple. Rule 1: Don't do it. Rule 2 (for experts only): Don't do it yet. -- Michael A. Jackson , "Principles of Program Design", 1975. -- http://mail.python.org/mailman/listinfo/python-list
4 byte integer
Greetings everyone. I'm a relative newcomer to python and I have a technical problem. I want to split a 32 bit / 4 byte unsigned integer into 4 separate byte variables according to the following logic: - bit numbers 0..7 byte 1 bit numbers 8..15 byte 2 bit numbers 16..23 byte 3 bit numbers 24..31 byte 4 Each of these byte variables to contain integer data from 0 to 255 (or 0 to FF in hex mode) I had thought that struct.unpack with an input message format of 'I' would be the way to do it, but its reporting an error that it doesn't want to accept an integer. Please can anyone advise? -- http://mail.python.org/mailman/listinfo/python-list
Re: searching algorithm
> > Call me dense, but how does one do this in Python - which doesn't have > pointers? Dictionaries with dictionaries within dictionaries... (with > each letter as the key and the its children as values) is going to be > extremely space inefficient, right? Isn't *everything* in python essentially a pointer? Dictionaries with dictionaries within dictionaries... My gut feeling (which means I have not measured it, so I don't actually know) is that it would not be space inefficient. Perhaps someone who knows more about this will speak up? -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: Python Module and Class Scope
In article <[EMAIL PROTECTED]>, johnny <[EMAIL PROTECTED]> wrote: > Can a class inside a module, access a method, outside of class, but > inside of the module? > > Eg. Can instance of class a access main, if so how? What is the > scope of "def main()" interms of class A? > > myModule: > > class A: >main() > > def main(): > Yes, class A can access main. The name "main" will be defined at the top level of the module, and is considered a global for that module. Code within that module can access it simply as "main". Code in other modules would have to import the module in order to use symbols within it. For example... ### myModule.py class A: def m(): main() def main(): pass ### other.py ### import myModule def main(): pass class B: def o(): main() # calls main() in this module myModule.main() # calls main in myModule Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: 4 byte integer
> > Have a look at http://aspn.activestate.com/ASPN/Cookbook/Python/ > Recipe/113799 Brilliant - thank you :) -- http://mail.python.org/mailman/listinfo/python-list
Re: newb: Python Module and Class Scope
Dave Baum <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > johnny <[EMAIL PROTECTED]> wrote: > >> scope of "def main()" interms of class A? >> >> myModule: >> >> class A: >>main() >> >> def main(): >> > > Yes, class A can access main. The name "main" will be defined at the > top level of the module, and is considered a global for that module. No, the name "main" will be defined when the execution of the 'def main()' statement is complete. It is not defined until that point. In the example given the class statement is executed before the def statement is executed so at that point main is still undefined. -- http://mail.python.org/mailman/listinfo/python-list
Custom Software Development
iTechArt Group - Custom Software Development and Offshore outsourcing Company http://www.itechart.com/ Offshore custom software development company iTechArt - Web site and Content Management Solutions development, CMS consulting: Ektron, Drupal and DotNetNuke iTechArt Group provides high quality custom software development services and offshore software development. On December 2006, iTechArt Group became an authorized Microsoft Certified Partner. This means that our company has been recognized by Microsoft for our vast expertise and authorized to custom software development; provide IT service consulting and custom business solutions. Custom Software Development and Offshore outsourcing Company iTechArt has worked together since 2003 to design build and deliver .NET Web Content Management software solutions that help clients meet their strategic objectives. We are agile oriented development partner able to consistently deliver solid results. iTechArt software development team assemblies specialists in the development of custom software applications and offshore software outsourcing services. Working concepts of our company are based on proven approaches and international standards used for custom software development such as Capability Maturity Model Integration for Software Engineering (CMMI- SW). In the same breath we have our own standpoint on software development process management which is fully effective and comprehensible for our clients. iTechArt offers software development in the next main directions: 1. Custom Software Development (Offshore outsourcing for worldwide based software development companies.) 2. Software Development for Digital Signage (Media content development and remote displays / information kiosks Web-based software application management.) 3. Web Site Development (E-commerce solutions, CMS/DotNetNuke/Ektron/ Drupal, Web 2.0/PHP/MySQL/AJAX, Flash/Action script/Flex and many more.) 4. Offshore Development Center (Dedicated development team of software developers. Our offshore development centers operate as an extension to clients' existing software engineering business.) Contact iTechArt ( http://www.itechart.com/ )about custom software development, end-to-end software solutions, outsourcing software development, custom DotNetNuke module development, DotNetNuke consulting, dotnetnuke hosting, first class Java and .Net developers, software application design, software testing, Quality Assurance, functionality testing and defect analysis, performance and stress testing, usability testing, Microsoft Media Services and Adobe Media Flash Server solutions, digital signage solutions and custom development, Ektron CMS400.NET developers, CMS, .NET Web Content Management software solutions Web: http://www.itechart.com/ http://www.itechart.com/Pages/ProductsServices/HowWeWork.aspx http://www.itechart.com/Pages/ProductsServices/BusinessModels.aspx http://www.itechart.com/Pages/ProductsServices/CustomSoftwareDevelopment.aspx http://www.itechart.com/Pages/ProductsServices/DotNetNukeModuleDevelopment.aspx -- http://mail.python.org/mailman/listinfo/python-list
Re: module error for elementtree
[EMAIL PROTECTED] wrote: > On May 11, 12:22 pm, [EMAIL PROTECTED] wrote: >> On May 11, 12:05 am, [EMAIL PROTECTED] wrote: >> >> >> >> >> >>> #!/usr/bin/env python >>> from elementtree import ElementTree as Element >>> tree = et.parse("testxml.xml") >>> for t in tree.getiterator("SERVICEPARAMETER"): >>> if t.get("Semantics") == "localId": >>> t.set("Semantics", "dataPackageID") >>> tree.write("output.xml") >>> Hi, >>> For the above code to work elementtree is >>> imported in first line ,but when running it says : >>> ImportError: No module named elementtree.ElementTree >>> Does thie module exists as default or a patch is needed? >>> Thanks >> http://groups.google.com/group/comp.lang.python/browse_frm/thread/e09... >> >> Read carefully.- Hide quoted text - >> >> - Show quoted text - > > The commands are given in that link are more so for a linux system .I > am developing in windows.how should i go about to make it work As said: read carefully. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: module error for elementtree
On May 11, 12:22 pm, [EMAIL PROTECTED] wrote: > On May 11, 12:05 am, [EMAIL PROTECTED] wrote: > > > > > > > #!/usr/bin/env python > > > from elementtree import ElementTree as Element > > tree = et.parse("testxml.xml") > > > for t in tree.getiterator("SERVICEPARAMETER"): > > if t.get("Semantics") == "localId": > > t.set("Semantics", "dataPackageID") > > > tree.write("output.xml") > > > Hi, > > For the above code to work elementtree is > > imported in first line ,but when running it says : > > ImportError: No module named elementtree.ElementTree > > Does thie module exists as default or a patch is needed? > > Thanks > > http://groups.google.com/group/comp.lang.python/browse_frm/thread/e09... > > Read carefully.- Hide quoted text - > > - Show quoted text - The commands are given in that link are more so for a linux system .I am developing in windows.how should i go about to make it work -- http://mail.python.org/mailman/listinfo/python-list
vim e autoindentazione commenti
Ciao a tutti, alla fine dopo le mille dispute emacs vs vim mi sono messo a provarli entrambi... e mi pare ora di essere diventato un vimmaro (pur se molto 'custom' in quanto lo sto rendendo un bel po' + simile a cream). Una domanda stupida. Forse è più da comp.editors. Come faccio a far sì che vim prosegua automaticamente i commenti su più righe? Ho settato la lunghezza massima della riga a 79 caratteri, fin qui tutto ok, ma quando vado a capo, anche se la riga inizia con #, vim non lo aggiunge in automatico all'inizio. Al contrario con altri tipi di file (es. Java) questa aggiunta è automatica e la trovo molto, molto comoda. Dovrei andae a intaccare il file di indentazione? o quello di sintassi? -- Alan Franzoni <[EMAIL PROTECTED]> - Togli .xyz dalla mia email per contattarmi. Remove .xyz from my address in order to contact me. - GPG Key Fingerprint (Key ID = FE068F3E): 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell whetehr Python script called as CGI or from command line?
> import os > if "QUERY_STRING" in os.environ: > # CGI script > > might work. Thanks Steve for this suggestion. I did something similar: import os req = os.getenv('REQUEST_URI') if (not req is None) and len(req) > 0: web = True which seemed to work for me. Rowan -- http://mail.python.org/mailman/listinfo/python-list
Re: Jython 2.2 Beta2 is available
In article <[EMAIL PROTECTED]>, Charlie Groves wrote: > >I'm happy to announce that Jython 2.2-beta2 is available for download: >http://sourceforge.net/project/showfiles.php?group_id=12867&package_id=12218&release_id=507592 >See http://jython.org/Project/installation.html for installation instructions. > >This is the second and final beta release towards the 2.2 version of >Jython. It includes fixes for more than 30 bugs found since the first >beta and the completion of Jython's support for new-style classes. COngrats! Whoo-hoo! Excellent news! -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "Look, it's your affair if you want to play with five people, but don't go calling it doubles." --John Cleese anticipates Usenet -- http://mail.python.org/mailman/listinfo/python-list
RE: Python and Decimal integers from DB
Here is the solution, for the record. import pyodbc conn = pyodbc.connect("DSN=NAPL;UID=NAPL_VIEW;PWD=NAPVIEW") curs = conn.cursor() roll_num = 'A27255' Cols = 'TO_CHAR(X_NO) as X_NO' Table = 'photos' Select = 'Select ' + Cols + ' from ' + Table + ' where roll_number = ' +"'" + roll_num + "'" curs.execute(Select) print "select sucess" rows= curs.fetchall() print "fetch success" for row in rows: print row.X_NO print "done" X_NO was entered in the DB as a number using the comma as a non-standard separator. Python did not like it in the decimal.py module so we brought it in as a character string using varchar2. Python liked this solution and returned my results. Now I can give the chars to a var and change it to numbers for some vector math Hope this helps people in the future From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sampson, David Sent: May 10, 2007 12:58 To: python-list@python.org Subject: Python and Decimal integers from DB Hey folks Freshie looking for help This is what I am trying to do. Use PYODBC to hit an oracle DB that has a ODBC connection.\ \The code bellow works when I replace '*' with a specific collumn name that does not have commas in the number. It also works for alphanumberic values. It fails when I try '*' or any collumn that has a comman in the number. The numbers are Latitude longitude readings. I get back "Select Success" but not "fetch success" so I feel as thopugh something is missing on the fetchall() function So how do I get the numbers to be recognized by python? I did lots of searches on python, ODBC, PYODBC, Decimal us and commas as decimals and various combinations. Lots of mailing lists a few tutorials and lots of misses. I came across: Import decimal Decimal.Decimal() This works a bit. It took a coma separated number string and kept the first part. But that works only when I put in a raw value, it doesn't work on the Fetchall function. HELP PLEASE... Cheers ===PYHTON CODE import pyodbc conn = pyodbc.connect("DSN=NAPL;UID=NAPL_VIEW;PWD=NAPVIEW") curs = conn.cursor() roll_num = 'A27255' Cols = '*' Table = 'photos' Select = 'Select ' + Cols + ' from ' + Table + ' where roll_number = ' +"'" + roll_num + "'" curs.execute(Select) print "select sucess" rows= curs.fetchall() print "fetch success" for row in rows: print row.PHOTO_NUMBER print "done" =Standard Output Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py" , line 310, in RunScript exec codeObject in __main__.__dict__ File "U:\My Documents\py_projects\georef\NAPL_DB.py", line 12, in rows= curs.fetchall() File "C:\Python25\lib\decimal.py", line 614, in __new__ self._sign, self._int, self._exp = context._raise_error(ConversionSyntax) File "C:\Python25\lib\decimal.py", line 2325, in _raise_error raise error, explanation InvalidOperation -- http://mail.python.org/mailman/listinfo/python-list
Re: searching algorithm
On 2007-05-11, ciju <[EMAIL PROTECTED]> wrote: > By the way, both data structures could be implemented as tuple > in python, for I suppose, if only lookup is needed tuple gives > better performance than list. I used a list instead of a tuple where I thought a list would be convenient while building the data structure. But you could convert everything to tuples in the end, it's true. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
software testing articles
Have you ever been interested in software testing? Giving you an in depth analysis/knowledge on software testing!! http://www.top-itarticles.com/softtest/main.asp -- http://mail.python.org/mailman/listinfo/python-list
Re: module error for elementtree
On 11 May 2007 00:05:19 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > For the above code to work elementtree is > imported in first line ,but when running it says : > ImportError: No module named elementtree.ElementTree > Does thie module exists as default or a patch is needed? That depends on which version of Python you are running. Starting with 2.5, ElementTree was moved into the standard library, as part of the xml package. If you're using an older version of python, I think you'll need to download and install the elementtree package from http://effbot.org/zone/element-index.htm Assuming you're using python 2.5, you probably want something like this: from xml.etree.ElementTree import ElementTree as et -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: vim e autoindentazione commenti
On 2007-05-11, Alan Franzoni <[EMAIL PROTECTED]> wrote: > Al contrario con altri tipi di file (es. Java) questa aggiunta > è automatica e la trovo molto, molto comoda. > > Dovrei andae a intaccare il file di indentazione? o quello di > sintassi? Colto prego nel manuale Vim: :help format-comments (Spiacente per la mia scrittura difettosa. Sto utilizzando il traduttore di altavista.) -- Neil Cerutti You've got to take the sour with the bitter. --Samuel Goldwyn -- http://mail.python.org/mailman/listinfo/python-list
Re: setting extra data to a wx.textctrl
On May 10, 10:51 pm, Pom <[EMAIL PROTECTED]> wrote: > Hello group! > > I have an application which uses a lot of mysql data fields, all the > same data type (floats). > > I created a panel which executes a "SELECT * FROM tablename" and makes > as much fields as needed, using de cursor.description as wx.statictext > and the cursors field contents copied into wx.textctrls. > > At creation time, I loop over all the fields in the record and create a > tuple which contains ((textctrl1, fieldname1), (textctrl2, fieldname2), > ...) so I can keep track of which textctrl holds which piece of fielddata. > > The problem I'm having is: > > to know the fieldname in an text_event, I use event.GetEventObject(), > then perform an iteration over the tuple and when I find a match I use > the field name to update the mysqltable. > When having a few fields, this is ok. But I have over 100 fields in 1 > record and it really slows things down. > > Now my question is: should I use a python dictionary (with an object as > first lookup field) ? > > On windows, I've seen a "Tag" property in a textbox which was meant to > be used for this kind of stuff. Maybe it's better to override the > wx.textctrl so I can add an extra string value? > > Anyone having the best solution for this ? > > thx! Both of your ideas seem sound to me. You could also look into using statically assigned IDs that increment by one. Then you could just increment or decrement by one and look up the field by ID. Of course, that might get ugly and there are some IDs that are supposedly reserved. But it's an idea. Also, I've heard that Dabo (http://dabodev.com/) is good for database work. You might look at that. To get the quickest and most on target answers to wxPython questions, I recommend the wxPython users-group mailing list: http://www.wxpython.org/maillist.php Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: append
> > the reference material. I want to know about list >> operations such as > > append. I've been struggling myself to assemble and learn just the right combination of quick references. Here is some of what I've found. For a quick search for the syntax and a simple example of a particular method or function, the single most efficient source for me has been the keyword search page for the Python Library Reference, Language Reference, and Python/C API manuals that you can find from a link on the official documentation page at http://www.python.org/doc/ or directly at http://starship.python.net/crew/theller/pyhelp.cgi Full text searches (not limited to keywords like the resource above) of the Python Library Reference can also be done at http://www.zvon.org/other/python/PHP/search.php Other handy references are: Dive into Python at http://diveintopython.org/toc/index.html The Python 2.5 Quick Reference at http://rgruet.free.fr/PQR25/PQR2.5.html Last, but far from least, the one resource that I most wish I had known about when I started with Python is the screencast tutorial site at www.showmedo.com. There are two excellent free screencasts on Python resources at http://tinyurl.com/2qkuht and lots of other Python tutorials, most free and some for a modest fee. In particular, the 9th installment of the paid series called Python Newbies on XP at http://tinyurl.com/3ayhwt is about how to use the help functions built into Python Idle. -- http://mail.python.org/mailman/listinfo/python-list
Dyla'07: 3rd Workshop on Dynamic Languages and Applications
Dear colleague, Please, note that after the workshop, best papers will be selected, and a second deadline will then be set regarding preparation of the Electronic Communications of the EASST. Note that we submission deadline has been extended. The important dates: - May 27: deadline for the workshop submissions. Submissions should follow LNCS format (www.springer.com/lncs) and should be sorter than 10 pages. **extended deadline** - June 12-13: Author notification of their submission - June 15, 2007: ECOOP'07 Early Registration - July 31: Workshop - August 5: Selection of best papers for Electronic Communications of the EASST - September 10: deadline for revised and extended version of submission for the communications. Regards, Dyla organisers * Call for Papers Dyla 2007: 3rd Workshop on Dynamic Languages and Applications July 31, 2007, Berlin (Collocated with ECOOP 2007) http://dyla2007.unibe.ch * Objective = The goal of this workshop is to act as a forum where we can discuss new advances in the conception, implementation and application of object-oriented languages that radically diverge from the statically typed class-based reflectionless doctrine. The goal of the workshop is to discuss new as well as older "forgotten" languages and features in this context. Topics of interest include, but are certainly not limited to: - agents, actors, active objects, distribution, concurrency and mobility - delegation, prototypes, mixins - first-class closures, continuations, environments - reflection and meta-programming - (dynamic) aspects for dynamic languages - higher-order objects & messages - ... other exotic dynamic features which you would categorize as OO - multi-paradigm & static/dynamic-marriages - (concurrent/distributed/mobile/aspect) virtual machines - optimisation of dynamic languages - automated reasoning about dynamic languages - "regular" syntactic schemes (cf. S-expressions, Smalltalk, Self) - Smalltalk, Python, Ruby, Scheme, Lisp, Self, ABCL, Prolog, ... - ... any topic relevant in applying and/or supporting dynamic languages. We solicit high-quality submissions on research results and/or experience. Submitted papers must be unpublished and not submitted for publication elsewhere. Submissions should not exceed 10 pages, LNCS format (www.springer.com/lncs). Submission == Prospective attendees are requested to submit a position paper or an essay (max 10 pages, references included) on a topic relevant to the workshop to Alexandre Bergel ([EMAIL PROTECTED]). Submissions are demanded to be in .pdf format and should arrive before May 13, 2007. A selection of the best papers will be made, which will require an extension for an inclusion in a special issue in Electronic Communications of the EASST (eceasst.cs.tu-berlin.de). For this purpose, a new deadline will be set after the workshop. Moreover, Springer publishes a Workshop-Reader (as in the case of previous ECOOPs) which appears after the Conference and which contains Workshop-Reports (written by the organizers) and not the position papers submitted by the participants. Important dates === May 27, 2007: deadline for the workshop submissions. Submissions should follow LNCS format (www.springer.com/lncs) and should be sorter than 10 pages. **extended deadline** June 12-13, 2007: Author notification of their submission June 15, 2007: ECOOP'07 Early Registration July 31, 2007: Workshop August 05, 2007: Selection of best papers for Electronic Communications of the EASST September 10, 2007: deadline for revised and extended version of submission for the communications. Organisers == Alexandre Bergel Wolfgang De Meuter Stéphane Ducasse Oscar Nierstrasz Roel Wuyts Program committee = Alexandre Bergel (Hasso-Plattner-Institut, University of Potsdam, Germany) Johan Brichau (Université catholique de Louvain, Belgium) Pascal Costanza (Vrije Universiteit Brussel, Belgium) Wolfgang De Meuter (Vrije Universiteit Brussel, Belgium) Stéphane Ducasse (University of Savoie, France) Erik Ernst (University of Aarhus, Denmark) Robert Hirschfeld (Hasso-Plattner-Institut, University of Potsdam, Germany) Oscar Nierstrasz(University of Bern, Switzerland) Matthew Flatt (University of Utah, USA) Dave Thomas(Bedarra Research Labs, Canada) Laurence Tratt(King's College London, UK) Roel Wuyts(IMEC & Université Libre de Bruxelles, Belgium) -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.software-artist.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. -- http://mail.python
Re: searching algorithm
Michael Bentley <[EMAIL PROTECTED]> wrote: > > > > Call me dense, but how does one do this in Python - which doesn't have > > pointers? Dictionaries with dictionaries within dictionaries... (with > > each letter as the key and the its children as values) is going to be > > extremely space inefficient, right? > > Isn't *everything* in python essentially a pointer? Dictionaries > with dictionaries within dictionaries... My gut feeling (which means > I have not measured it, so I don't actually know) is that it would > not be space inefficient. Perhaps someone who knows more about this > will speak up? Dicts are hash tables, and therefore, for performance, always keep some "extra" space (so that the table won't be too full). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Towards faster Python implementations - theory
On May 10, 4:02 pm, Tim Golden <[EMAIL PROTECTED]> wrote: > But the relevant bit of your last paragraph is at the start: > "We should...". Sorry, bad choice of words. > see it faster. That's great. But unless people > puts their money where their mouths are, I don't I know, I know. But that doesn't stop me from envying what the Lisp community has achieved. Python still sucks if we are using it for scientific simulations, testing CPU-bound algorithms, etc. Sure it is only 150-200 times slower than C for these tasks, but that can amount to the difference between one day and half a year of CPU time. But as strange as it may seem, it can still be advantageous to use Python. E.g. it may be less expensive to run the simulation in parallel on 200 CPUs than writing the code in C instead of Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie look at Python and OO
On 2007-05-10, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Thu, 10 May 2007 18:21:42 -0300, <[EMAIL PROTECTED]> escribió: > >> These conversations are funny to me. I use Python every day and I >> have never actually thought about the implications of binding objects >> to names, or two names pointing to the same object. Problems of this >> sort just never come up in actual programming for me. It just works. >> >> Python was my virgin language, so maybe that just makes it natural to >> me, but it seems like people coming from other languages get hung up >> on testing out the differences and theories rather than just >> programming in it. Alas, maybe I have yet to get deep enough to run >> into these kinds of problems. > > Certainly, learning Python as a first language has some > advantages. But I think you'd feel a bit shocked if you had to > program in C++ someday; these rather innocent lines might not > do what you think: [...] > Simple things have so complex and ugly rules that... ugh, enough for now. http://www.ariel.com.au/jokes/An_Interview_with_Bjarne_Stroustrup.html Maybe BS thought he was joking, but IMO, it's true. "Stroustrup: Remember the length of the average-sized 'C' project? About 6 months. Not nearly long enough for a guy with a wife and kids to earn enough to have a decent standard of living. Take the same project, design it in C++ and what do you get? I'll tell you. One to two years." -- Grant Edwards grante Yow! I know how to do at SPECIAL EFFECTS!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: software testing articles
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Have you ever been interested in software testing? Giving you an in > depth analysis/knowledge on software testing!! Looking around the site at random, I saw no "in depth analysis/knowledge" of anything. -- http://mail.python.org/mailman/listinfo/python-list
Re: Towards faster Python implementations - theory
On May 10, 7:18 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > Unfortunately, native machine code depends on the machine, or at least the > machine being emulated by the hardware. Fortunately or not, the dominance > of the x386 model makes this less of a problem. CMUCL and SBCL depends on the dominance of the x86 architecture. GCL uses the GCC backend, which supports a wide range of architectures. Building a compiler backend is not needed for a Python JIT, one can accept the GPL license and use GCC as a backend. Or one could translate between Python and Lisp on the fly, and use a compiled Lisp (CMUCL, SBCL, Franz, GCL) as runtime backend. -- http://mail.python.org/mailman/listinfo/python-list
Re: change of random state when pyc created??
This is an attempt to synthesize Bill and Carsten's proposals. http://docs.python.org/lib/typesmapping.html: for footnote (3) Keys and values are listed in an arbitrary order. This order is indeterminate and generally depends on factors outside the scope of the containing program. However, if items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond. http://docs.python.org/lib/types-set.html: append a new sentence to 2nd par. Iteration over a set returns elements in an indeterminate order, which generally depends on factors outside the scope of the containing program. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list
Better way to isolate string
Greetings. Given the string s below and using only python built-in capabilities, I am trying to isolate the substring G132153. This string may have any number of digits but the pieces around it will not change. I have accomplished this with split but there must be a more elegant and compact way to do this. >>> s ='>> class="dvLink">G132153' >>> t = s.split('">') >>> u = t[-1].split('<') >>> v = u[0] >>> v 'G132153' Thanks, jvh -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie look at Python and OO
Grant Edwards <[EMAIL PROTECTED]> wrote: > http://www.ariel.com.au/jokes/An_Interview_with_Bjarne_Stroustrup.html > > Maybe BS thought he was joking, but IMO, it's true. > > "Stroustrup: Remember the length of the average-sized 'C' >project? About 6 months. Not nearly long enough for a guy >with a wife and kids to earn enough to have a decent >standard of living. Take the same project, design it in C++ >and what do you get? I'll tell you. One to two years." > I doubt very much that BS was involved at any point in writing it. You forgot to quote the bit at the end: [Note - for the humor-impaired, not a true story] -- http://mail.python.org/mailman/listinfo/python-list
Re: Better way to isolate string
HMS Surprise wrote: > I suppose a one liner would look better, but I am alway leery of these > things 'breaking'. > > t = s.split('">')[-1].split('<')[0] > s ='G132153' Only if you're competing in an obscurity competition ;) If you're really confined to built-ins (ie you can't import a single module) then just go with your original solution. Why not? If you can import modules, then you want to look at the urlparser and cgi modules, I suspect. TJG -- http://mail.python.org/mailman/listinfo/python-list
PyGTK : a NEW simple way to code an app
I was a fan of "SimpleGladeApp/tepache way" to build a pygtk app. I've build a new efficient/dynamic way to build a pygtk app ... Here is an example : = class Fen(GladeApp): """ Window win .title="Hello" @delete_event VBox HBox Label jo .label="kokotte" entry myEntry .text="kuku" gtkBuTTon b2 .label="33" @clicked Label jo .label="koko" Button b .label="3" @clicked """ def init(self,m): self.jo.set_text(m) pass def on_b_clicked(self,*a): self.quit(3) def on_b2_clicked(self,*a): self.quit(33) def on_win_delete_event(self,*args): self.quit(4) f=Fen("koko2") print f.loop() = How it works : in fact, the __doc__ is converted as a "glade file" the tree of object is indented (like python way) you can see some common pygtk widget ... line starting with a dot is an property of the parent object. line starting with a @ is a declaration of a event of the parent object. widgets are not case sensitive, and can start with "Gtk". If a second word is provided it will be used as an "id", otherwise an unique id will be build according the type of widget. the window is created with glade, widgets are provided as attributs of the instance, and signals are autoconnected on method "on_[widgetId]_[event](self,*args)" (if a signal is missing in your class, it warns you at run time) It will not replace the use of glade-3 for complex widget ... but I think it's an easy way to code very easily/quickly a simple pygtk window/form. I think it could be really useful/handly for beginners too. for people which are involved in pygtk/python/gui ... i'd like to hear your comments/ideas ... Rq: i don't provide the code now, but it will be released in next version of "GladeApp" ( http://manatlan.infogami.com/GladeApp ) it works already, but i need to make "packing properties available" too ... -- http://mail.python.org/mailman/listinfo/python-list
Re: vim e autoindentazione commenti
Il Fri, 11 May 2007 13:15:01 GMT, Neil Cerutti ha scritto: >:help format-comments > > (Spiacente per la mia scrittura difettosa. Sto utilizzando il > traduttore di altavista.) Really sorry ^_^ I thought I was posting in it.comp.lang.python Thank you BTW! -- Alan Franzoni <[EMAIL PROTECTED]> - Togli .xyz dalla mia email per contattarmi. Remove .xyz from my address in order to contact me. - GPG Key Fingerprint (Key ID = FE068F3E): 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie look at Python and OO
On 2007-05-11, Duncan Booth <[EMAIL PROTECTED]> wrote: > Grant Edwards <[EMAIL PROTECTED]> wrote: > >> http://www.ariel.com.au/jokes/An_Interview_with_Bjarne_Stroustrup.html >> >> Maybe BS thought he was joking, but IMO, it's true. >> >> "Stroustrup: Remember the length of the average-sized 'C' >>project? About 6 months. Not nearly long enough for a guy >>with a wife and kids to earn enough to have a decent >>standard of living. Take the same project, design it in C++ >>and what do you get? I'll tell you. One to two years." >> > > I doubt very much that BS was involved at any point in writing it. You > forgot to quote the bit at the end: > > [Note - for the humor-impaired, not a true story] My bad. I completely missed that -- I thought it was a real interview where BS was joking. -- Grant Edwards grante Yow! I just remembered at something about a TOAD! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python REGEX Question
johnny wrote: > I need to get the content inside the bracket. > > eg. some characters before bracket (3.12345). > > I need to get whatever inside the (), in this case 3.12345. > > How do you do this with python regular expression? > >>> import re >>> x = re.search("[0-9.]+", "(3.12345)") >>> print x.group(0) 3.12345 There's a lot more to the re module, of course. I'd suggest reading the manual, but this should get you started. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: Towards faster Python implementations - theory
Tim Golden wrote: > sturlamolden wrote: > >> On May 8, 5:53 pm, John Nagle <[EMAIL PROTECTED]> wrote: >> >>> The point here is that we don't need language changes or >>> declarations >>> to make Python much faster. All we need are a few restrictions that >>> insure that, when you're doing something unusual, the compiler can >>> tell. > > I doubt if anyone disputes the gist of what you're > saying[*], viz that Python could be made faster by using > technique (a), (b) or (c) which have been successful elsewhere. At least > that it's worth investgating. > > But the relevant bit of your last paragraph is at the start: > "We should...". Unless someone or someones has the time, > inclination, money, backing, wherewithal etc. to implement > this or any other measure of speeding-up, it's all > pie-in-the-sky. Useful, maybe, as discussion of what > options are viable, but a project of this magnitude > doesn't just happen in some developer's lunchbreak. Focusing may help. Between Jython, PyPy, and Shed Skin, enough effort has been put in to produce something better than CPython, but none of those efforts resulted in something more useable than CPython. There's a "commercial grade Python" from ActiveState, but that's CPython in a cardboard box, I think. Another problem is that if the language is defined as "whatever gets put in CPython", that discourages other implementations. The language needs to be standards-based. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Better way to isolate string
I suppose a one liner would look better, but I am alway leery of these things 'breaking'. t = s.split('">')[-1].split('<')[0] s ='G132153' jh -- http://mail.python.org/mailman/listinfo/python-list
Simple Python REGEX Question
I need to get the content inside the bracket. eg. some characters before bracket (3.12345). I need to get whatever inside the (), in this case 3.12345. How do you do this with python regular expression? -- http://mail.python.org/mailman/listinfo/python-list
Re: path stuff
On May 10, 6:08 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 10 May 2007 19:04:30 -0300, fscked <[EMAIL PROTECTED]> > escribió: > > > > > > > ok, I lied, it is still doing the archived folders. Here is the code: > > > import os, sys > > from path import path > > > myfile = open("boxids.txt", "r", 0) > > for line in myfile: > > d = 'D:\\Dir\\' + path(line.strip()) > > for f in d.walkfiles('*Config*.xml'): > > for dirpath, dirnames, filenames in os.walk(d): > > if "Archived" in dirnames: > > dirnames.remove("Archived") #skip this directory > > print f > > print 'Done' > > > when it does the print f it still shows me the dirs i don't want to > > see. > > You are walking the directory structure *twice*, using two different > methods at the same time. Also, there is no standard `path` module, and > several implementations around, so it would be a good idea to tell us > which one you use. > If you want to omit a directory, and include just filenames matching a > pattern: > > import os, sys, os.path, fnmatch > > def findinterestingfiles(root_dir): >for dirpath, dirnames, filenames in os.walk(root_dir): > if "Archived" in dirnames: >dirnames.remove("Archived") > for filename in fnmatch.filter(filenames, '*Config*.xml'): >fullfn = os.path.join(dirpath, filename) >print fullfn > > myfile = open("boxids.txt", "r") > for line in myfile: >dirname = os.path.join('D:\\Dir\\', line.strip()) >findinterestingfiles(dirname): > myfile.close() > > -- > Gabriel Genellina- Hide quoted text - > > - Show quoted text - Should this code work? I get a syntax error and cannot figure out why. -- http://mail.python.org/mailman/listinfo/python-list
Re: Better way to isolate string
On May 11, 10:45 am, Tim Golden <[EMAIL PROTECTED]> wrote: > HMS Surprise wrote: > > I suppose a one liner would look better, but I am alway leery of these > > things 'breaking'. > > > t = s.split('">')[-1].split('<')[0] > > s ='G132153' > > Only if you're competing in an obscurity competition ;) > > If you're really confined to built-ins (ie you can't import > a single module) then just go with your original solution. > Why not? > > If you can import modules, then you want to look > at the urlparser and cgi modules, I suspect. > > TJG Thanks for replying Tim. Good point. jh -- http://mail.python.org/mailman/listinfo/python-list
Re: Towards faster Python implementations - theory
On 11 May, 18:04, John Nagle <[EMAIL PROTECTED]> wrote: > > Another problem is that if the language is defined as > "whatever gets put in CPython", that discourages other > implementations. The language needs to be standards-based. Indeed. This was suggested by one of the speakers at last year's EuroPython with reference to the various proposals to remove map, reduce, lambda and so on from the language. The opinion was that if Python implementations change and leave the users either on unsupported releases or with the work of migrating their code continuously and/or to features that they don't find as intuitive or appropriate, some people would rather migrate their code to a language which is standardised and which can remain agreeable for the foreseeable future. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: software testing articles
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Have you ever been interested in software testing? Giving you an in | depth analysis/knowledge on software testing!! Random non-Python IT topics are spam. Please desist. [Link to page with 75% ads deleted] -- http://mail.python.org/mailman/listinfo/python-list
Re: File modes
On May 10, 7:11 pm, Jon Pentland <[EMAIL PROTECTED]> wrote: > I don't really see the use for being able to do that. Have you tried > Well, I think I found a reason and it probably happens quite a bit. I open the file and read it into a list. I pop some elements from the list for processing and then write the shortened list back to disk to be available for other functions to access later, where later varies from seconds to days. There is no need to keep the file open till after the processing so I wish to write/flush/close right away. jvh -- http://mail.python.org/mailman/listinfo/python-list
File writing success
If file writing has no return value (http://docs.python.org/lib/bltin- file-objects.html), how do you know if the write was successful? Should one assume that if the open was successful then write are also? Thanks, jvh -- http://mail.python.org/mailman/listinfo/python-list
A newbie question about FileDialog in wxPython
Hi! I am opening files using the wx.FileDialog in wxPython. I want to modify the FileDialog such that some information about a highlighted file is displayed before I decide to open the file. This is what I tried: class ModifiedFileDialog(wx.FileDialog): def __init__(self,parent,message,wildcard,style): wx.FileDialog(self,parent,message,"","",wildcard,style) width,height = self.GetSizeTuple() self.SetSizeWH(width,height+100) # and so on... I get an error when I try to change the size or make other changes. Could someone tell me how to make this work or direct me to some reference? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Towards faster Python implementations - theory
"sturlamolden" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On May 10, 4:02 pm, Tim Golden <[EMAIL PROTECTED]> wrote: | I know, I know. But that doesn't stop me from envying what the Lisp | community has achieved. But do not let your envy stop you from noticing and appreciating what the Python commnunity has achieved. | Python still sucks if we are using it for scientific simulations, Not if you use extensions compiled from C or Fortran. Doing so is not cheating, any more than using the C-coded methods of the builtin types. Leveraging existing code and compilers was part of Python's design. With the Numeric extensions, produced by people at the US nuke labs. scientific simulations were, I think, Python's first killer ap. | Sure it is only 150-200 times slower than C for these tasks, As a general statement, nonsense. A LinPack inversion of a 10k x 10k matrix takes the same time whether called from Python or a C program. The miniscule extra overhead of Python is more than made up for by the ability to call LinPack and other functions interactively. The extended buffer protocol, championed by Travis Oliphant and slated for 3.0, will make cooperation between extensions much easier. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: File writing success
On May 11, 12:21 pm, HMS Surprise <[EMAIL PROTECTED]> wrote: > If file writing has no return value (http://docs.python.org/lib/bltin- > file-objects.html), how do you know if the write was successful? > Should one assume that if the open was successful then write are also? > > Thanks, > > jvh In Python, errors are not usually indicated by a return code. Instead, an exception should be raised for error conditions. The Python file semantics follows this. If the function returns instead of raising an exception, you may assume that the write completed successfully. Please note that the file objects may use buffers, so a call to the flush method may be needed to ensure that everything is on disk. K:\temp>dir Volume in drive K is LEXAR MEDIA Volume Serial Number is - Directory of K:\temp 05/11/2007 01:14 PM . 05/11/2007 01:14 PM .. 0 File(s) 0 bytes 2 Dir(s) 75,071,488 bytes free K:\temp>python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> out = file("test.txt", "wb") >>> out.write( "Hi!" * 8000 ) Traceback (most recent call last): File "", line 1, in IOError: [Errno 28] No space left on device >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: File writing success
On 2007-05-11, HMS Surprise <[EMAIL PROTECTED]> wrote: > If file writing has no return value (http://docs.python.org/lib/bltin- > file-objects.html), how do you know if the write was successful? Because no exception was thrown? Although bear in mind that some errors might not become apparent until you close or flush the file. -- http://mail.python.org/mailman/listinfo/python-list
Interesting list Validity (True/False)
Hello all, First let me appologise if this has been answered but I could not find an acurate answer to this interesting problem. If the following is true: C:\Python25\rg.py>python Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> [] == [] True >>> ['-o'] == [] False >>> ['-o'] == False False >>> Then why do I get the following results: C:\Python25\rg.py>help.py -o print arg ['-o'] type(arg): arg is True? False help.py version 1.0 Copyright RDEG (c) 2007 ['-o'] is an unrecognized option. Progam Exit (0) import sys _ver_ = 1.00 if '-h' in sys.argv or '--help' in sys.argv: print print "help.py Version", _ver_, "Copyright RDEG (c) 2007" print ''' Options : -h, --help -- display this message Progam Exit (0)''' sys.exit(0) else: arg = sys.argv[1:] print 'print arg', arg print 'type(arg):', type(arg) print 'arg is True?', arg == True print "help.py version", _ver_, "Copyright RDEG (c) 2007" print "", arg, "is an unrecognized option." print "Progam Exit (0)" sys.exit(0) -- http://mail.python.org/mailman/listinfo/python-list
stealth screen scraping with python?
Folks: I am screen scraping a large volume of data from Yahoo Finance each evening, and parsing with Beautiful Soup. I was wondering if anyone could give me some pointers on how to make it less obvious to Yahoo that this is what I am doing, as I fear that they probably monitor for this type of activity, and will soon ban my IP. -DE -- http://mail.python.org/mailman/listinfo/python-list
Re: stealth screen scraping with python?
On 11 May 2007 12:32:55 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Folks: > > I am screen scraping a large volume of data from Yahoo Finance each > evening, and parsing with Beautiful Soup. > > I was wondering if anyone could give me some pointers on how to make > it less obvious to Yahoo that this is what I am doing, as I fear that > they probably monitor for this type of activity, and will soon ban my > IP. > > -DE > So long as you are sending a regular http request, as from a browser, then they will have no way of knowing. Just keep your queries down to no more than once every 3-5 seconds and you should be fine. Rotate your IP, too, if you can. Dotan Cohen http://lyricslist.com/lyrics/artist_albums/110/carmen_eric.html http://what-is-what.com/what_is/eula.html -- http://mail.python.org/mailman/listinfo/python-list
Re: File writing success
HMS Surprise wrote: > If file writing has no return value (http://docs.python.org/lib/bltin- > file-objects.html), how do you know if the write was successful? If not, you'll get an error raised. Regards, -- . Facundo . Blog: http://www.taniquetil.com.ar/plog/ PyAr: http://www.python.org/ar/ -- http://mail.python.org/mailman/listinfo/python-list
Re: stealth screen scraping with python?
On May 11, 2:32 pm, [EMAIL PROTECTED] wrote: > Folks: > > I am screen scraping a large volume of data from Yahoo Finance each > evening, and parsing with Beautiful Soup. > > I was wondering if anyone could give me some pointers on how to make > it less obvious to Yahoo that this is what I am doing, as I fear that > they probably monitor for this type of activity, and will soon ban my > IP. > > -DE Depends on what you're doing exactly. I've done something like this and it only hits the page once: URL = 'http://quote.yahoo.com/d/quotes.csv?s=%s&f=sl1c1p2' TICKS = ('AMZN', 'AMD', 'EBAY', 'GOOG', 'MSFT', 'YHOO') u = urlopen(URL % ','.join(TICKS)) for data in u: tick, price, chg, per = data.split(',') # do something with data If you're grabbing all the data in one fell swoop (which is what you should aim for), then it's harder for Yahoo! to know what you're doing exactly. And I can't see why they'd care as that is all a browser does anyway. It's when you hit the site a bunch of times in a short period of time that sets off the alarms. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On 2007-05-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Then why do I get the following results: > C:\Python25\rg.py>help.py -o > print arg ['-o'] > type(arg): > arg is True? False > help.py version 1.0 Copyright RDEG (c) 2007 > ['-o'] is an unrecognized option. > Progam Exit (0) You got those results because that's what your program does. Were you intending it to do something else? If so, you're going to have to explain what you wanted, because we can't read your mind. -- Grant Edwards grante Yow! Hey, wait at a minute!! I want a visi.comdivorce!! ... you're not Clint Eastwood!! -- http://mail.python.org/mailman/listinfo/python-list
test
sorry just a test. Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 2:28 pm, [EMAIL PROTECTED] wrote: > Hello all, > > First let me appologise if this has been answered but I could not find > an acurate answer to this interesting problem. > > If the following is true: > C:\Python25\rg.py>python > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> [] == [] > True > >>> ['-o'] == [] > False > >>> ['-o'] == False > False > >>> > > Then why do I get the following results: > C:\Python25\rg.py>help.py -o > print arg ['-o'] > type(arg): > arg is True? False > help.py version 1.0 Copyright RDEG (c) 2007 > ['-o'] is an unrecognized option. > Progam Exit (0) > > > import sys > > _ver_ = 1.00 > > if '-h' in sys.argv or '--help' in sys.argv: > print > print "help.py Version", _ver_, "Copyright RDEG (c) 2007" > print ''' > > Options : -h, --help -- display this message > Progam Exit (0)''' > sys.exit(0) > else: > arg = sys.argv[1:] > print 'print arg', arg > print 'type(arg):', type(arg) > print 'arg is True?', arg == True > print "help.py version", _ver_, "Copyright RDEG (c) 2007" > print "", arg, "is an unrecognized option." > print "Progam Exit (0)" > sys.exit(0) > Does this clear things up? import sys _ver_ = 1.00 if '-h' in sys.argv or '--help' in sys.argv: print print "help.py Version", _ver_, "Copyright RDEG (c) 2007" print ''' Options : -h, --help -- display this message Progam Exit (0)''' sys.exit(0) else: arg = sys.argv[1:] print 'print arg', arg print 'type(arg):', type(arg) print 'arg is True?', arg == True print if arg: print 'was True' else: print 'was False' print print "help.py version", _ver_, "Copyright RDEG (c) 2007" print "", arg, "is an unrecognized option." print "Progam Exit (0)" sys.exit(0) ##C:\python25\user>python arghhh!.py -o ##print arg ['-o'] ##type(arg): ##arg is True? False ## ##was True ## ##help.py version 1.0 Copyright RDEG (c) 2007 ## ['-o'] is an unrecognized option. ##Progam Exit (0) ##C:\python25\user>python arghhh!.py ##print arg [] ##type(arg): ##arg is True? False ## ##was False ## ##help.py version 1.0 Copyright RDEG (c) 2007 ## [] is an unrecognized option. ##Progam Exit (0) -- http://mail.python.org/mailman/listinfo/python-list
Re: test
Joe Eagar <[EMAIL PROTECTED]> writes: > sorry just a test. Sorry, you failed. You missed alt.test by a mile. sherm-- -- Web Hosting by West Virginians, for West Virginians: http://wv-www.net Cocoa programming in Perl: http://camelbones.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On Fri, May 11, 2007 at 01:20:44PM -0700, [EMAIL PROTECTED] wrote: > On May 11, 3:55 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > > You got those results because that's what your program does. > > > > Were you intending it to do something else? If so, you're > > going to have to explain what you wanted, because we can't > According to my output, it seems that arg is False even when I > give an option of '-o' which according to the book should be > True. No? '-o' is not equal to True. However, that does not mean it evaluates to false when tested by an if or while statement. > If arg == ['-o'] then shouldn't arg == True return True and > skip the if? No. See the folloing link regarding the "truth value" of an object: http://docs.python.org/lib/truth.html There are many objects other than True that evaluate to "true" in the context of an if/while statement. Just because an objecty has a "true" truth-value doesn't mean that it is equal to the True object. -- Grant Edwards grante Yow! Why don't you ever at enter any CONTESTS, visi.comMarvin?? Don't you know your own ZIPCODE? -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 2:28 pm, [EMAIL PROTECTED] wrote: > > > > > > > Hello all, > > > First let me appologise if this has been answered but I could not find > > an acurate answer to this interesting problem. > > > If the following is true: > > C:\Python25\rg.py>python > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > > bit (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more > > information. > > >>> [] == [] > > True > > >>> ['-o'] == [] > > False > > >>> ['-o'] == False > > False > > > Then why do I get the following results: > > C:\Python25\rg.py>help.py -o > > print arg ['-o'] > > type(arg): > > arg is True? False > > help.py version 1.0 Copyright RDEG (c) 2007 > > ['-o'] is an unrecognized option. > > Progam Exit (0) > > > > > import sys > > > _ver_ = 1.00 > > > if '-h' in sys.argv or '--help' in sys.argv: > > print > > print "help.py Version", _ver_, "Copyright RDEG (c) 2007" > > print ''' > > > Options : -h, --help -- display this message > > Progam Exit (0)''' > > sys.exit(0) > > else: > > arg = sys.argv[1:] > > print 'print arg', arg > > print 'type(arg):', type(arg) > > print 'arg is True?', arg == True > > print "help.py version", _ver_, "Copyright RDEG (c) 2007" > > print "", arg, "is an unrecognized option." > > print "Progam Exit (0)" > > sys.exit(0) > > > I hope this helps (I have tried to post this twice already but it seems to be going somewhere else) you help me. What I would like to happen is: else: arg = sys.argv[1:] print 'print arg', arg print 'type(arg):', type(arg) print 'arg is True?', arg == True if arg != True: print "No Option Provided" print "help.py version", _ver_, "Copyright RDEG (c) 2007" print "", arg, "is an unrecognized option." print "Progam Exit (0)" sys.exit(0) But as you can see by my output ['-o'] seems to be False as well as [] so the if happens regardless. According to the "Book", ['-o'] should return True which should fail the if, no? -- http://mail.python.org/mailman/listinfo/python-list
Path python versions and Macosx
Hi everyone, I use python on macosx with textmate as editor (great program). I also use macport to install unix programs from the command line and I find it great too. Well I would like to have all my modules in the path when I'm using textmate AND when I use the commandline (ipython), but because textmate and the command line use different python versions they also search in different places.. I found somewhere to write .pythonrc.py like this #!/usr/bin/env python import sys PATH='/opt/local/lib/python2.4/site-packages/' sys.path.append(PATH) del sys But it doesn't work either, I also tried to append this PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/ local/lib/python2.4/site-packages:${PATH} to .bash_profile but nothing. Where should I set this variables?? Thanks a lot -- http://mail.python.org/mailman/listinfo/python-list
name capitalization of built-in types, True, and False
I see that naming conventions are such that classes usually get named CamelCase. So why are the built-in types named all lowercase (like list, dict, set, bool, etc.)? And names for instances of classes are usually written in lowercase, like foo in ``foo = CamelCase()``. So why are True and False (instances of bool) capitalized? Shouldn't they be "true" and "false"? Same goes for None. -- http://mail.python.org/mailman/listinfo/python-list
Time
I need to convert the string below into epoch seconds so that I can perform substractions and additions. I assume I will need to break it up into a time_t struct and use mktime. Two questions if you will please: Is there a way to use multiple separator characters for split similar to awk's [|] style? Could you point to an example of a python time_t struct? 05/11/2007 15:30 Thanks, jvh -- http://mail.python.org/mailman/listinfo/python-list
Re: Time
> > Could you point to an example of a python time_t struct? > Or maybe that should be a tm struct??? -- http://mail.python.org/mailman/listinfo/python-list
Re: Simulating simple electric circuits
Dave Baum wrote: > Sounds reasonable. Depending on the size of your network, I might > not worry too much about precomputing and saving information. Thanks. Yes, I'm actually testing it presently without any optimizations and it runs very well. > If your circuit has loops in it (where the output of a later relay > circles back to an earlier relay's coil), then it is possible for > the circuit to oscillate, so you might have to be careful about > this. That's no substancial problem, with real relay circuits this happens sometimes too :) (even in the systems I'm modelling) After all, I'm quite pleased now with how well the last approach I mentioned works. I've been able to model a medium complex switching sequence today, and it worked flawlessly. (The only problem I have now arises when I make relays react delayed, using Twisted's reactor.callLater. Sometimes, a relay gets current and loses it shortly after, but the event loop in rare cases executes the status change functions the other way round ("no current", then "current"). I've been trying to fix that by detection if a timer already runs. Anyhow, the inconsistencies only vanish if I let the relays react delayless again. I'm going to have to look into this further ...) Regards, Björn P.S.: If anyone happens to be interested in details, just ask, I'll post some code. -- BOFH excuse #319: Your computer hasn't been returning all the bits it gets from the Internet. -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On Fri, 2007-05-11 at 12:28 -0700, [EMAIL PROTECTED] wrote: > Hello all, > > First let me appologise if this has been answered but I could not find > an acurate answer to this interesting problem. > > If the following is true: > C:\Python25\rg.py>python > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > bit (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> [] == [] > True > >>> ['-o'] == [] > False > >>> ['-o'] == False > False > >>> Your confusion stems from the fact that for a given object, the answer to the following three questions can be vastly different: a) Is the object identical to True? b) Is the object equal to True? c) Is the object considered to be True in an "if" statement? Observe: >>> def check_trueness(obj): ...if obj is True: print repr(obj), "is identical to True." ...else: print repr(obj), "is not identical to True." ...if obj == True: print repr(obj), "is equal to True." ...else: print repr(obj), "is not equal to True." ...if obj: print repr(obj), "is considered to be True by if." ...else: print repr(obj), "is not considered to be True by if." ... >>> check_trueness(True) True is identical to True. True is equal to True. True is considered to be True by if. >>> check_trueness(1) 1 is not identical to True. 1 is equal to True. 1 is considered to be True by if. >>> check_trueness([1]) [1] is not identical to True. [1] is not equal to True. [1] is considered to be True by if. >>> check_trueness([]) [] is not identical to True. [] is not equal to True. [] is not considered to be True by if. Testing whether an object is equal to True is a much stronger test than whether it is considered to be True in an 'if' statement, and the test for identity is stronger still. Testing whether an object is equal to True or identical to True is useless in most Python programs. So, rather than doing this: if thing==True: # blah Just do this: if thing: # blah Hope this helps, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Problems with grid() layout under tkinter
Dear all I am trying to make a small wrapper program for textbased program and it is going well but I have one problem. Namely that I simply do not understand how this grid thing work. I have assigned every widget a specific placement in a grid but when I am running the program it looks very strange. I hope you can help me. A example of the program http://tjansson.dyndns.dk/apache2-default/strange-grid.jpg and the code http://tjansson.dyndns.dk/tjansson/gui.py Kind regards Thomas Jansson -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 4:32 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On Fri, May 11, 2007 at 01:20:44PM -0700, [EMAIL PROTECTED] > wrote: > > > On May 11, 3:55 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > > > You got those results because that's what your program does. > > > > Were you intending it to do something else? If so, you're > > > going to have to explain what you wanted, because we can't > > According to my output, it seems that arg is False even when I > > give an option of '-o' which according to the book should be > > True. No? > > '-o' is not equal to True. However, that does not mean it > evaluates to false when tested by an if or while statement. > > > If arg == ['-o'] then shouldn't arg == True return True and > > skip the if? > > No. See the folloing link regarding the "truth value" of an > object: > > http://docs.python.org/lib/truth.html > > There are many objects other than True that evaluate to "true" > in the context of an if/while statement. Just because an > objecty has a "true" truth-value doesn't mean that it is equal > to the True object. > > -- > Grant Edwards grante Yow! Why don't you ever > at enter any CONTESTS, >visi.comMarvin?? Don't you know >your own ZIPCODE? OK. Then how would you differenciate between a call with an option versus one without (e.g. help.py -o (where arg == ['-o']) Vs. help.py (where arg == []))? -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On Fri, 2007-05-11 at 14:07 -0700, [EMAIL PROTECTED] wrote: > OK. Then how would you differenciate between a call with an option > versus one without (e.g. help.py -o (where arg == ['-o']) Vs. help.py > (where arg == []))? if arg: print "With options" else: print "Without options" -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 5:07 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-05-11 at 12:28 -0700, [EMAIL PROTECTED] wrote: > > Hello all, > > > First let me appologise if this has been answered but I could not find > > an acurate answer to this interesting problem. > > > If the following is true: > > C:\Python25\rg.py>python > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > > bit (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more > > information. > > >>> [] == [] > > True > > >>> ['-o'] == [] > > False > > >>> ['-o'] == False > > False > > Your confusion stems from the fact that for a given object, the answer > to the following three questions can be vastly different: > a) Is the object identical to True? > b) Is the object equal to True? > c) Is the object considered to be True in an "if" statement? > > Observe: > > >>> def check_trueness(obj): > > ...if obj is True: print repr(obj), "is identical to True." > ...else: print repr(obj), "is not identical to True." > ...if obj == True: print repr(obj), "is equal to True." > ...else: print repr(obj), "is not equal to True." > ...if obj: print repr(obj), "is considered to be True by if." > ...else: print repr(obj), "is not considered to be True by if." > ...>>> check_trueness(True) > > True is identical to True. > True is equal to True. > True is considered to be True by if.>>> check_trueness(1) > > 1 is not identical to True. > 1 is equal to True. > 1 is considered to be True by if.>>> check_trueness([1]) > > [1] is not identical to True. > [1] is not equal to True. > [1] is considered to be True by if.>>> check_trueness([]) > > [] is not identical to True. > [] is not equal to True. > [] is not considered to be True by if. > > Testing whether an object is equal to True is a much stronger test than > whether it is considered to be True in an 'if' statement, and the test > for identity is stronger still. Testing whether an object is equal to > True or identical to True is useless in most Python programs. > > So, rather than doing this: > > if thing==True: ># blah > > Just do this: > > if thing: ># blah > > Hope this helps, > > -- > Carsten Haesehttp://informixdb.sourceforge.net- Hide quoted text - > > - Show quoted text - Thanks Carsten (& all), I will give the if thing: # blah trick. I guess I am starting to seem my own confusion. As Grant mentioned, I was comparing ['-o'] to True which of course is False :o) However, how would you test for the falsness of the object arg? -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On Fri, 2007-05-11 at 14:12 -0700, [EMAIL PROTECTED] wrote: > However, how would you test for the falsness of the object arg? if not arg: # stuff -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 5:12 pm, [EMAIL PROTECTED] wrote: > On May 11, 5:07 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > > > > > On Fri, 2007-05-11 at 12:28 -0700, [EMAIL PROTECTED] wrote: > > > Hello all, > > > > First let me appologise if this has been answered but I could not find > > > an acurate answer to this interesting problem. > > > > If the following is true: > > > C:\Python25\rg.py>python > > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > > > bit (Intel)] on > > > win32 > > > Type "help", "copyright", "credits" or "license" for more > > > information. > > > >>> [] == [] > > > True > > > >>> ['-o'] == [] > > > False > > > >>> ['-o'] == False > > > False > > > Your confusion stems from the fact that for a given object, the answer > > to the following three questions can be vastly different: > > a) Is the object identical to True? > > b) Is the object equal to True? > > c) Is the object considered to be True in an "if" statement? > > > Observe: > > > >>> def check_trueness(obj): > > > ...if obj is True: print repr(obj), "is identical to True." > > ...else: print repr(obj), "is not identical to True." > > ...if obj == True: print repr(obj), "is equal to True." > > ...else: print repr(obj), "is not equal to True." > > ...if obj: print repr(obj), "is considered to be True by if." > > ...else: print repr(obj), "is not considered to be True by if." > > ...>>> check_trueness(True) > > > True is identical to True. > > True is equal to True. > > True is considered to be True by if.>>> check_trueness(1) > > > 1 is not identical to True. > > 1 is equal to True. > > 1 is considered to be True by if.>>> check_trueness([1]) > > > [1] is not identical to True. > > [1] is not equal to True. > > [1] is considered to be True by if.>>> check_trueness([]) > > > [] is not identical to True. > > [] is not equal to True. > > [] is not considered to be True by if. > > > Testing whether an object is equal to True is a much stronger test than > > whether it is considered to be True in an 'if' statement, and the test > > for identity is stronger still. Testing whether an object is equal to > > True or identical to True is useless in most Python programs. > > > So, rather than doing this: > > > if thing==True: > ># blah > > > Just do this: > > > if thing: > ># blah > > > Hope this helps, > > > -- > > Carsten Haesehttp://informixdb.sourceforge.net-Hide quoted text - > > > - Show quoted text - > > Thanks Carsten (& all), I will give the if thing: # blah trick. I > guess I am starting to seem my own confusion. As Grant mentioned, I > was comparing ['-o'] to True which of course is False :o) > > However, how would you test for the falsness of the object arg?- Hide quoted > text - > > - Show quoted text - Would that be arg is not True: # blah.? -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 5:19 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-05-11 at 14:12 -0700, [EMAIL PROTECTED] wrote: > > However, how would you test for the falsness of the object arg? > > if not arg: ># stuff > > -- > Carsten Haesehttp://informixdb.sourceforge.net I think that is the ticket Carsten! Thanks for all the good information all y'all. -- http://mail.python.org/mailman/listinfo/python-list
Re: setting extra data to a wx.textctrl
[EMAIL PROTECTED] wrote: > On May 10, 10:51 pm, Pom <[EMAIL PROTECTED]> wrote: >> Hello group! >> >> I have an application which uses a lot of mysql data fields, all the >> same data type (floats). >> >> I created a panel which executes a "SELECT * FROM tablename" and makes >> as much fields as needed, using de cursor.description as wx.statictext >> and the cursors field contents copied into wx.textctrls. >> >> At creation time, I loop over all the fields in the record and create a >> tuple which contains ((textctrl1, fieldname1), (textctrl2, fieldname2), >> ...) so I can keep track of which textctrl holds which piece of fielddata. >> >> The problem I'm having is: >> >> to know the fieldname in an text_event, I use event.GetEventObject(), >> then perform an iteration over the tuple and when I find a match I use >> the field name to update the mysqltable. >> When having a few fields, this is ok. But I have over 100 fields in 1 >> record and it really slows things down. >> >> Now my question is: should I use a python dictionary (with an object as >> first lookup field) ? >> >> On windows, I've seen a "Tag" property in a textbox which was meant to >> be used for this kind of stuff. Maybe it's better to override the >> wx.textctrl so I can add an extra string value? >> >> Anyone having the best solution for this ? >> >> thx! > > Both of your ideas seem sound to me. You could also look into using > statically assigned IDs that increment by one. Then you could just > increment or decrement by one and look up the field by ID. Of course, > that might get ugly and there are some IDs that are supposedly > reserved. But it's an idea. > > Also, I've heard that Dabo (http://dabodev.com/) is good for database > work. You might look at that. To get the quickest and most on target > answers to wxPython questions, I recommend the wxPython users-group > mailing list: http://www.wxpython.org/maillist.php > > Mike > thx! -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
wrote in news:[EMAIL PROTECTED] in comp.lang.python: > >>> [] == [] > True > >>> ['-o'] == [] > False > >>> ['-o'] == False > False > >>> To test wether something is true use if. To test wether something is false use if not. The python values "True" and "False" are for when you need to *store* a boolean value (for later testing). I you want to to see if an arbitry expression would test as true or false at the interactive prompt use bool(): >>> bool([]) False >>> bool(['-o']) True >>> There is *never* any need to write things like: expression == True or: expression == False Once you stop doing this things will become much simpler. Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
On May 11, 3:36 pm, [EMAIL PROTECTED] wrote: > On May 11, 2:28 pm, [EMAIL PROTECTED] wrote: > > > > > > > > > > Hello all, > > > > First let me appologise if this has been answered but I could not find > > > an acurate answer to this interesting problem. > > > > If the following is true: > > > C:\Python25\rg.py>python > > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 > > > bit (Intel)] on > > > win32 > > > Type "help", "copyright", "credits" or "license" for more > > > information. > > > >>> [] == [] > > > True > > > >>> ['-o'] == [] > > > False > > > >>> ['-o'] == False > > > False > > > > Then why do I get the following results: > > > C:\Python25\rg.py>help.py -o > > > print arg ['-o'] > > > type(arg): > > > arg is True? False > > > help.py version 1.0 Copyright RDEG (c) 2007 > > > ['-o'] is an unrecognized option. > > > Progam Exit (0) > > > > > > > import sys > > > > _ver_ = 1.00 > > > > if '-h' in sys.argv or '--help' in sys.argv: > > > print > > > print "help.py Version", _ver_, "Copyright RDEG (c) 2007" > > > print ''' > > > > Options : -h, --help -- display this message > > > Progam Exit (0)''' > > > sys.exit(0) > > > else: > > > arg = sys.argv[1:] > > > print 'print arg', arg > > > print 'type(arg):', type(arg) > > > print 'arg is True?', arg == True > > > print "help.py version", _ver_, "Copyright RDEG (c) 2007" > > > print "", arg, "is an unrecognized option." > > > print "Progam Exit (0)" > > > sys.exit(0) > > > > > I hope this helps (I have tried to post this twice already but it > seems to be going somewhere else) you help me. > > What I would like to happen is: > else: > arg = sys.argv[1:] > print 'print arg', arg > print 'type(arg):', type(arg) > print 'arg is True?', arg == True > if arg != True: > print "No Option Provided" > print "help.py version", _ver_, "Copyright RDEG (c) 2007" > print "", arg, "is an unrecognized option." > print "Progam Exit (0)" > sys.exit(0) > > But as you can see by my output ['-o'] seems to be False as well as [] > so the if happens regardless. > > According to the "Book", ['-o'] should return True which should fail > the if, no? You're mistaking the porperties of an object for the object itself. if arg: tests the property (of being empty). if arg==True: tests the type property (whether a list is a boolean). Change the code I gave above to be: print if arg: print 'The argument given was:',arg else: print 'No argument given' print then you'll get ##C:\python25\user>python arghhh!.py -o ##print arg ['-o'] ##type(arg): ##arg is True? False ## ##The argument given was: ['-o'] ## ##help.py version 1.0 Copyright RDEG (c) 2007 ## ['-o'] is an unrecognized option. ##Progam Exit (0) ## ##C:\python25\user>python arghhh!.py ##print arg [] ##type(arg): ##arg is True? False ## ##No argument given ## ##help.py version 1.0 Copyright RDEG (c) 2007 ## [] is an unrecognized option. ##Progam Exit (0) -- http://mail.python.org/mailman/listinfo/python-list
Re: Interesting list Validity (True/False)
Just an update of my output after Carsten and company's advice: C:\Python25\rg.py>help.py -h help.py Version 1.0 Copyright RDEG (c) 2007 Options : -h, --help -- display this message Progam Exit (0) C:\Python25\rg.py>help.py -i print arg ['-i'] type(arg): arg is True? False help.py version 1.0 Copyright RDEG (c) 2007 ['-i'] is an unrecognized option. Progam Exit (0) C:\Python25\rg.py>help.py -i help.py version 1.0 Copyright RDEG (c) 2007 ['-i'] is an unrecognized option. Progam Exit (0) C:\Python25\rg.py>help.py No Option provided help.py version 1.0 Copyright RDEG (c) 2007 No Option is an unrecognized option. Progam Exit (0) Thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Time
Sorry, reading a little closer I see that the time tuple is apparently an ordinary list. jvh -- http://mail.python.org/mailman/listinfo/python-list
OMG BRITNEYS AT IT AGAIN AGAIN!!!!!!
http://britneyboobs.blogspot.com/2007/05/britney-spears-slips-up-again-exposes.html - Exclusive pics of Britney Spears.. -- http://mail.python.org/mailman/listinfo/python-list
Re: OMG BRITNEYS AT IT AGAIN AGAIN!!!!!!
On 2007-05-11, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > http://britneyboobs.blogspot.com/2007/05/britney-spears-slips-up-again-exposes.html > - Exclusive pics of Britney Spears.. Britneyboobs what?... you take pride in being one? nb -- http://mail.python.org/mailman/listinfo/python-list
Recursion limit problems
Hello everyone, I am runing into recursion limit problems. I have found that the culprit was related to the __hash__ function that I had assigned to the objects that were added to a set. Basically my __hash__ function is the following: def __hash__(self): out_int = 0 for property,value in self: out_int ^= hash( property )^hash( value ) return out_int And the iterator for this object is: def __iter__(self): for property,value in self.__dict__.iteritems(): yield property,value After commenting the __hash__ function and using the default provided by Python (I suppose it is based on the position in memory of the object), the recursion limit problems went away. (This problem was happening even after increasing the recursion limit to the maximum of my platform, MacOSX). I am not that versed in Python, so I don't know exactly I could do to overcome this problem, any ideas are deeply appreciated. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
py2exe LoadLibrary question
Yep, it's the old LoadLibrary failed problem. I understand that python24.dll is required for the executable to run, but I'm going to be building a few of these executables and I don't want to have to bundle python24 along with each one. We have python24.dll installed in c:/windows/system32, why is loadlibrary not finding it? Is there an option I can specify to add c:/windows/system32 to the loadlibrary search path? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
matplotlib: howto set title of whole window?
hi all, does anyone know howto set title of whole window? (I mean not just area above plot but string in the same line where buttons 'close', 'iconify', 'fullscreen' are situated) Thx, D. -- http://mail.python.org/mailman/listinfo/python-list
find out all threads?
Hi, I have a written a C program which makes use of python embedding. I want to find out all threads that a loaded module has started. But I can't find anything about this in the docs. Is it possible? -- http://mail.python.org/mailman/listinfo/python-list
mmap thoughts
I've been thinking about the Python mmap module quite a bit during the last couple of days. Sadly most of it has just been thinking ... and reading pages from Google searches ... and very little of it as been coding. Mostly it's just academic curiosity (I might be teaching an "overview of programming" class in a few months, and I'd use Python for most of the practical examples to cover a broad range of programming topics, including the whole concept of memory mapping used, on the one hand, as a file access abstraction and as a form of inter-process shared memory, on the other). Initial observations: * The standard library reference could use some good examples. At least of those should show use of both anonymous and named mmap objects as shared memory. * On Linux (various versions) using Python 2.4.x (for at least 2.4.4 and 2.4.2) if I create on mmap'ing in one process, then open the file using 'w' or 'w+' or 'w+b' in another process then my first process dies with "Bus Error" This should probably be documented. (It's fine if I use 'a' (append) modes for opening the file). * It seems that it's also necessary to extend a file to a given size before creating a mapping on it. In other words you can't mmap a newly created, 0-length file. So it seems like the simplest example of a newly created, non-anonymous file mapping would be something like: sz = (1024 * 1024 * 1024 * 2 ) - 1 f=open('/tmp/mmtst.tmp','w+b') f.seek(sz) f.write('\0') f.flush() mm = mmap.mmap(f.fileno(), sz, mmap.MAP_SHARED) f.close() Even creating a zero length file and trying to create a zero-length mapping on it (with mmap(f.fileno(),0,...) ... with a mind towards using mmap's .resize() method on it doesn't work. (raises: EnvironmentError: "Errno 22: Invalid Argument"). BTW: the call to f.flush() does seem to be required at least in my environments (Linux under 2.6 kernels various distributions and the aforementioned 2.4.2 and 2.4.4 versions of Python. * The mmtst.tmp file is "sparse" of course. So its size in the example above is 2GB ... but the disk usage (du command) on it is only a few KB (depending on your filesystem cluster size etc). * Using a function like len(mm[:]) forces the kernel's filesystem to return a huge stream of NUL characters. (And might thrash your system caches a little). * On my SuSE/Novell 10.1 system, using Python 2.4.2 (their RPM 2.4.2-18) I found that anonymous mmaps would raise an EnvironmentError. Using the same code on 2.4.4 on my Debian and Fedora Core 6 system worked with no problem: anonmm == mmap.mmap(-1,4096,mmap.MAP_ANONYMOUS|mmap.MAP_SHARED) ... and also testing on their 2.4.2-18.5 update with the same results: Python 2.4.2 (#1, Oct 13 2006, 17:11:24) [GCC 4.1.0 (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import mmap >>> mm = mmap.mmap(-1,4096, mmap.MAP_ANONYMOUS|mmap.MAP_SHARED) Traceback (most recent call last): File "", line 1, in ? EnvironmentError: [Errno 22] Invalid argument >>> [EMAIL PROTECTED]:~> uname -a Linux dhcphostname 2.6.16.13-4-default #1 Wed May 3 ... * On the troublesome SuSE/Novell box using: f = open('/dev/zero','w+') anonmm == mmap.mmap(f.fileno(),4096, mmap.MAP_ANONYMOUS|mmap.MAP_SHARED) ... seems to work. However, a .resize() on that raises the same EnvironmentError I was getting before. * As noted in a few discussions in the past Python's mmap() function doesn't take an "offset" parameter ... it always uses an offset of 0 (It seems like a patch is slated for inclusion in some future release?) * On 32-bit Linux systems (or on systems running a 32-bit compilation of Python) 2GB is, of course, the upper limit of an mmap'ing The ability to map portions of larger files is a key motivation to include the previously mentioned "offset" patch. Other thoughts: (Going beyond initial observations, now) * I haven't tested this, but I presume that anonymous|shared mappings on UNIX can only be shared with child/descendant processes ... since there's no sort of "handle" or "key" that can be passed to unrelated processes via any other IPC method; so only fork() based inheritence will work. * Another thing I haven't tested, yet: how robust are shared mappings to adjacent/non-overlapping concurrent writes by multiple processes? I'm hoping that you can reliably have processes writing updates to small, pre-assigned, blocks in the mmap'ing without contention issues. I plan to write some "hammer test" code to test this theory ... and run it for awhile on a few multi-core/SMP systems. * It would be nice to bu
Re: Path python versions and Macosx
On May 11, 1:36 pm, andrea <[EMAIL PROTECTED]> wrote: > Hi everyone, > I use python on macosx with textmate as editor (great program). > > I also use macport to install unix programs from the command line and > I find it great too. > Well I would like to have all my modules in the path when I'm using > textmate AND when I use the commandline (ipython), but because > textmate and the command line use different python versions they also > search in different places.. > > I found somewhere to write .pythonrc.py like this > > #!/usr/bin/env python > import sys > PATH='/opt/local/lib/python2.4/site-packages/' > sys.path.append(PATH) > del sys > > But it doesn't work either, I also tried to append this > PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/ > local/lib/python2.4/site-packages:${PATH} > to .bash_profile but nothing. > > Where should I set this variables?? > > Thanks a lot You can set environment variables for gui apps with this freeware: http://www.versiontracker.com/dyn/moreinfo/macosx/15073 You can edit some text files as well, but this thing just makes it much easier. ~Sean -- http://mail.python.org/mailman/listinfo/python-list
Re: Time
On May 12, 7:46 am, HMS Surprise <[EMAIL PROTECTED]> wrote: [first message] HS ==> I need to convert the string below into epoch seconds so that I can perform substractions and additions. JM ==> I presume you mean "seconds since the epoch". You don't need to do that. HS ==> I assume I will need to break it up into a time_t struct and use mktime. JM ==> You assume wrongly. The time module exists (IMVHO) solely as a crutch for people who are converting C etc code that uses the time.h functions from the C standard library. If you are starting off from scratch, use the Python datetime module -- especially if you need to store and manipulate pre-1970 dates; e.g. the date of birth of anyone aged more than about 37.5 years :-) HS ==> Two questions if you will please: Is there a way to use multiple separator characters for split similar to awk's [|] style? JM ==> Only if you can find such a way in the manual. HS ==> Could you point to an example of a python time_t struct? JM ==> Python doesn't have that; it's a C concept HS ==> 05/11/2007 15:30 [second message] HS==> > Could you point to an example of a python time_t struct? Or maybe that should be a tm struct??? JM ==> See previous answer. [third message] HS ==> Sorry, reading a little closer I see that the time tuple is apparently an ordinary list. JM ==> Huh? A tuple is a tuple. A tuple is not a list, not even a very extraordinary one. If you are desperate to use the time module, try this: >>> import time >>> s = "05/11/2007 15:30" >>> fmt = "%m/%d/%Y %H:%M" # Given the current date, I'm presuming that your example indicates that you adhere to the "month-first-contrary-to-common-sense" religion :-) >>> time.strptime(s, fmt) (2007, 5, 11, 15, 30, 0, 4, 131, -1) otherwise: >>> import datetime >>> d1 = datetime.datetime.strptime(s, fmt) >>> d1 datetime.datetime(2007, 5, 11, 15, 30) >>> d2 = datetime.datetime(2007, 5, 1) >>> d2 datetime.datetime(2007, 5, 1, 0, 0) >>> delta = d1 - d2 >>> delta datetime.timedelta(10, 55800) >>> days_diff = delta.days + delta.seconds / 60. / 60. / 24. >>> days_diff 10.6458334 Do read the datetime module documentation for more info ... in particular the timedelta object has a microseconds attribute; in general there is a whole heap of functionality in there. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about bsddb
Thanks for the suggestion, I do remember reading that, but I don't think that helped much. I found experimenting around with the different settings, that the cache size is where the problem was. I've got it set to 1.5 GB and it's pretty happy at the moment, and the reduction in build time is a fraction of what it used to be. Thanks again for all the suggestions. Regards, JM -- http://mail.python.org/mailman/listinfo/python-list
Re: matplotlib: howto set title of whole window?
On May 11, 3:44 pm, dmitrey <[EMAIL PROTECTED]> wrote: > hi all, > does anyone know howto set title of whole window? (I mean not just > area above plot but string in the same line where buttons 'close', > 'iconify', 'fullscreen' are situated) > Use coordinates to set a title for the current figure. E.g., from pylab import * from matplotlib.font_manager import FontProperties figtitle = 'This is my title above all subplots' t = gcf().text(0.5, 0.95, figtitle, horizontalalignment='center', fontproperties=FontProperties(size=16)) subplot(121) subplot(122) show() -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple Python REGEX Question
On May 12, 2:21 am, Gary Herron <[EMAIL PROTECTED]> wrote: > johnny wrote: > > I need to get the content inside the bracket. > > > eg. some characters before bracket (3.12345). > > > I need to get whatever inside the (), in this case 3.12345. > > > How do you do this with python regular expression? > > >>> import re > >>> x = re.search("[0-9.]+", "(3.12345)") > >>> print x.group(0) > > 3.12345 > > There's a lot more to the re module, of course. I'd suggest reading the > manual, but this should get you started. > >>> s = "some chars like 987 before the bracket (3.12345) etc" >>> x = re.search("[0-9.]+", s) >>> x.group(0) '987' OP sez: "I need to get the content inside the bracket" OP sez: "I need to get whatever inside the ()" My interpretation: >>> for s in ['foo(123)bar', 'foo(123))bar', 'foo()bar', 'foobar']: ... x = re.search(r"\([^)]*\)", s) ... print repr(x and x.group(0)[1:-1]) ... '123' '123' '' None -- http://mail.python.org/mailman/listinfo/python-list
docs patch: dicts and sets
This is an attempt to synthesize Bill and Carsten's proposals. (I'm changing the subject line to better match the topic.) http://docs.python.org/lib/typesmapping.html: for footnote (3) Keys and values are listed in an arbitrary order. This order is indeterminate and generally depends on factors outside the scope of the containing program. However, if items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond. http://docs.python.org/lib/types-set.html: append a new sentence to 2nd par. Iteration over a set returns elements in an indeterminate order,which generally depends on factors outside the scope of the containing program. Alan Isaac -- http://mail.python.org/mailman/listinfo/python-list