Re: How to use tk.call ?
On 29 May 2006 21:13:07 -0700, <[EMAIL PROTECTED]> wrote: >>> self.table.bind("",self.table.tk.call(self.table._w,'yview','scroll',-5,'units') > >> I haven't used Table, but are you sure that what you are calling >> "self.table" here actually has mouse focus? > >> James > > Yup, I click on the table, and then frantically work the mouse wheel to > no > effect... ... which is quite normal, since you actually didn't define any binding. What you did is: - *Call* self.table.tk.call(self.table._w,'yview','scroll',-5,'units'), which did the scroll; - Pass the *result* of this call (which is probably None or the empty string) as the second parameter of self.table.bind. So no binding was defined. One solution is to define the binding via a lambda, like this (untested): self.table.bind("", lambda e, t=self.table: t.tk.call(t._w, 'yview', 'scroll', -5, 'units')) For more information on lambda, see here: http://docs.python.org/tut/node6.html#SECTION00675 HTH -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Ricerca Programmatore Python
I read your replies and am really sorry for the trouble. Best regards, Nic "Boris Borcic" <[EMAIL PROTECTED]> ha scritto nel messaggio news:[EMAIL PROTECTED] > Nic wrote: >> Please accept my apologies for the use of the Italian language. > > accepted -- http://mail.python.org/mailman/listinfo/python-list
Re: Very good Python Book. Free download : Beginning Python: From Novice to Professional
Hi, I hope you all know about wikibooks, it's like wikipedia but for books. It is also "some kind of openware" (my favourite expression). I specifically think about http://en.wikibooks.org/wiki/Programming:Python I have thought about adding to it but I am low on time - this randomchoice(["is","could be"]) a great book. Please read and/or add if you are one of the nice guys. Ciao, PER9000 "It is a gift. A gift to the foes of 'the Terrorists'. Why not use this 'terrorism'? Long has my father, 'George Bush', kept the forces of 'the terrorists' at bay. By the blood of our people are your lands kept safe. Give 'the land of the brave' the weapon of the enemy. Let us use it against him." /George W Bush on the topic of Human rights (not really, it's from http://www.imdb.com/title/tt0120737/quotes ) -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
John Bokma wrote: > [EMAIL PROTECTED] wrote: > Your first question should be: Is it alright that Xah harasses 5 > newsgroups? Or maybe work on your spelling, harass is with one r, but > maybe you didn't read the subject, which wouldn't amaze me, since you > sound like you should be spending time on MySpace OMG!. I assume that the single l in alright is the courteous misspelling that should allways be in a posting, when correcting other peoples speling? -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science Phone: +45 66 11 84 94 Mobile: +45 29 93 42 96 -- http://mail.python.org/mailman/listinfo/python-list
os.time()
i have a problem with the os.times() command, on different Python versions, i get different printout: Server1# python Python 2.3.4 (#1, Feb 2 2005, 11:44:13) [GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> import os >>> >>> print os.times()[4] 4880406.62 -- Server2% python Python 2.3.2 (#4, Sep 14 2004, 09:41:45) [C] on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> import os >>> >>> print os.times()[4] -21464227.74 --- Server3% python Python 2.4.1 (#1, May 16 2005, 15:19:29) [GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> import os >>> >>> print os.times()[4] 18390711.21 and on the 3 servers, the linux command: $date returns the same value. any suggestions??? what is the command that gives me the actual time? -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
WIdgeteye wrote: > HI, > I am trying to write a little program that will run a program on > scedule. There are usually existing programs to do so on most platforms (cron on *n*x, the Windows scheduler, etc). -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Python OpenGL difficulties
Mike C. Fletcher wrote: > [EMAIL PROTECTED] wrote: > > I'm beginning learning Python and OpenGL in Python. > > [...] > > ImportError: No module named OpenGL.GLUT > > > > [EMAIL PROTECTED]/etc/python>$ echo $PYTHONPATH > > /usr/lib/python2.2/site-packages/OpenGL > > > You should already have site-packages in your PythonPath. You want the > directory *above* OpenGL in the path, not OpenGL itself. Yes, tried that: $ echo $PYTHONPATH /usr/lib/python2.2/site-packages/ and no improvement. Should there be a file or directory named GLUT* in /usr/lib/python2.2/site-packages/OpenGL/ ? All I can see are GL, GLU and GLX directories. I'm unsure why > you're running a Python 2.2 instance on a modern Linux. [EMAIL PROTECTED]/etc/python>$ python2 Python 2.4.2 (#1, Feb 12 2006, 03:59:46) [GCC 4.1.0 20060210 (Red Hat 4.1.0-0.24)] on linux2 The OpenGL stuff was from an RPM that I sound on the web. Many thanks, Jon C. -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Max M wrote: > John Bokma wrote: >> [EMAIL PROTECTED] wrote: > >> Your first question should be: Is it alright that Xah harasses 5 >> newsgroups? Or maybe work on your spelling, harass is with one r, but >> maybe you didn't read the subject, which wouldn't amaze me, since you >> sound like you should be spending time on MySpace OMG!. > > > I assume that the single l in alright is the courteous misspelling that > should allways be in a posting, when correcting other peoples speling? Nope. Oxford English Dictionary has: alright a frequent spelling of all right. And Merriam-Webster has: alright Pronunciation: (")ol-'rIt, 'ol-" Function: adverb or adjective : ALL RIGHT usage The one-word spelling alright appeared some 75 years after all right itself had reappeared from a 400-year-long absence. Since the early 20th century some critics have insisted alright is wrong, but it has its defenders and its users. It is less frequent than all right but remains in common use especially in journalistic and business publications. It is quite common in fictional dialogue, and is used occasionally in other writing . DS -- http://mail.python.org/mailman/listinfo/python-list
Re: Very good Python Book. Free download : Beginning Python: From Novice to Professional
Good :) Can someone provide this ebook? . I'm looking forwards it. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.time()
Anthony wrote: > i have a problem with the os.times() command, on different Python > versions, i get different printout: > and on the 3 servers, the linux command: $date > returns the same value. > > any suggestions??? > what is the command that gives me the actual time? time.time(), not os.times(). The latter is for process-times. No idea why it can become _negative, though. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
>Your first question should be: Is it alright that Xah harasses 5 >newsgroups? Or maybe work on your spelling, harass is with one r, but >maybe you didn't read the subject, which wouldn't amaze me, since you >sound like you should be spending time on MySpace OMG!. Dear John, Should I ask myself the question about Xah first, or work on my spelling? I knew har*ass it had 1 or more r's in it but I couldn't figure out the exact number. That makes me suspect my spelling is good enough and I should dive right into the Xah issue. What do you think John? I don't get the MySpace OMG reference, but rest assured John, you are still my favorite newsnet nazi. I know you have been feeling pretty insecure about this Xah fellow, but you know that is just silly, don't you? Yours truly Immanuel P.S Do not hesitate to comment on form, spelling or style of this message. I am always eager to learn. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is anybody knows about a linkable, quick MD5/SHA1 calculator library ?
DurumDara wrote: > Hi ! > > I need to speedup my MD5/SHA1 calculator app that working on > filesystem's files. You could try using threads. This would allow the CPU and the disk to work in parallel. The sha/md5 modules don't seem to release the global interpreter lock, so you won't be able to use multiple CPUs/cores yet. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: create a text file
Hi, This is what I often do: somekindofoutput = '' somekindofoutput += somefunk(somearg) + '\n' # w is for writing myfile = open('theoutfile',w) myfile.write(somekindofoutput) myfile.close() also see http://www.python.org/doc/2.3.5/tut/node9.html or some other documentation /P9k -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Max M wrote: > John Bokma wrote: >> [EMAIL PROTECTED] wrote: > >> Your first question should be: Is it alright that Xah harasses 5 >> newsgroups? Or maybe work on your spelling, harass is with one r, but >> maybe you didn't read the subject, which wouldn't amaze me, since you >> sound like you should be spending time on MySpace OMG!. > > > I assume that the single l in alright is the courteous misspelling that > should allways be in a posting, when correcting other peoples speling? > > I'm glad you caught the usage error and another fine example of Bokma hypocrisy. People need to point it out because Bokma's hypocrisy is invisible to him. :) Xah's posting on-topic messages to 5 newsgroups about two times per week isn't harassment, but Bokma's attempts to cut off Xah *are*. -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
David Squire wrote: > Max M wrote: >> John Bokma wrote: >>> [EMAIL PROTECTED] wrote: >> >>> Your first question should be: Is it alright that Xah harasses 5 >>> newsgroups? Or maybe work on your spelling, harass is with one r, but >>> maybe you didn't read the subject, which wouldn't amaze me, since you >>> sound like you should be spending time on MySpace OMG!. >> >> >> I assume that the single l in alright is the courteous misspelling >> that should allways be in a posting, when correcting other peoples >> speling? > > Nope. Oxford English Dictionary has: > > alright > > a frequent spelling of all right. > > And Merriam-Webster has: > > alright > Pronunciation: (")ol-'rIt, 'ol-" > Function: adverb or adjective > : ALL RIGHT > usage The one-word spelling alright appeared some 75 years after all > right itself had reappeared from a 400-year-long absence. Since the > early 20th century some critics have insisted alright is wrong, but it > has its defenders and its users. It is less frequent than all right but > remains in common use especially in journalistic and business > publications. It is quite common in fictional dialogue, and is used > occasionally in other writing were alright -- Gertrude Stein>. > > DS American Heritage Dictionary: Usage Note: [...] one who uses alright, especially in formal writing, runs the risk that readers may view it as an error or as the willing breaking of convention. That's sounds kinda like what Xah does, and that's why I flag it as hypocrisy. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.time()
Diez B. Roggisch wrote: > Anthony wrote: > > >>i have a problem with the os.times() command, on different Python >>versions, i get different printout: > > > >>and on the 3 servers, the linux command: $date >>returns the same value. >> >>any suggestions??? >>what is the command that gives me the actual time? > > > time.time(), not os.times(). The latter is for process-times. No idea why it > can become _negative, though. > > Diez WANTED: reliable benchmarks to improve Python speed/performance estimation. REWARD: the thanks of the whole community. I spent some time at the recent Need For Speed sprint addressing benchmarking questions, and discovered that we need more benchmark tests for speed and perfomance. Sean Reifenshneider seems to be on the trail of one addition, but the, more the merrier. It's not easy to write good benchmarks ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Is anybody knows about a linkable, quick MD5/SHA1 calculator library ?
DurumDara wrote: > Hi ! > > I need to speedup my MD5/SHA1 calculator app that working on > filesystem's files. > I use the Python standard modules, but I think that it can be faster if > I use C, or other module for it. > > I use FSUM before, but I got problems, because I "move" into "DOS area", > and the parameterizing of outer process maked me very angry (not working). > You will see this in this place: > http://mail.python.org/pipermail/python-win32/2006-May/004697.html FWIW I looked at what is the problem, apparently fsum converts the name back to unicode, tries to print it and silently corrupts the output. You give it short name XA02BB~1 of the file xAÿ and fsum prints xA Use python module or try another utility. -- http://mail.python.org/mailman/listinfo/python-list
Re: saving settings
Grant Edwards wrote: > Documents and settings aren't quite the same thing, but it's a > valid point. > >> Especially not the ones you wrote on that other machine. >> >> Seriously: Who is going to copy a executable around? > > I do. I copy putty.exe around all of the time. I download it every time, and if I didn't, I'd be pretty annoyed if I'd copy it to a friends machine containing ALL MY KEYS embedded into it. >> Do you know of any other program that behaves like that? > > Back in the day, that used to be fairly common under > DOS/Windows. Not that it's still not a really bad idea. Back in the day self-modifying code was the craze too. And _some_ people even do it in python :) Diez -- http://mail.python.org/mailman/listinfo/python-list
Way to get an array of latitude/longitude points (tuples) from a trip
I am not sure if this is the right place for this, but I thought it was worth a shot. What I want: Enter a From: street address and a To: street address, and then specify an interval (say every half mile). Then, I click a submit button, and it gives me latitude and longitude points (in order) from the beginning of my trip to the end of my trip in 1/2 mile increments. I can't seem to find anything to simulate this, and I am not sure how to go about coding this either. BTW - I have used Yahoo geocoding service (to my delight), and while it is a good service, I don't see a way to do this unless we knew every street address in 1/2 mile increments. Are there any Python modules that would assist with dealing with latitude and longitude? Can anyone out there help? -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginner Python OpenGL difficulties
[EMAIL PROTECTED] wrote: > > Mike C. Fletcher wrote: >> [EMAIL PROTECTED] wrote: >> > I'm beginning learning Python and OpenGL in Python. >> > > [...] >> > ImportError: No module named OpenGL.GLUT >> > >> > [EMAIL PROTECTED]/etc/python>$ echo $PYTHONPATH >> > /usr/lib/python2.2/site-packages/OpenGL >> > >> You should already have site-packages in your PythonPath. You want the >> directory *above* OpenGL in the path, not OpenGL itself. > > Yes, tried that: > > $ echo $PYTHONPATH > /usr/lib/python2.2/site-packages/ > > and no improvement. Should there be a file or directory named GLUT* in > /usr/lib/python2.2/site-packages/OpenGL/ ? All I can see are GL, GLU > and GLX directories. > > I'm unsure why >> you're running a Python 2.2 instance on a modern Linux. > > [EMAIL PROTECTED]/etc/python>$ python2 > Python 2.4.2 (#1, Feb 12 2006, 03:59:46) > [GCC 4.1.0 20060210 (Red Hat 4.1.0-0.24)] on linux2 > > The OpenGL stuff was from an RPM that I sound on the web. Go compile it yourself then - the RPM seems to be for python2.2, but you run 2.4. That means more happened than just changing the PYTHONPATH - so don't expect you come away so cheap :) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use tk.call ?
Eric, Thanks, your tip did the trick... Is there someplace where tk.call is discussed? Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: starting some Python script from C#
> >> "Gerard Flanagan" <[EMAIL PROTECTED]> je napisao u poruci interesnoj > >> grupi:[EMAIL PROTECTED] > >> > tatamata wrote: > >> >> Hello. > >> >> > >> >> How can I run some Python script within C# program? > >> >> > >> > > >> > - > >> >ProcessStartInfo startInfo; > >> >Process process; > >> >string directory; > >> >string pyArgs; > >> >string script; > >> > > >> >startInfo = new ProcessStartInfo("python"); > >> >startInfo.WorkingDirectory = directory; > >> >startInfo.Arguments = script + " " + pyArgs; > >> >startInfo.UseShellExecute = false; > >> >startInfo.CreateNoWindow = true; > >> >startInfo.RedirectStandardOutput = true; > >> >startInfo.RedirectStandardError = true; > >> > > >> >process = new Process(); > >> >process.StartInfo = startInfo; > >> >process.Start(); > >> > > >> >string s; > >> >while ((s = process.StandardOutput.ReadLine()) != null) > >> >{ > >> >//do something with s > >> >} > >> > - > >> > > > > > tatamata wrote: > >> Hello. I tried to implement ypour suggestion, but an error apears: > >> "Exception System.ComponentModel.Win32Exception was thrown in debugee: > >> The specified executable is not a valid Win32 application. > >> > >> namespace CS_script > >> { > >> class MainClass > >> { > >> public static void Main(string[] args) > >> { > >> > >> System.Diagnostics.ProcessStartInfo psi =new > >> System.Diagnostics.ProcessStartInfo(); > >> psi.FileName="my_script.py"; > >> psi.WorkingDirectory=Environment.CurrentDirectory; > >> psi.RedirectStandardOutput = true; > >> psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; > >> psi.UseShellExecute = false; > >> psi.CreateNoWindow = true; > >> > >> System.Diagnostics.Process script; > >> script = System.Diagnostics.Process.Start(psi); > >> > >> System.IO.StreamReader myOutput = script.StandardOutput; > >> script.WaitForExit(2000); > >> if (script.HasExited) > >> { > >> string output = myOutput.ReadToEnd(); > >> //this.processResults.Text = output; > >> } > >> MessageBox.Show("finished!"); > >> } > >> } > >> } > >> > >> When running the program, I have the following error: > >> > >> "Exception System.ComponentModel.Win32Exception was thrown in debugee: > >> The specified executable is not a valid Win32 application. > >> > >> StartWithCreateProcess() > >> Start() > >> Start() > >> Main() - c:\Documents and Settings\Zlatko\My Documents\SharpDevelop > >> Projects\CS_script\CS_script\Main.cs:32,5 " > >> > > > > > > I have no means of running C# programs at present and can't claim much > > expertise in any case. A guess is that a "valid Win32 application" > > means an '.exe' file, not a '.py' file. > > > > You are assuming that a Process object is as smart as the command > > interpreter ('cmd.exe') and will know to use 'python.exe' for a file > > with a 'py' extension? > > > > What happens if you use 'python.exe' (or 'cmd.exe') as your file and > > the script name as argument as in the code I posted? > > > > Gerard > > > > > > (PS. This group prefers that one doesn't top-post) > > tatamata wrote: > Hello. It seems that the following code works. And it seems that Process > object can automatically run script by using python.exe, but only if > standard output is not redirected... > > class MainClass > { > public static void Main(string[] args) > { >MyProcess myProcess = new MyProcess(); > myProcess.ExecuteScript(); > MessageBox.Show("Continue?","Application", > MessageBoxButtons.OKCancel); > } > } > public class MyProcess > { > // These are the Win32 error code for file not found or access > denied. > const int ERROR_FILE_NOT_FOUND =2; > const int ERROR_ACCESS_DENIED = 5; > > /// > /// Executes a python script. > /// > public void ExecuteScript() > { > Process myProcess = new Process(); > > try > { > // Get the path that stores the python script. > //string myDocumentsPath > =Environment.GetFolderPath(Environment.SpecialFolder.Personal); > //If the script is placed in the same folder as C# > executable, set the path to current directory: > string myDocumentsPath=Environment.CurrentDirectory; > > //Set the fully qualified script name > myProcess.StartInfo.FileName = myDocumentsPath + > "\\my_script.py"; > > //Execute the script: > myProcess.Start(); > >// Wait for it to die... >
Re: Watching serial port activity.
On 2006-05-30, xkenneth <[EMAIL PROTECTED]> wrote: > I'm using linux. [It's generally considered good practice to quote enough context so that your post makes sense to people without access to older postings.] Under Linux there isn't really anything. IIRC, many years ago, somebody had written a kernel module that inserted itself between application and serial port and logged operations, but the last time I tried to find it, I was unsuccessful. If you feel like building a kernel, adding a few printk() calls to either the low-level serial driver or the tty line-discipline layer might do what you want. -- Grant Edwards grante Yow! YOW!! Everybody out at of the GENETIC POOL! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: wait() on Popen4 object from thread?
On 2006-05-30, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Tue, 30 May 2006 03:01:54 -, Grant Edwards <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> watching = False > > You do realize that this is a LOCAL definition, and is NOT the same > "watching" your later loop is waiting on... > >> while watching: >> time.sleep(0.1) Oops, forgot the global declaration. However, the presence/absence of the global affect whether the OSError happens or not. -- Grant Edwards grante Yow! Do I hear th' at SPINNING of various visi.comWHIRRING, ROUND, and WARM WHIRLOMATICS?! -- http://mail.python.org/mailman/listinfo/python-list
Re: wait() on Popen4 object from thread?
On 2006-05-30, Grant Edwards <[EMAIL PROTECTED]> wrote: doesn't V > However, the presence/absence of the global affect whether the > OSError happens or not. -- Grant Edwards grante Yow! I'm EMOTIONAL at now because I have visi.comMERCHANDISING CLOUT!! -- http://mail.python.org/mailman/listinfo/python-list
Re: create a text file
"per9000" <[EMAIL PROTECTED]> wrote: > # w is for writing > myfile = open('theoutfile',w) That won't work, the second argument to open needs to be a string: myfile = open('theoutfile', 'w') max -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
Hi, Have you looked into slsnif (http://www.dakotacom.net/~ymg/software.html) Duane -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
Grant Edwards <[EMAIL PROTECTED]> wrote: [...] > Under Linux there isn't really anything. IIRC, many years ago, somebody > had written a kernel module that inserted itself between application and > serial port and logged operations, but the last time I tried to find it, I > was unsuccessful. A dirty hack that might work is to rename /dev/ttyS* off somewhere else and replace them with named pipes. Have a process monitor the named pipes and relay data back and forth to the actual serial ports while logging it. The serial ioctls won't work to the named pipe, but the application might not notice it failed. But this is probably way too advanced for the OP. -- PGP key ID E85DC776 - finger [EMAIL PROTECTED] for full key -- http://mail.python.org/mailman/listinfo/python-list
Re: Linking onClick event to other controls on the Frame
Hi Miki, I appreciate you taking the time to figure out what I was trying to do. This is exactly what I was looking for. I plan on studing this code and looking at the wxpython demo as you mentioned. Thanks again! R.D. Harles -- http://mail.python.org/mailman/listinfo/python-list
webbrowser problems
I’m having trouble trying to pass arguments to a file path url… ie c:/testPython/test.html?testArg=testValue import webbrowser webbrowser.open(“c:/testPython/test.html”) # Works webbrowser.open(“c:/testPython/test.html?testArg=testValue”) # Doesn’t Work webbrowser.get() # Returns a WindowsDefault instance I looked into the webbrowser python command, and see that windows default just does a os.filestart(url) call. If I use the command prompt to try and mimic this it also errors out which is what I would expect. But if I run this from the command line… it seems to work fine: c:\Program Files\Internet Explorer\iexplore.exe c:/testPython/test.html?testArg=testValue I assume this is because the url is being passed as an argument to the iexplore.exe instead of trying to find a file call that url. I guess what I need to do is try and find the file path to the default browser so that I can build my own string to execute via command line. But I have no clue as to how I would go about getting that… and also I want to make sure its still going to be cross platform compatible. Any help? Ideas? Thanks Keith -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
On 2006-05-30, TheSeeker <[EMAIL PROTECTED]> wrote: > Have you looked into slsnif > (http://www.dakotacom.net/~ymg/software.html) FYI, slsnif won't work for any serial program that needs to use parity, 7 data bits, or any of the modem control/status lines. Since all of the serial applications I use need to use actual serial ports, I've never found slsnif to be useful. It's really a shame that pty devices don't support the same set of ioctl calls that tty devices do. -- Grant Edwards grante Yow! World War Three can at be averted by adherence visi.comto a strictly enforced dress code! -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
On 2006-05-30, Peter Corlett <[EMAIL PROTECTED]> wrote: > A dirty hack that might work is to rename /dev/ttyS* off somewhere else and > replace them with named pipes. Have a process monitor the named pipes and > relay data back and forth to the actual serial ports while logging it. The > serial ioctls won't work to the named pipe, but the application might not > notice it failed. If so, then that would be one pretty crappy application. ;) The slsnif program uses a pty so it will support at least some of the ioctl calls that a serial port does. -- Grant Edwards grante Yow! Yow! Is my fallout at shelter termite proof? visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use tk.call ?
On 30 May 2006 05:51:04 -0700, <[EMAIL PROTECTED]> wrote: > Eric, > > Thanks, your tip did the trick... Is there someplace where tk.call is > discussed? I don't think so. I personnally never find any documentation on it. But there is not much to say: you can just pass regular tcl commands through it and that's all. The only thing to remember is to split your command in "words" as tcl expects them. But you seem to have figured out that already... -- python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])" -- http://mail.python.org/mailman/listinfo/python-list
Re: sybase open client 15_0
Eduardo Gonzalez-Solares wrote: > See: > > http://www.object-craft.com.au/pipermail/python-sybase/2006-May/000471.html > > Dan wrote: > > I'm running SLES 9.3 on Tyan with 2 single core 64-bit Opteron & 8 GB of > > memory and SWAP. > > > > OCS-15_0 > > sybperl-2.18 > > python 2.3.5 > > > > > > > > "Dan" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > >> I have compiled and installed sybase-.037 , the module to add sybase to > >> python. However, when I try to use it I get Import error: > >> /usr/local/lib/python2.3/site-packages/sybasect.so > >> > >> undefined symbol: cs_dt_info > >> > >> I've seen some posts on the internet with other people having this issue. > >> But nothing they've suggested has resolved this issue. Maybe python just > >> needs to be installed again or upgraded to support sybase Open Client. > >> > >> Thanks, > >> ~DjK > >> > > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: sybase open client 15_0
Hi, Thanks for the reply. I have tried that solution - adding syb like sybblk to setup.py, but it didn't change my end result, import sybase fails. I wonder if I need to start fresh. How would I be sure sybase-0.37 is gone? Also, I have 64-bit linux. I have libsybblk64.so for example. I don't have libsybcs.a or sybinsck, it didn't come with OCS-15_0. ~DjK -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Version Testing Tool?
Michael Yanowitz wrote: > Hello: > >Is there a version testing tool available for Python > such that I can check to see if my code will still run in > versions 2.2, 2.3, 2.4.3, and 1.1 (for example) (or whatever) > without having to install all these different versions on my > computer? > This is one of the things Movable Python is good at. (For Windows only currently). http://www.voidspace.org.uk/python/movpy/ You can test your code with multiple versions of Python (currently 2.2, 2.3 & 2.4) without having to install them. The next update will allow you to switch which version you run your code with just by selecting hte interpreter from the menu. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Thanks in advance: > Michael Yanowitz -- http://mail.python.org/mailman/listinfo/python-list
Re: logging
Baurzhan Ismagulov wrote: > Hello Vinay, > Ok, here is my hierarchy: > [snip] > [handlers] > keys=console [snip] > [logger_root] > level=CRITICAL > handlers=console > > [logger_l01] > level=DEBUG > qualname=l01 > handlers=console > > [logger_l02] > level=CRITICAL > qualname=l02 > handlers=console [snip] > With the config above, I expect that zzz gets printed, and qqq doesn't. > When I run the script, zzz is printed twice, and qqq isn't. I want that > zzz is printed once. How do I do that? I can add a filter if this can't > be done otherwise, however, I'm at the moment reluctant to do that since > I don't see why CRITICAL for root passes zzz through and drops qqq > correctly for l02. Did you try removing the handler from l01, as I suggested in an earlier reply? The config above still has the console handler attached to root, l01 and l02. The reason that zzz is printed twice is that when a logger decides to process an event, it is passed to handlers attached to ancestor loggers (unless propagate is set to 0 - but this is not the normal situation). So, log1 is deciding to process the event (based on the level), and passing it to its own handlers (l01->console) and then to its ancestor loggers' handlers (root->console). Remove the handlers from l01 and l02 and try again. -- http://mail.python.org/mailman/listinfo/python-list
Multiple Polynomial Quadratic Sieve
Just to announce that I have posted an experimental version of MPQS which I am hoping those of a mathematical turn of mind would care to test, comment on and maybe contribute to. There is work to do but it performs very well. The package is available via FTP at http://www.pythonstuff.pwp.blueyonder.co.uk/ account: python password: guest Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: create a text file
Max Erickson wrote: >> # w is for writing >> myfile = open('theoutfile',w) > > That won't work, the second argument to open needs to be a string: w = 'w' -- http://mail.python.org/mailman/listinfo/python-list
Re: Very good Python Book. Free download : Beginning Python: From Novice to Professional
Moneyhere wrote: > Good :) > Can someone provide this ebook? . > I'm looking forwards it. > http://www.amazon.com/gp/product/0130410659/002-1715230-0496030?v=glance&n=283155 -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
In article <[EMAIL PROTECTED]>, Grant Edwards <[EMAIL PROTECTED]> wrote: >On 2006-05-30, xkenneth <[EMAIL PROTECTED]> wrote: > >> I'm using linux. > >[It's generally considered good practice to quote enough context >so that your post makes sense to people without access to older >postings.] > >Under Linux there isn't really anything. IIRC, many years ago, >somebody had written a kernel module that inserted itself >between application and serial port and logged operations, but >the last time I tried to find it, I was unsuccessful. > >If you feel like building a kernel, adding a few printk() calls >to either the low-level serial driver or the tty >line-discipline layer might do what you want. . . . !? I hadn't realized there's no such monitor ... What do you think of http://wiki.tcl.tk/moni >? -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple Polynomial Quadratic Sieve
Philip Smith wrote: > Just to announce that I have posted an experimental version of MPQS which I > am hoping those of a mathematical turn of mind would care to test, comment > on and maybe contribute to. > > There is work to do but it performs very well. > > The package is available via FTP at > http://www.pythonstuff.pwp.blueyonder.co.uk/ > account: python password: guest > not sure I can help, but clicking on that http link produces a 404 for me. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
Well thanks for the mathematical restatement of my problem. I had forgotten the proper terms. Searching on those terms generates some interesting results. However, none of the algo's I have checked will work with generated sequences, or iterable classes, as posited in my first post. While appropriate to the current domain, ie dice. What if you want combinations of extrememely large lists, say 3 sets of 10 mil items. In such a case, I really do want my sets to be generators rather than lists or set objects. This is what had me stumped before, and still has me stumped. -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
[EMAIL PROTECTED] wrote: > > > Well thanks for the mathematical restatement of my problem. I had > forgotten the proper terms. Searching on those terms generates some > interesting results. > > However, none of the algo's I have checked will work with generated > sequences, or iterable classes, as posited in my first post. > > While appropriate to the current domain, ie dice. What if you want > combinations of extrememely large lists, say 3 sets of 10 mil items. > In such a case, I really do want my sets to be generators rather than > lists or set objects. > > This is what had me stumped before, and still has me stumped. def combinations(l, depth): if depth == 1: for element in l: yield (element,) else: for element in l: for rest in combinations(l, depth -1 ): yield (element,) + rest HTH, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
Max M <[EMAIL PROTECTED]> wrote: > John Bokma wrote: >> [EMAIL PROTECTED] wrote: > >> Your first question should be: Is it alright that Xah harasses 5 >> newsgroups? Or maybe work on your spelling, harass is with one r, but >> maybe you didn't read the subject, which wouldn't amaze me, since you >> sound like you should be spending time on MySpace OMG!. > > I assume that the single l in alright is the courteous misspelling that > should allways be in a posting, when correcting other peoples speling? http://www.answers.com/alright http://www.answers.com/main/ntquery?tname=all-right :-D -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: John Bokma harassment
[EMAIL PROTECTED] wrote: > I don't get the MySpace OMG reference, but rest assured John, you are > still my favorite > newsnet nazi. I know you have been feeling pretty insecure about this > Xah fellow, but Funny that someone diagnosing insecurity needs to refer to Nazi's in an attempt to promote a feeling. -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
In article <[EMAIL PROTECTED]>, I confused matters with: > . > . > . >!? I hadn't realized there's no such monitor ... What do you >think of http://wiki.tcl.tk/moni >? Ugh. Please ignore, all; this was a first draft of what was intended for private e-mail. It escaped the corral through a mistake. I apologize for the distraction. -- http://mail.python.org/mailman/listinfo/python-list
Dr. Dobb's Python-URL! - weekly Python news and links (May 30)
QOTW: "Making a user class work anywhere you can put a mapping in Perl is deep magic, but easy in Python. Creating types that act like files and can be used wherever a file is used is SOP in Python; I'm not even sure it's possible in Perl (probably is, but it's again deep magic)." - Mike Meyer "... I don't bother with classes unless I'm going to end up with multiple instances (or I'm pushed into a corner ..." - Dan Sommers Over TWO DOZEN Python-based projects have been accepted for the 2006 Summer of Code: http://wiki.python.org/moin/SummerOfCode While waiting for more polished summaries from the Iceland Sprint, admire a few of the incidental photographs: http://www.flickr.com/photos/tags/pyneedforspeed/ http://www.flickr.com/photos/[EMAIL PROTECTED]/ John Machin and others stride throught the periods of sequences: http://groups.google.com/group/comp.lang.python/msg/74c81885d7dd4b0e http://groups.google.com/group/comp.lang.python/msg/b9d10df764bdd3df Under-invested desiderata: documentation, regression tests, marketing, serenity, and, as Steve Holden recently discovered, *benchmarks*: http://groups.google.com/group/comp.lang.python/msg/903d5ba9745bad5b Fuzzyman advertises yet another convenience of Movable Python: http://groups.google.com/group/comp.lang.python/msg/35baaa3af891c12f Gonzalo Monzon and others discuss the circumstances of Pyrex applicability: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b051c5ae05517e3e/ Zlatko Matic, Gerard Flanagan, and others work out C# invocations for launching an out-of-process Python application: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b051c5ae05517e3e/ Computing stuff is categorically hard because of the combinatorics and scales which arise naturally. Grant Edwards details a true-life example, which happened to be about numeric interpolation, of how problems ("debugging") are dramatically superlinear: http://groups.google.com/group/comp.lang.python/msg/9a78b5d34db196b4 Everything Python-related you want is probably one or two clicks away in these pages: Python.org's Python Language Website is the traditional center of Pythonia http://www.python.org Notice especially the master FAQ http://www.python.org/doc/FAQ.html PythonWare complements the digest you're reading with the marvelous daily python url http://www.pythonware.com/daily Mygale is a news-gathering webcrawler that specializes in (new) World-Wide Web articles related to Python. http://www.awaretek.com/nowak/mygale.html While cosmetically similar, Mygale and the Daily Python-URL are utterly different in their technologies and generally in their results. For far, FAR more Python reading than any one mind should absorb, much of it quite interesting, several pages index much of the universe of Pybloggers. http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog http://www.planetpython.org/ http://mechanicalcat.net/pyblagg.html comp.lang.python.announce announces new Python software. Be sure to scan this newsgroup weekly. http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce Python411 indexes "podcasts ... to help people learn Python ..." Updates appear more-than-weekly: http://www.awaretek.com/python/index.html Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous tradition early borne by Andrew Kuchling, Michael Hudson and Brett Cannon of intelligently summarizing action on the python-dev mailing list once every other week. http://www.python.org/dev/summary/ The Python Package Index catalogues packages. http://www.python.org/pypi/ The somewhat older Vaults of Parnassus ambitiously collects references to all sorts of Python resources. http://www.vex.net/~x/parnassus/ Much of Python's real work takes place on Special-Interest Group mailing lists http://www.python.org/sigs/ Python Success Stories--from air-traffic control to on-line match-making--can inspire you or decision-makers to whom you're subject with a vision of what the language makes practical. http://www.pythonology.com/success The Python Software Foundation (PSF) has replaced the Python Consortium as an independent nexus of activity. It has official responsibility for Python's development and maintenance. http://www.python.org/psf/ Among the ways you can support PSF is with a donation. http://www.python.org/psf/donate.html Kurt B. Kaiser publishes a weekly report on faults and patches. http://www.google.com/groups?as_usubject=weekly%20python%
Re: Watching serial port activity.
On 2006-05-30, Cameron Laird <[EMAIL PROTECTED]> wrote: >>If you feel like building a kernel, adding a few printk() calls >>to either the low-level serial driver or the tty >>line-discipline layer might do what you want. > . > . > . > !? I hadn't realized there's no such monitor ... What do you > think of http://wiki.tcl.tk/moni >? It's yet another a terminal program (written in TCL). _If_ the pty device didn't force parity=None and bits=8, and _if_ it implemented the modem control/status ioctl() calls, and _if_ it went through the line discipline layer like a real serial port does, then something like slsnif would be workable for "real" serial port applications. In a more general sense, it would mean you could actually simulate a serial port with user-space code. That allows you to do cool stuff like create virtual serial ports in user-space that are connected via Ethernet to physical (or virtual) serial ports on other hosts. [OK, I admit there are only a few of us who think that's a cool thing to do.] Currently, if you want to create a virtual serial port under Linux you have to write a kernel-mode device driver. The only practical way to do that is to write a virtual "low level" serial driver that uses the line-discipline layer in the normal manner. And that's a real bitch to maintain because the API between the line-discipline layer and the driver you've just written is constantly changing (it seems to get major overhauls even between minor versions of a "stable" kernel). Someday I'll write a pty driver that actually allows simulation of a serial port... -- Grant Edwards grante Yow! .. My pants just went at on a wild rampage through a visi.comLong Island Bowling Alley!! -- http://mail.python.org/mailman/listinfo/python-list
Re: saving settings
Diez B. Roggisch wrote: > Grant Edwards wrote: > > >> Documents and settings aren't quite the same thing, but it's a >> valid point. >> >>> Especially not the ones you wrote on that other machine. >>> >>> Seriously: Who is going to copy a executable around? >> I do. I copy putty.exe around all of the time. > > I download it every time, and if I didn't, I'd be pretty annoyed if I'd copy > it to a friends machine containing ALL MY KEYS embedded into it. > >>> Do you know of any other program that behaves like that? >> Back in the day, that used to be fairly common under >> DOS/Windows. Not that it's still not a really bad idea. > > Back in the day self-modifying code was the craze too. And _some_ people > even do it in python :) those crazy bastards! ;) > > Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
[EMAIL PROTECTED] wrote: > However, none of the algo's I have checked will work with generated > sequences, or iterable classes, as posited in my first post. > > While appropriate to the current domain, ie dice. What if you want > combinations of extrememely large lists, say 3 sets of 10 mil items. > In such a case, I really do want my sets to be generators rather than > lists or set objects. > > This is what had me stumped before, and still has me stumped. class Counter(object): def __init__(self, digits, iterable=None): self.digits = digits self.iterable = iterable def __iter__(self): for digit in self.digits: single = digit, if self.iterable is None: yield single else: for rest in self.iterable: yield single + rest for v in Counter('ab', Counter('cd', Counter('ef', Counter('gh': print v This works with "iterables" (and produces), rather than "iterators", which is vital to the operation. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
This would only work for combinations of identical sets, and also does not seem to work with generated sets, or iterators. Forgetting dice for a moment. Say I have 3 very long files, and i want to generate the combinations of lines in the files. This provides a well known iterator for the example. file1 = open('foo.txt') file2 = open('bar.txt') file3 = open('baz'.xt') All examples I have seen and all attempts I have written generally do something similar - which is they only iterates through the possible combinations for the last element and do nothing for all other elements. I saw an interesting example that generates a nested function for the given number of sets. While the example still didn't work with generators as input, I think a little tweaking would make it work. This should fulfill my requirements with a rather harsh limit of python's max nesting depth (20?) -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
Scott David Daniels wrote: > This works with "iterables" (and produces), rather than "iterators", > which is vital to the operation. > > --Scott David Daniels > [EMAIL PROTECTED] Sorry, it doesn't. It works with strings. It doesn't work with file, it doesn't work with iterators I have created. I have been using file objects as my test iterables for now - forgoing any complications in my own iterables. such that my test bed has been: f = open('word.txt') f2 = open('word2.txt') f3 = open('word3.txt') for combo in [testable function here] print combo Each file contains the letter a through g on, with each letter on a line. At least I don't feel as bad anymore. My first attempts generate the same output, and a couple of my earlier attempts work quite nicely with lists, and similar things. But I can't find anthing that works generically with any iterable, nor anything that works with generators. -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
On Tue, 30 May 2006 16:15:44 +1000, John McMonagle wrote: > Tue, 2006-05-30 at 00:23 -0500, WIdgeteye wrote: >> On Tue, 30 May 2006 04:34:03 +, Tim Roberts wrote: >> >> > WIdgeteye <[EMAIL PROTECTED]> wrote: >> >>HI, >> >>I am trying to write a little program that will run a program on >> >>scedule. I am having trouble understanding the datetime, time, sched >> >>modules. What I would like is something like this: >> >> >> >>If date&time = 06-13-2006:18:00:00 >> >>Then run this program >> >> >> >>I am not sure how to enter a future date in this equation using any of >> >>the modules mentioned above. I have figured out how to get the date >> >>and time from the modules above but not the future and then compare >> >>the two. >> > >> > What operating system are you using? Both Linux and Windows have >> > commands that can do this for you. It's more efficient to use >> > existing operating system services than to invent your own. >> > >> > Also, remember to take into account the possibility that your program >> > might not check the time at the exact second. In your example, you >> > need to be prepared to start your app if the time is just PAST 6 PM on >> > June 13. >> >> I am using Linux and could use cron. But I want to be able to schedule >> and record television shows on her. And yeah I know about freevo but >> it's way to complicated than it needs to be. >> >> So back to the question: How can I get a 9 position tuple from the time >> functions in Python based on a future date. > > Tim Roberts is right. As you are on linux, I suggest you investigate the > at command - very user friendly and not at all complicated. I have been using Slackware for over 10 years I know all about the commands on the OS. If you guys don't have an answer to the question just say so. But don't give me suggestions on how to use an OS I have been using most likely longer than 90% of the people using linux today. This is the comp.lang.python news group not the linux news group. If I didn't want to write the Python code and I wanted to use the OS commands instead I would. Python is cross platform. Linux is not. I intend to release the software to the general public someday when it is done. I want it cross platform. BTW in the time it took me NOT to get an answer for my question in this so called Python NG, I figured it out for myself. This PYTHON NG blows to high heaven. Whats worse, the answers I got were most likely from people who know SQUAT about Python scripting. That's why they gave me such lame fucking answers. Idiots. -- http://mail.python.org/mailman/listinfo/python-list
Re: stupid perl question
On Sat, 27 May 2006 11:11:40 +1000, John Machin <[EMAIL PROTECTED]> wrote: ... > Yes, you could write out the whitespace characters for the 8-bit > encoding of your choice, or you could find them using Python (and get > some possibly surprising answers): > > >>> mkws = lambda enc, sz=256: "".join([chr(i) for i in range(sz) if > chr(i).decode(enc, 'ignore').isspace()]) ... > >>> mkws('latin1') > '\t\n\x0b\x0c\r\x1c\x1d\x1e\x1f \x85\xa0' That surprised me, at least. Should NO-BREAK SPACE really count as whitespace? I thought that the whole purpose with it was to have a blank character which programs automatically treated as non-whitespace, for line-breaking, word-counting and similar purposes. /Jorgen -- // Jorgen Grahn R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
On Tue, 30 May 2006 14:50:38 -0500, WIdgeteye <[EMAIL PROTECTED]> wrote: > > [snip] > >This PYTHON NG blows to high heaven. Whats worse, the answers I got were >most likely from people who know SQUAT about Python scripting. That's why >they gave me such lame fucking answers. > >Idiots. While that may all be true, there's no call for this kind of post. You came here looking for help, and help was offered. If it is not to your liking, you can move on and look for help elsewhere. The people who answer questions here are doing so for no compensation and don't deserve outbursts like this one, regardless of what you think of their responses. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: hyperthreading locks up sleeping threads
Update The problem turned out to be the BIOS of the PC we were using. The Python test program has been running fine for 5 days now (after we upgraded the system BIOS) and is still running fine. Sorry, I do not have any information as to what was fixed in the BIOS. Also, I do not know exactly who made the motherboard or the BIOS. I will post another update if this information becomes available. This was sure a strange bug! Olaf -- http://mail.python.org/mailman/listinfo/python-list
Strange behavior with iterables - is this a bug?
Ok, I am confused about this one. I'm not sure if it's a bug or a feature.. but >>> RESTART >>> f1 = open('word1.txt') >>> f2 = open('word2.txt') >>> f3 = open('word3.txt') >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in f1 for i2 in f2 for i3 >>> in f3] [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c')] >>> l1 = ['a\n','b\n','c\n'] >>> l2 = ['a\n','b\n','c\n'] >>> >>> l3 = ['a\n','b\n','c\n'] >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in l1 for i2 in l2 for i3 >>> in l3] [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c'), ('a', 'b', 'a'), ('a', 'b', 'b'), ('a', 'b', 'c'), ('a', 'c', 'a'), ('a', 'c', 'b'), ('a', 'c', 'c'), ('b', 'a', 'a'), ('b', 'a', 'b'), ('b', 'a', 'c'), ('b', 'b', 'a'), ('b', 'b', 'b'), ('b', 'b', 'c'), ('b', 'c', 'a'), ('b', 'c', 'b'), ('b', 'c', 'c'), ('c', 'a', 'a'), ('c', 'a', 'b'), ('c', 'a', 'c'), ('c', 'b', 'a'), ('c', 'b', 'b'), ('c', 'b', 'c'), ('c', 'c', 'a'), ('c', 'c', 'b'), ('c', 'c', 'c')] explanation of code: the files word1.txt, word2.txt and word3.txt are all identical conataining the letters a,b and c one letter per line. The lists I've added the "\n" so that the lists are identical to what is returned by the file objects. Just eliminating any possible differences. If you notice, when using the file objects I don't get the proper set of permutations. I was playing around with doing this via recursion, etc. But nothing was working so I made a simplest case nesting. Still no go. Why does this not work with the file objects? Or any other class I''ve made which implements __iter__ and next? Seems like a bug to me, but maybe I am missing something. Seems to happen in 2.3 and 2.4. -- http://mail.python.org/mailman/listinfo/python-list
interactive programme (voice)
hi i have wrote an interactive programme,this is a small section of it. #This is my first programme writing in python s = raw_input ("hello what's your name? ") if s=='carmel': print "Ahh the boss's wife" if s=='melvyn': print "your the boss's dad" if s=='rebecca': print "you must be the wreath woman" if s=='gareth ': print "You must be the trucker" if s=='carol': print "you must be my boss's mom" What i was wandering is there a way i can get sound,i mean instead of getting it to just print text on my screen i would like my computer to say it. Thanks nige -- http://mail.python.org/mailman/listinfo/python-list
"initializer element is not constant"
When trying to compile python extensions written in C using "python setup.py build" on cygwin I get the following error: foo.c: initializer element is not constant foo.c: error: (near initialization for `FooType.ob_type') I remember someone telling me a long time ago that this had something to do with declspec and how dlls are imported on cygwin/python. Can someone give me a pointer to how to build python extensions on cygwin? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
[EMAIL PROTECTED] wrote: > Scott David Daniels wrote: > >> This works with "iterables" (and produces), rather than "iterators", >> which is vital to the operation. >> >> --Scott David Daniels >> [EMAIL PROTECTED] > > Sorry, it doesn't. It works with strings. It doesn't work with file, > it doesn't work with iterators I have created. Sorry, "re-iterables". A file re-iterable is: class FileReIterable(object): def __init__(self, file): if isinstance(file, basestring): self.file = open(file, 'rU') else: self.file = file def __iter__(self): self.file.seek(0) return iter(self.file) This works if-and-only-if it is only in use once at a time. If you have multiple simultaneous accesses, you need to do something like: class FileReIterable2(object): def __init__(self, file): if isinstance(file, basestring): self.file = open(file, 'rU') else: self.file = file def __iter__(self): self.file.seek(0) for line in self.file: nextpos = self.file.tell() yield line self.file.seek(nextpos) --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
WIdgeteye wrote: > Thank you very much for your participation. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: os.time()
Diez B. Roggisch wrote: > Anthony wrote: > > >>i have a problem with the os.times() command, on different Python >>versions, i get different printout: > > > >>and on the 3 servers, the linux command: $date >>returns the same value. >> >>any suggestions??? >>what is the command that gives me the actual time? > > > time.time(), not os.times(). The latter is for process-times. No idea why it > can become _negative, though. > > Diez WANTED: reliable benchmarks to improve Python speed/performance estimation. REWARD: the thanks of the whole community. I spent some time at the recent Need For Speed sprint addressing benchmarking questions, and discovered that we need more benchmark tests for speed and perfomance. Sean Reifenshneider seems to be on the trail of one addition, but the, more the merrier. It's not easy to write good benchmarks ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: create a text file
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Max Erickson wrote: > >>> # w is for writing >>> myfile = open('theoutfile',w) >> >> That won't work, the second argument to open needs to be a string: > > w = 'w' > > > Is it inappropriate to call the w on the left side of the equal's sign a string? I.e., w refers to a string(object) that contains 'w'? My goal was to point out that the code would not work as posted. max -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior with iterables - is this a bug?
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ok, I am confused about this one. I'm not sure if it's a bug or a > feature.. but > RESTART f1 = open('word1.txt') f2 = open('word2.txt') f3 = open('word3.txt') print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in f1 for i2 in f2 for i3 in f3] > [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c')] A file is something like an iterator and something like an iterable. At this point, the internal cursur for f3 points at EOF. To reiterate thru the file, you must rewind in the inner loops. So try (untest by me) def initf(fil): f.seek(0) return f and ...for i2 in initf(f2) for i3 in initf(f3) l1 = ['a\n','b\n','c\n'] l2 = ['a\n','b\n','c\n'] l3 = ['a\n','b\n','c\n'] print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in l1 for i2 in l2 for i3 in l3] > [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c'), ('a', 'b', 'a'), > ('a', 'b', 'b'), ('a', 'b', 'c'), ('a', 'c', 'a'), ('a', 'c', 'b'), > ('a', 'c', 'c'), ('b', 'a', 'a'), ('b', 'a', 'b'), ('b', 'a', 'c'), > ('b', 'b', 'a'), ('b', 'b', 'b'), ('b', 'b', 'c'), ('b', 'c', 'a'), > ('b', 'c', 'b'), ('b', 'c', 'c'), ('c', 'a', 'a'), ('c', 'a', 'b'), > ('c', 'a', 'c'), ('c', 'b', 'a'), ('c', 'b', 'b'), ('c', 'b', 'c'), > ('c', 'c', 'a'), ('c', 'c', 'b'), ('c', 'c', 'c')] > > explanation of code: the files word1.txt, word2.txt and word3.txt are > all identical conataining the letters a,b and c one letter per line. > The lists I've added the "\n" so that the lists are identical to what > is returned by the file objects. Just eliminating any possible > differences. But lists are not file objects and you did not eliminate the crucial difference in reiterability. Try your experiment with StringIO objects, which are more nearly identical to file objects. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: interactive programme (voice)
nigel a écrit : > hi i have wrote an interactive programme,this is a small section of it. > #This is my first programme writing in python > s = raw_input ("hello what's your name? ") > if s=='carmel': >print "Ahh the boss's wife" > if s=='melvyn': > print "your the boss's dad" > if s=='rebecca': > print "you must be the wreath woman" > if s=='gareth ': > print "You must be the trucker" > if s=='carol': > print "you must be my boss's mom" The problem with this code is that: - it does a lots of useless tests (ie : even if the user enters 'carmel', all other names will be tested too). - it doesn't handle the default case (any other name than the one you test for) A minimal amelioration would be to use if/elif/else: s = raw_input ("hello what's your name? ") if s == 'carmel': print "Ahh the boss's wife" elif s == 'melvyn': print "your the boss's dad" elif s == 'rebecca': print "you must be the wreath woman" elif s == 'gareth ': print "You must be the trucker" elif s=='carol': print "you must be my boss's mom" else: # default print "I'm afraid I don't know you..." Now this is a little better, but still not very pythonic. We have a nice thing in Python named a dict (for 'dictionnary'). It stores pairs of key:value - and FWIW, it's the central data structure in Python, so you'll see them quite a lot. There very handy for this kind of use case: greetings = { 'carmel' : "Ahh the boss's wife", 'melvyn' : "your the boss's dad", 'rebecca': "you must be the wreath woman", 'gareth ': "You must be the trucker", 'carol' : "you must be my boss's mom", } name = raw_input ("hello what's your name? ") print greetings.get(name, "I'm afraid I don't know you...") > What i was wandering is there a way i can get sound, Now this is a sound question !-) >i mean instead of getting > it to just print text on my screen i would like my computer to say it. This depends mostly on your computer and what's installed on it. And this is not part of the standard lib AFAIK. -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
Scott David Daniels wrote: > Sorry, "re-iterables". A file re-iterable is: > > class FileReIterable(object): > def __init__(self, file): > if isinstance(file, basestring): > self.file = open(file, 'rU') > else: > self.file = file > def __iter__(self): > self.file.seek(0) > return iter(self.file) > > This works if-and-only-if it is only in use once at a time. > If you have multiple simultaneous accesses, you need to do > something like: > > class FileReIterable2(object): > def __init__(self, file): > if isinstance(file, basestring): > self.file = open(file, 'rU') > else: > self.file = file > def __iter__(self): > self.file.seek(0) > for line in self.file: > nextpos = self.file.tell() > yield line > self.file.seek(nextpos) > > --Scott David Daniels > [EMAIL PROTECTED] Since I was doing this as a self education excercise. When you say is in use once and only once, you mean I can only use a single instance of the class? I haven't even tested these yet, but I am very curious about that statement. Why is it necessary to return a generator object in the second example? If it's a real long explanation, feel free to point me to some relvant texts. My practical problem was solved about 10 posts ago... but I am still trying to understand the behavior. Thank you for you time. AK -- http://mail.python.org/mailman/listinfo/python-list
Re: logging
Hello Vinay, On Tue, May 30, 2006 at 09:13:25AM -0700, Vinay Sajip wrote: > [snip] > > [handlers] > > keys=console > [snip] > > [logger_root] > > level=CRITICAL > > handlers=console > > > > [logger_l01] > > level=DEBUG > > qualname=l01 > > handlers=console > > > > [logger_l02] > > level=CRITICAL > > qualname=l02 > > handlers=console > [snip] ... > > When I run the script, zzz is printed twice, and qqq isn't. I want that > > zzz is printed once. ... > Did you try removing the handler from l01, as I suggested in an earlier > reply? I had removed the whole line, and it complained about the missing handlers line. Now I've tried with 'handlers=', this seems to work. Thanks much! > The reason that zzz is printed twice is that when a logger decides to > process an event, it is passed to handlers attached to ancestor > loggers (unless propagate is set to 0 - but this is not the normal > situation). So, log1 is deciding to process the event (based on the > level), and passing it to its own handlers (l01->console) and then to > its ancestor loggers' handlers (root->console). Hmm, log1 decides once whether to print an event, and after that it gets printed in log1 and all its ancestors, regardless of their level? I find this quite counter-intuitive. I'd instead expect that each logger decides whether to print an event according to its own level. Could you give an example why one would want the python behavior? With kind regards, Baurzhan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior with iterables - is this a bug?
On Tue, May 30, 2006 at 01:11:26PM -0700, [EMAIL PROTECTED] wrote: [...] > >>> RESTART > >>> f1 = open('word1.txt') > >>> f2 = open('word2.txt') > >>> f3 = open('word3.txt') > >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in f1 for i2 in f2 for > >>> i3 in f3] > [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c')] > >>> l1 = ['a\n','b\n','c\n'] > >>> l2 = ['a\n','b\n','c\n'] > >>> > >>> l3 = ['a\n','b\n','c\n'] > >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in l1 for i2 in l2 for > >>> i3 in l3] > [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c'), ('a', 'b', 'a'), > ('a', 'b', 'b'), ('a', 'b', 'c'), ('a', 'c', 'a'), ('a', 'c', 'b'), > ('a', 'c', 'c'), ('b', 'a', 'a'), ('b', 'a', 'b'), ('b', 'a', 'c'), > ('b', 'b', 'a'), ('b', 'b', 'b'), ('b', 'b', 'c'), ('b', 'c', 'a'), > ('b', 'c', 'b'), ('b', 'c', 'c'), ('c', 'a', 'a'), ('c', 'a', 'b'), > ('c', 'a', 'c'), ('c', 'b', 'a'), ('c', 'b', 'b'), ('c', 'b', 'c'), > ('c', 'c', 'a'), ('c', 'c', 'b'), ('c', 'c', 'c')] > > explanation of code: the files word1.txt, word2.txt and word3.txt are > all identical conataining the letters a,b and c one letter per line. > The lists I've added the "\n" so that the lists are identical to what > is returned by the file objects. Just eliminating any possible > differences. You're comparing file, which is ITERATOR, and list, which is ITERABLE, not ITERATOR. To get the result you want, use this instead; >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in open('word1.txt') for i2 in open('word2.txt') for i3 in open('word3.txt')] FIY, to get the same buggy(?) result using list, try this instead; >>> l1 = iter(['a\n','b\n','c\n']) >>> l2 = iter(['a\n','b\n','c\n']) >>> l3 = iter(['a\n','b\n','c\n']) >>> print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in l1 for i2 in l2 for i3 >>> in l3] [('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c')] >>> -Inyeol Lee -- http://mail.python.org/mailman/listinfo/python-list
Re: Way to get an array of latitude/longitude points (tuples) from a trip
kbperry schrieb: > I am not sure if this is the right place for this, but I thought it was > worth a shot. > > What I want: > Enter a From: street address and a To: street address, and then specify > > an interval (say every half mile). Then, I click a submit button, and > it gives me latitude and longitude points (in order) from the beginning > > of my trip to the end of my trip in 1/2 mile increments. > > > I can't seem to find anything to simulate this, and I am not sure how > to go about coding this either. > > > BTW - I have used Yahoo geocoding service (to my delight), and while it > > is a good service, I don't see a way to do this unless we knew every > street address in 1/2 mile increments. > > Are there any Python modules that would assist with dealing with > latitude and longitude? > Can anyone out there help? The problem is not the latitude/longitude. It would be trivial to compute the great circle, thus the length of the trip between A and B and divide it in smaller pieces to get 1-mile-distances. But unless you own an Aircraft & are important enough to take flights the direct route without air traffic control getting mad at you (aka: you are George W. Bush or some other bigwig goverment guy), this won't do you much good. What you needed would be a vectormap of the streets so that you could do route planning. Which is expensive to get. So I guess you are better off trying to find someone who offers that as part of the service. Diez Diez -- http://mail.python.org/mailman/listinfo/python-list
RE: interactive programme (voice)
http://www.cs.unc.edu/~parente/tech/tr02.shtml loads of fun. -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
xkenneth wrote: > Hi, > >I'm writing a couple python applications that use the serial port > (RS-232) quite extensively. Is there any way I can monitor all activity > on the serial port and have it printed as the transactions occur? I'm > trying to reverse engineer a microcontroller serial routine and I'd > like to see any response the chip sends back. I've done similar things in the past, and the best tools I found at that time were: - Serial Port sniffer from www.hhdsoftware.com Similar to portmon, but (in my experience) more stable. Windows only, though. - VMWare You can run your serial port app in a VMWare and connect the virtual serial port to a file or named pipe on the host system. But this won't help you if the app uses serial commands not available for files/pipes. - Hardware cable If you know how to use a soldering iron, this might be the best way: a serial cable has an RX and a TX wire, connect each of them to the RX wires of two separate serial cables, that way you can "wiretap" the whole communication to two different serial ports (e.g. on your laptop) in a running system. Dead useful for debugging! -- http://mail.python.org/mailman/listinfo/python-list
how to print newline in xml?
I currently use xml.dom.minidom and ext to create a dom-tree which I would write to an xml-file. My intention is to create something like this: but I didn't find any possibility either to put comment directly behind a tag nor did I found how to put a new line like in example between the two joints. The reason why I'm trying to achieve this: the file should be easy to read for a human... now I can just print the upper document like this: which is already not very readable - but it becomes even worse along with increasing number of comments -- http://mail.python.org/mailman/listinfo/python-list
Re: "initializer element is not constant"
[EMAIL PROTECTED] wrote: > When trying to compile python extensions written in C using "python > setup.py build" on cygwin I get the following error: > > foo.c: initializer element is not constant > foo.c: error: (near initialization for `FooType.ob_type') > > I remember someone telling me a long time ago that this had something > to do with declspec and how dlls are imported on cygwin/python. Can > someone give me a pointer to how to build python extensions on cygwin? Essentially, Python and its extensions must be compatibly compiled. The distributed Windows python is compatible with MS C/C++ and (as a result) also compatible with the Intel C/C++ compilers. In addition, "MinGW" (Minimal GNU for Windows) can compile C source to be compatible with and use the MS C runtimes. If you really want cygwin, you need to compile the whole of Python with cygmin (I've no idea if that compile cleanly). If you want to use the MinGW approach, your call to setup is something like "python setup.py -compiler=mingw32 -build " (look it up, there are more details to know about. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: iterator? way of generating all possible combinations?
[EMAIL PROTECTED] wrote: > Scott David Daniels wrote: >> Sorry, "re-iterables". A file re-iterable is: >> >> class FileReIterable(object): ... >> def __iter__(self): >> self.file.seek(0) >> return iter(self.file) >> >> This works if-and-only-if it is only in use once at a time. >> If you have multiple simultaneous accesses, you need to do >> something like: >> >> class FileReIterable2(object): ... >> def __iter__(self): >> self.file.seek(0) >> for line in self.file: >> nextpos = self.file.tell() >> yield line >> self.file.seek(nextpos) > > Since I was doing this as a self education excercise. When you say is > in use once and only once, you mean I can only use a single instance of > the class? No. This works: f1 = FileReIterable("one.file") f2 = FileReIterable("another.file") ... free uses of ... This does not "work": gen = FileReIterable("one.file") for a in gen: for b in gen: print a, b This does "work": gen = FileReIterable2("one.file") for a in gen: for b in gen: print a, b That is, any instance of FileReIterable must not be used in a context where it may be in the midst of iterating a file, gets used to produce a result, and then must produce a result from the original iteration. If you think about what must happen to the file read pointer, the reason for all of this should become clear. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Watching serial port activity.
xkenneth wrote: > Hi, > >I'm writing a couple python applications that use the serial port > (RS-232) quite extensively. Is there any way I can monitor all activity > on the serial port and have it printed as the transactions occur? I'm > trying to reverse engineer a microcontroller serial routine and I'd > like to see any response the chip sends back. I've done similar things in the past, and the best tools I found at that time were: - Serial Port sniffer from www.hhdsoftware.com Similar to portmon, but (in my experience) more stable. Windows only, though. - VMWare You can run your serial port app in a VMWare and connect the virtual serial port to a file or named pipe on the host system. But this won't help you if the app uses serial commands not available for files/pipes. - Hardware cable If you know how to use a soldering iron, this might be the best way: a serial cable has an RX and a TX wire, connect each of them to the RX wires of two separate serial cables, that way you can "wiretap" the whole communication to two different serial ports (e.g. on your laptop) in a running system. Dead useful for debugging! -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple Polynomial Quadratic Sieve
Whoops Should have been http://www.python.pwp.blueyonder.co.uk/ Thanks Phil "Philip Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Just to announce that I have posted an experimental version of MPQS which > I am hoping those of a mathematical turn of mind would care to test, > comment on and maybe contribute to. > > There is work to do but it performs very well. > > The package is available via FTP at > http://www.pythonstuff.pwp.blueyonder.co.uk/ > account: python password: guest > > Thanks > -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
You can try this EnergyKey http://www30.webSamba.com/SmartStudio This may be help you. Now I always use EnergyKey, it helps me so much in my work. -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior with iterables - is this a bug?
[EMAIL PROTECTED] wrote: >Ok, I am confused about this one. I'm not sure if it's a bug or a >feature.. but > > List comprehension is a great shortcut, but when the shortcut starts causing trouble, better to go with the old ways. You need to reopen each file each time you want to iterate through it. You should be able to understand the difference between these two bits of code. The first bit opens each file but uses (two of them) multiple times. Reading from a file at EOF returns an empty sequence. The second bit opened the file each time you want to reuse it. That works correctly. And that suggest the third bit of correctly working code which uses list comprehension. # Fails because files are opened once but reused f1 = open('word1.txt') f2 = open('word2.txt') f3 = open('word3.txt') for i1 in f1: for i2 in f2: for i3 in f3: print (i1.strip(),i2.strip(),i3.strip()) and # Works because files are reopened for each reuse: f1 = open('word1.txt') for i1 in f1: f2 = open('word2.txt') for i2 in f2: f3 = open('word3.txt') for i3 in f3: print (i1.strip(),i2.strip(),i3.strip()) and # Also works because files are reopened for each use: print [(i1.strip(),i2.strip(),i3.strip()) for i1 in open('word1.txt') for i2 in open('word2.txt') for i3 in open('word3.txt')] Hope that's clear! Gary Herron > > RESTART f1 = open('word1.txt') f2 = open('word2.txt') f3 = open('word3.txt') print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in f1 for i2 in f2 for i3 in f3] >[('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c')] > > l1 = ['a\n','b\n','c\n'] l2 = ['a\n','b\n','c\n'] l3 = ['a\n','b\n','c\n'] print [(i1.strip(),i2.strip(),i3.strip(),) for i1 in l1 for i2 in l2 for i3 in l3] >[('a', 'a', 'a'), ('a', 'a', 'b'), ('a', 'a', 'c'), ('a', 'b', 'a'), >('a', 'b', 'b'), ('a', 'b', 'c'), ('a', 'c', 'a'), ('a', 'c', 'b'), >('a', 'c', 'c'), ('b', 'a', 'a'), ('b', 'a', 'b'), ('b', 'a', 'c'), >('b', 'b', 'a'), ('b', 'b', 'b'), ('b', 'b', 'c'), ('b', 'c', 'a'), >('b', 'c', 'b'), ('b', 'c', 'c'), ('c', 'a', 'a'), ('c', 'a', 'b'), >('c', 'a', 'c'), ('c', 'b', 'a'), ('c', 'b', 'b'), ('c', 'b', 'c'), >('c', 'c', 'a'), ('c', 'c', 'b'), ('c', 'c', 'c')] > >explanation of code: the files word1.txt, word2.txt and word3.txt are >all identical conataining the letters a,b and c one letter per line. >The lists I've added the "\n" so that the lists are identical to what >is returned by the file objects. Just eliminating any possible >differences. > > >If you notice, when using the file objects I don't get the proper set >of permutations. I was playing around with doing this via recursion, >etc. But nothing was working so I made a simplest case nesting. Still >no go. >Why does this not work with the file objects? Or any other class I''ve >made which implements __iter__ and next? > >Seems like a bug to me, but maybe I am missing something. Seems to >happen in 2.3 and 2.4. > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange behavior with iterables - is this a bug?
DOH!! thanks a lot. had to be something stupid on my part. Now I get it :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Dr. Dobb's Python-URL! - weekly Python news and links (May 30)
Cameron Laird wrote: > QOTW: "Making a user class work anywhere you can put a mapping in Perl is > deep magic, but easy in Python. Creating types that act like files and can be > used wherever a file is used is SOP in Python; I'm not even sure it's > possible in Perl (probably is, but it's again deep magic)." - Mike Meyer > > "... I don't bother with classes unless I'm going to end up with multiple > instances (or I'm pushed into a corner ..." - Dan Sommers > > > Over TWO DOZEN Python-based projects have been accepted for > the 2006 Summer of Code: > http://wiki.python.org/moin/SummerOfCode > > While waiting for more polished summaries from the Iceland Sprint, > admire a few of the incidental photographs: > http://www.flickr.com/photos/tags/pyneedforspeed/ > http://www.flickr.com/photos/[EMAIL PROTECTED]/ > > John Machin and others stride throught the periods of sequences: > http://groups.google.com/group/comp.lang.python/msg/74c81885d7dd4b0e > http://groups.google.com/group/comp.lang.python/msg/b9d10df764bdd3df > > Under-invested desiderata: documentation, regression tests, > marketing, serenity, and, as Steve Holden recently discovered, > *benchmarks*: > http://groups.google.com/group/comp.lang.python/msg/903d5ba9745bad5b > > Fuzzyman advertises yet another convenience of Movable Python: > http://groups.google.com/group/comp.lang.python/msg/35baaa3af891c12f > That's a very surprising mention, thanks. :-) A *better* URL for the thread is : http://groups.google.com/group/comp.lang.python/browse_frm/thread/28edb6b248dbae85/6a64800985655dce#6a64800985655dce All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
F2G bug (was Re: How to calc easier the "long" filesize from nFileSizeLow and nFileSizeHigh)
On 30/05/2006 1:55 PM, Roger Upole *top-posted*: > Shift nFileSizeHigh by 32 and add FileSizeLow. Uh-ohh. Here we have yet another manifestation of the Y2K bug's little sibling, the F2G bug. The above doesn't work for 2GB <= filesize < 4GB, 6GB <= filesize < 8GB, etc. See below. > > Roger > > "DurumDara" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> Hi ! >> >> I get the file datas with FindFilesW. >> I want to calc the filesize from nFileSizeLow and nFileSizeHigh with easiest >> as possible, without again calling os.getsize(). >> How to I do it ? I need good result ! >> >> Thanx for help: >> dd > Those two items are defined as int (that's *signed* int) -- so if the punter has a 3 GB file, nFileSizeHigh will be zero and nFileSizeLow will be -1073741824. *Minus* 1 GB? Hey, d00d, who stole my file-system? Try this: fsz = (hi << 32) + lo if lo < 0: fsz += 0x1 This problem is described in the first article found by googling for "nFileSizeHigh", as I suggested to the OP. Here is some evidence: C:\junk>dir gb3.txt [snip] 31/05/2006 07:59 AM 3,221,225,472 gb3.txt [snip] C:\junk>python Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. |>>> import win32file |>>> d = win32file.FindFilesW(u'gb3.txt') |>>> d [(32, , , , 0, -1073741824, 0, 0, u'gb3.txt', u'')] |>>> hi, lo = d[0][4:6] |>>> hi, lo (0, -1073741824) |>>> fsz = (hi << 32) + lo |>>> fsz -1073741824 |>>> # if lo < 0: |... fsz += (1 << 32) |>>> |>>> fsz 3221225472L |>>> Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: stupid perl question
On 31/05/2006 5:55 AM, Jorgen Grahn wrote: > On Sat, 27 May 2006 11:11:40 +1000, John Machin <[EMAIL PROTECTED]> wrote: > ... >> Yes, you could write out the whitespace characters for the 8-bit >> encoding of your choice, or you could find them using Python (and get >> some possibly surprising answers): >> > mkws = lambda enc, sz=256: "".join([chr(i) for i in range(sz) if >> chr(i).decode(enc, 'ignore').isspace()]) > ... > mkws('latin1') >> '\t\n\x0b\x0c\r\x1c\x1d\x1e\x1f \x85\xa0' > > That surprised me, at least. Should NO-BREAK SPACE really count as > whitespace? NO-BREAK SPACE is a space. Of course it should return True when fed to isspace(). Whitespace is a silly term, anyway (IMHO); is there such a thing as a space that is not white? > I thought that the whole purpose with it was to have a blank > character which programs automatically treated as non-whitespace, for > line-breaking, word-counting and similar purposes. Yes, but the concept of things like split() splitting on ASCII "whitespace" evidently predated (or ignored!) the concept of a no-break space appearing in various word-processors. Automatically?? Sure it counts for line-breaking, but some applications might want to treat it as a word-separator. It pays to look at what's in one's data, and find out what the tools and functions are actually doing with it. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Try/Except for ADSI GetObject
I am a little confused on why I can not detect an object that does not exist with a try and except. If I understand ADSI correctly from what I have read you do not create these objects but rather get them. They already exist. I believe if I do the equivalent in VB I would generate an error when I try to get an object that does not exist (can not find). What have I done wrong? I have included the function below that works in ever respect but detecting incorrect NT Domain Names (objects that do not exist) . Any tips, insight or comments would be welcome by this newbie. Thx def CheckNT4(header, all): adsi = win32com.client.Dispatch('ADsNameSpaces') try: nt = adsi.GetObject('', "WinNT://"+ frm.NTName) #->I need some type of try/except to detect incorrect NT Domain Names except: print "Domain name failed" # this does not detect a problem nt.Filter = ['user'] try: oSID = win32com.client.Dispatch('ADsSid') except: MyUsers = [ eauser for eauser in all if eauser[GetPostion(header, 'STATUS')] is ''] for ea in MyUsers: ea[GetPostion(header, 'STATUS')] = 'FailNT' ea[GetPostion(header, 'COMMENT')] ='Can not find ADsSid' MyUsers = [ eauser for eauser in all if eauser[GetPostion(header, 'STATUS')] is ''] intcnt = 0 for user in nt: for ea in MyUsers: if string.upper(user.Name) == string.upper(ea[GetPostion(header, 'OLDNTLOGON')]): frm.MyProgress.Update ( intcnt, 'Found NT user and SID : ' + user.Name ) intcnt = intcnt+ 1 if user.AccountDisabled: ea[GetPostion(header, 'STATUS')] = 'FailNT' ea[GetPostion(header, 'COMMENT')] ='Disabled' else: if ea[GetPostion(header, 'COMMENT')] is not '': ea[GetPostion(header, 'COMMENT')] = '' oSID.SetAs (5, "WinNT://"+ frm.NTName + '/' + user.Name) ea[GetPostion(header, 'STATUS')] = 'PassNT' ea[GetPostion(header, 'Nt4Sid')] = oSID.GetAs(1) for user in [ eauser for eauser in all if eauser[GetPostion(header, 'STATUS')] is '']: user[GetPostion(header, 'STATUS')] = 'FailNT' user[GetPostion(header, 'COMMENT')] = 'NoNt4Account' -- http://mail.python.org/mailman/listinfo/python-list
genexp performance problem?
Hello, I found this strange: python -mtimeit "sum(int(L) for L in xrange(3000))" 100 loops, best of 3: 5.04 msec per loop python -mtimeit "import itertools; sum(itertools.imap(int, xrange(3000)))" 100 loops, best of 3: 3.6 msec per loop I thought the two constructs could achieve the same speed. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
RE: genexp performance problem?
Giovanni Bajo wrote: > python -mtimeit "sum(int(L) for L in xrange(3000))" > 100 loops, best of 3: 5.04 msec per loop > > python -mtimeit "import itertools; sum(itertools.imap(int, > xrange(3000)))" 100 loops, best of 3: 3.6 msec per loop > > I thought the two constructs could achieve the same speed. What does it give you with: python -mtimeit -s "g = (int(L) for L in xrange(3000))" "sum(g)" ? I get: python -mtimeit "import itertools; sum(itertools.imap(int, xrange(3000)))" 100 loops, best of 3: 3.99 msec per loop python -mtimeit -s "import itertools" "sum(itertools.imap(int, xrange(3000)))" 100 loops, best of 3: 3.97 msec per loop python -mtimeit "sum(int(L) for L in xrange(3000))" 100 loops, best of 3: 6.76 msec per loop python -mtimeit -s "g = (int(L) for L in xrange(3000))" "sum(g)" 100 loops, best of 3: 1.09 usec per loop The generator comprehension needs to create a new generator each time around. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
Re: how to print newline in xml?
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > which is already not very readable - but it becomes even worse along > with increasing number of comments How about: armar3 : : XML editor + xpath makes this way more easier to use by humans compared to normal comments. Also, if you declare several of comment elements (summary, description, author, etc.) you can auto generate documentation etc. -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
RE: interactive programme (voice)
"Bell, Kevin" <[EMAIL PROTECTED]> wrote: > http://www.cs.unc.edu/~parente/tech/tr02.shtml Thanks! -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
On 31/05/2006 5:50 AM, WIdgeteye wrote: > > This PYTHON NG blows to high heaven. Whats worse, the answers I got were > most likely from people who know SQUAT about Python scripting. That's why > they gave me such lame [expletive deleted] answers. > > Idiots. Kindly refer back to your post of almost two years ago: http://groups.google.com/group/comp.lang.python/browse_frm/thread/46e15fb12e0f297a/d0e5efc00c1b5359?lnk=st&q=author%3A%09WIdgeteye&rnum=17&hl=en#d0e5efc00c1b5359 """Arg! That was it, now I really feel stupid. """ -- http://mail.python.org/mailman/listinfo/python-list
Re: TIming
WIdgeteye <[EMAIL PROTECTED]> wrote: > BTW in the time it took me NOT to get an answer for my question in > this so called Python NG, I figured it out for myself. Maybe you want to post the solution in order to help others with similar problems in the future? -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: genexp performance problem?
Delaney, Timothy (Tim) wrote: > python -mtimeit "sum(int(L) for L in xrange(3000))" > 100 loops, best of 3: 6.76 msec per loop > > python -mtimeit -s "g = (int(L) for L in xrange(3000))" "sum(g)" > 100 loops, best of 3: 1.09 usec per loop > > The generator comprehension needs to create a new generator each time > around. Reusing the generator doesn't give a correct answer; after the first sum() the generator is exhausted: In [1]: g=(int(L) for L in xrange(10)) In [2]: sum(g) Out[2]: 45 In [3]: sum(g) Out[3]: 0 Kent -- http://mail.python.org/mailman/listinfo/python-list
RE: genexp performance problem?
Kent Johnson wrote: > Reusing the generator doesn't give a correct answer; after the first > sum() the generator is exhausted: Duh - good point. I forgot it was returning a generator object, not generator function. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
shuffling elements of a list
I would like to make a function that takes a list, more specificaly a list of strings, and shuffles its elements, like a pile of cards. The following is a script I tryed to make that implements pile shuffling. -- testdeck = list('qwertyuiop') def pileshuffle(DECK, NUMPILES): """Split the deck given into NUMPILES piles. Then also put the piles""" \ """ together to make the deck again.""" # Define a list of lists which is the piles PILES = [[]] * NUMPILES card = 0 pilenum = 0 while card < len(DECK): PILES[pilenum].append(DECK[card]) card += 1 if pilenum < NUMPILES: pilenum += 1 else: pilenum = 0 print PILES -- First of all, this script tells me that an index is out of range. I cannot see why this would be so. Second of all, I would like to have other methods of shuffling, prefererably riffle shuffling and just plain randomly arranging the elements of the list. I very much appreciate any help. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
On 30 May 2006 20:18:19 -0700, greenflame <[EMAIL PROTECTED]> wrote: > Second of all, I would like to have > other methods of shuffling, prefererably riffle shuffling and just > plain randomly arranging the elements of the list. The random module has a `shuffle' method. It "Shuffle the sequence x in place". It may be help for you -- http://mail.python.org/mailman/listinfo/python-list
Tktable, WinXP and ActiveState Python 2.4.3,x
Hi, I have a python app that runs fine on MacOS X and Fedora Core 5. This evening I dragged the folder over to my windows partition and tried to run the rascal. The program starts up fine but at the first call to create a Table object I get Traceback (most recent call last): File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Documents and Settings\Jerry\Desktop\PyPgBrowseUni\PyPgExplorer.py", line 7, in ? obj.main() File "C:\Documents and Settings\Jerry\Desktop\PyPgBrowseUni\Resources\PyPgBrowse.py", line 72, in main self.build_ui( info) File "C:\Documents and Settings\Jerry\Desktop\PyPgBrowseUni\Resources\PyPgBrowse.py", line 187, in build_ui rowtagcommand=self.rowproc File "C:\Documents and Settings\Jerry\Desktop\PyPgBrowseUni\Resources\Tktable.py", line 64, in __init__ master.tk.call('load', '', 'Tktable' ) TclError: package "Tktable" isn't loaded statically : I get the same error if I try to create a Table object from the command line in a console. I tried waving a dead chicken at my laptop but it did no good. Is there some special magic to get Tktable.py to play nice? I do have the latest Tcl from Active State loaded on my box and the Tktable in my Tk programs work well... Thanks for any insight Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
Zhang Fan wrote: > On 30 May 2006 20:18:19 -0700, greenflame <[EMAIL PROTECTED]> wrote: > > Second of all, I would like to have > > other methods of shuffling, prefererably riffle shuffling and just > > plain randomly arranging the elements of the list. > > The random module has a `shuffle' method. It "Shuffle the sequence x > in place". > It may be help for you I am sorry but this does not help much. In my version of python (2.3) this method does not seem to exist. Also from the documentation, it seems that this method would give a random number. -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
"greenflame" <[EMAIL PROTECTED]> writes: > I would like to make a function that takes a list, more specificaly a > list of strings, and shuffles its elements, like a pile of cards. Sounds like a job for (ta-da-daa) DSU[0]. That said, here are some comments on your implementation. > -- > testdeck = list('qwertyuiop') > > def pileshuffle(DECK, NUMPILES): Ouch. Why use uppercase for the parameter names? This implies either shouting, or constants, neither of which is appropriate. > """Split the deck given into NUMPILES piles. Then also put the > piles""" \ > """ together to make the deck again.""" Remember that triple-quoted strings don't terminate until the next triple-quote delimiter. This means not having to close and open them every newline, which is a primary reason to choose them for doc strings. def pileshuffle(deck, numpiles): """ Split the deck bla bla bla bla bla bla. """ > # Define a list of lists which is the piles > PILES = [[]] * NUMPILES More shouting :-( That will create a list with many references to the *same* list; almost certainly not what you want. This creates the desired number of new lists:: piles = [] for _ in range(numpiles): piles.append(list()) The '_' name is convention for "We're not going to use this value". For something more Pythonic, try a list comprehension:: piles = [list() for _ in range(numpiles)] > card = 0 > pilenum = 0 > while card < len(DECK): > PILES[pilenum].append(DECK[card]) > card += 1 > if pilenum < NUMPILES: > pilenum += 1 > else: > pilenum = 0 Please don't write C in Python. The 'for' statement allows iteration directly over a sequence, no need to maintain an index. Also, the modulus operator is called for with your cycling of the pile index. pile_index = 0 for card in deck: piles[pile_index].append(card) pile_index = (pile_index + 1) % numpiles Rather than having the function print the result, it should return it; that way, the caller gets to decide what happens with the result. return piles Here's my result with your test input:: >>> def pileshuffle(deck, numpiles): ... """ Split the deck into piles """ ... piles = [list() for _ in range(numpiles)] ... pile_index = 0 ... for card in deck: ... piles[pile_index].append(card) ... pile_index = (pile_index + 1) % numpiles ... return piles ... >>> deck = list("qwertyuiop") >>> print pileshuffle(deck, 5) [['q', 'y'], ['w', 'u'], ['e', 'i'], ['r', 'o'], ['t', 'p']] >>> print pileshuffle(deck, 3) [['q', 'r', 'u', 'p'], ['w', 't', 'i'], ['e', 'y', 'o']] For actually implementing this, and to allow the flexibility you said you wanted, using DSU would be most obvious to me. [0] Decorate-Sort-Undecorate http://en.wikipedia.org/wiki/Schwartzian_Transform> -- \ "Pity the meek, for they shall inherit the earth." -- Donald | `\ Robert Perry Marquis | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
On 31/05/2006 1:18 PM, greenflame wrote: > I would like to make a function that takes a list, more specificaly a > list of strings, and shuffles its elements, like a pile of cards. The > following is a script I tryed to make that implements pile shuffling. > In general, if you can't see why Python is complaining, insert print statements. Anyhow, read the following, run it, read it again, ... HTH, John def pileshuffle1(deck, numpiles, fix1bug=False): piles = [[]] * numpiles # 2nd bug: n references to *same* sublist card = 0 pilenum = 0 while card < len(deck): print card, pilenum assert 0 <= pilenum < numpiles piles[pilenum].append(deck[card]) card += 1 if not fix1bug: if pilenum < numpiles: pilenum += 1 else: pilenum = 0 else: pilenum = (pilenum + 1) % numpiles print print piles def pileshuffle2(deck, numpiles): piles = [[] for x in range(numpiles)] # n *different* sublists for cardindex, card in enumerate(deck): piles[cardindex % numpiles].append(card) print print piles pileshuffle1('qwertyuiop', 3, True) pileshuffle2('qwertyuiop', 3) pileshuffle1('qwertyuiop', 3, False) -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
greenflame wrote: > Zhang Fan wrote: >> ... The random module has a `shuffle' method. It "Shuffle the sequence x >> in place". It may be help for you > > I am sorry but this does not help much. In my version of python (2.3) > this method does not seem to exist. Also from the documentation, it > seems that this method would give a random number. Using Python 2.3.4 on Windows 2000, I get: import random lst = range(52) random.shuffle(lst) print lst [8, 26, 9, 10, 22, 39, 36, 48, 29, 5, 50, 16, 15, 2, 40, 33, 3, 7, 37, 43, 11, 0, 30, 49, 32, 44, 24, 47, 42, 27, 23, 28, 12, 18, 13, 35, 1, 34, 25, 45, 21, 20, 46, 38, 17, 31, 6, 4, 14, 41, 51, 19] Don't be so sure the advice you get is wrong. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: shuffling elements of a list
Thank you all for all of your help. Also I got the shuffle function to work. Do not worry I will be back soon with more shuffling! However, I do not quite understand this DSU that you mention, although it looks useful. -- http://mail.python.org/mailman/listinfo/python-list