Thanks a lot Alan and Karim, it's working -- I really appreciate it, guys.
On Wed, Aug 25, 2010 at 4:53 AM, <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: continuous running of a method (Greg Bair) > 2. Re: continuous running of a method (Hugo Arts) > 3. Re: Retriving previous user inputs in a gui (Alan Gauld) > 4. Re: python: can't open file 'ex1.py' : [Errno 2] No such > fileor directory (Alan Gauld) > 5. os.access unreliable? (Albert-Jan Roskam) > 6. Re: os.access unreliable? (Tim Golden) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Wed, 25 Aug 2010 01:56:14 -0400 > From: Greg Bair <gregb...@gmail.com> > To: tutor@python.org > Subject: Re: [Tutor] continuous running of a method > Message-ID: <4c74b07e.3060...@gmail.com> > Content-Type: text/plain; charset=UTF-8; format=flowed > > On 08/25/2010 01:25 AM, Nitin Das wrote: > > The problem with this while loop is if your random value doesn't lie > > between the mentioned range then ur 100% cpu would be utilized. The > > one thing u can do is to sleep for some time lets say 0.5 sec after > > every while loop iteration , in this case ur cpu utilization will go > down. > It's not that the value doesn't lie between the mentioned range. > > What I'm doing is randomly fetching an item from a list of dicts > (multi-dimensional ones from a JSON response) and accessing a value from > it, but not every item has the key I'm looking for (can't change that). > I suppose what I could do to not randomize every time is to iterate > through the list and create a new list that only contains dicts that > have that key, then get a random one from that. I suppose that would be > more efficient. > > Any thoughts? > > Greg > > > > --nitin > > > > On Mon, Aug 23, 2010 at 8:21 PM, bob gailer <bgai...@gmail.com > > <mailto:bgai...@gmail.com>> wrote: > > > > On 8/23/2010 1:00 AM, Greg Bair wrote: > > > > I have a method (I'll call it foo) that will either return > > None or an object depending on a random value generated. What > > I want to happen is that if I call foo(), i.e, f = foo() and > > it returns None, to re-call it until it returns something > > else. I would think this would be done with a while loop, but > > can't seem to get the details right. > > > > > > Even though a while will work, you will have tied up the CPU until > > the loop terminates. This is never a good idea. > > > > What is your higher level goal? > > > > > > > > ------------------------------ > > Message: 2 > Date: Wed, 25 Aug 2010 02:12:46 -0500 > From: Hugo Arts <hugo.yo...@gmail.com> > To: Greg Bair <gregb...@gmail.com> > Cc: tutor@python.org > Subject: Re: [Tutor] continuous running of a method > Message-ID: > <aanlktingribt-sbecpi7btuzq5vfuz3e4mntkm2sa...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > On Wed, Aug 25, 2010 at 12:56 AM, Greg Bair <gregb...@gmail.com> wrote: > > > > It's not that the value doesn't lie between the mentioned range. > > > > What I'm doing is randomly fetching an item from a list of dicts > > (multi-dimensional ones from a JSON response) and accessing a value from > it, > > but not every item has the key I'm looking for (can't change that). ?I > > suppose what I could do to not randomize every time is to iterate through > > the list and create a new list that only contains dicts that have that > key, > > then get a random one from that. ?I suppose that would be more efficient. > > > > Any thoughts? > > > > this sounds like a good idea. Either the filter() function or a list > comprehension can filter out the dicts you want easily. > > My guess is the list comprehension is somewhat faster, but I could be > wrong. And it doesn't sound like performance is a very big deal here > anyway, so take your pick. > > Hugo > > > ------------------------------ > > Message: 3 > Date: Wed, 25 Aug 2010 08:21:31 +0100 > From: "Alan Gauld" <alan.ga...@btinternet.com> > To: tutor@python.org > Subject: Re: [Tutor] Retriving previous user inputs in a gui > Message-ID: <i52g9o$cq...@dough.gmane.org> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > "Karim" <karim.liat...@free.fr> wrote > > > Is there any equivalent to JAVACC in python (or lex yacc) to create > > grammary > > for config or format file? > > Thats kind of what ConfiogParser does - it gives you tools to > read/write > a config file. > > If you don't mind the data not being human readable you could also > use the shelve module which simulates a dictionary in a file. > > There are lots of options. > > Alan G. > > > > > ------------------------------ > > Message: 4 > Date: Wed, 25 Aug 2010 08:30:59 +0100 > From: "Alan Gauld" <alan.ga...@btinternet.com> > To: tutor@python.org > Subject: Re: [Tutor] python: can't open file 'ex1.py' : [Errno 2] No > such fileor directory > Message-ID: <i52grh$es...@dough.gmane.org> > Content-Type: text/plain; format=flowed; charset="iso-8859-1"; > reply-type=original > > > "Carter Danforth" <carter.danfo...@gmail.com> wrote > > > Anyhow, I can't seem to be executing any files in terminal for some > > reason, in this case the file ex1.py: > > > > C:\Users\Carter Danforth\python ex1.py > > python: can't open file 'ex1.py': [Errno 2] No such file or > > directory > > > > ex1.py is located in "pythonpractice" on my desktop and I've updated > > the > > modules, here's the output from sys.path: > > sys.path (and PYTHONPATH) only affect how imports work within > Python, they have no effect on Windows ability to find scripts. > To run a script you must do one of the following: > > 1) CD to the script folder and run Python from there as: > > Python myscript.py > > 2) From anywhere execute Python as > > python full\path\to\myscript.py > > 3) From anywhere execute myscript as > > myscript.py > > For 1,2 PATH must include the Python executable folder > For 3 the .py extension must be associated with the Python > executable and the folder containing myscript must be in PATH. > > > I'm not sure why I keep getting this error message and why I'm not > > able to > > execute any .py files. Any help would be great appreciated. > > Windows needs to know where the file lives. You could have many > files called myscript.py in your file system. PYTHONPATH is used > only by Python and only for imports. PATH is used only for > executables. > > HTH, > > > -- > Alan Gauld > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > > > > > ------------------------------ > > Message: 5 > Date: Wed, 25 Aug 2010 01:28:47 -0700 (PDT) > From: Albert-Jan Roskam <fo...@yahoo.com> > To: Python Mailing List <tutor@python.org> > Subject: [Tutor] os.access unreliable? > Message-ID: <502129.63760...@web110716.mail.gq1.yahoo.com> > Content-Type: text/plain; charset="iso-8859-1" > > Hi, > > Hi I'm using os.access to do a preliminary check to see if I have RW > access, but > it seems to be unreliable. In a dir for which I have only read access, > os.access > also says I have write access. This is under Windows 2000. I could of > course use > a try-except and catch the IOError, but I'd like to know why the code below > isn;t working. > > ??? def isAcccessible(self): > ??????? if os.access(self.path, os.R_OK) and os.access(self.path, os.W_OK): > ??????????? return True > ??????? else: > ??????????? return False > ?Cheers!! > Albert-Jan > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > All right, but apart from the sanitation, the medicine, education, wine, > public > order, irrigation, roads, a fresh water system, and public health, what > have the > Romans ever done for us? > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tutor/attachments/20100825/3a660844/attachment-0001.html > > > > ------------------------------ > > Message: 6 > Date: Wed, 25 Aug 2010 09:53:08 +0100 > From: Tim Golden <m...@timgolden.me.uk> > Cc: Python Mailing List <tutor@python.org> > Subject: Re: [Tutor] os.access unreliable? > Message-ID: <4c74d9f4.3030...@timgolden.me.uk> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed > > On 25/08/2010 09:28, Albert-Jan Roskam wrote: > > Hi, > > > > Hi I'm using os.access to do a preliminary check to see if I have RW > access, but > > it seems to be unreliable. In a dir for which I have only read access, > os.access > > also says I have write access. This is under Windows 2000. I could of > course use > > a try-except and catch the IOError, but I'd like to know why the code > below > > isn;t working. > > > > def isAcccessible(self): > > if os.access(self.path, os.R_OK) and os.access(self.path, > os.W_OK): > > return True > > else: > > return False > > os.access is effectively meaningless under Windows, especially > against directories. It only checks the read-only flag (which > doesn't mean anything for directories anyway). > > There is a long-open issue here: > > http://bugs.python.org/issue2528 > > which I am half-minded to close although I could be > persuaded to pursue it if anyone were interested enough. > On the other hand, os.access checks are open to race-conditions > in any case, so you might simply be better off with a > try-except block as you suggest. > > If you want more information I can explain further but unless you > want to dive into the Windows API and use AccessCheck -- which is > what that patch is doing -- then I suggest you use try-except > > TJG > > > ------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 78, Issue 116 > ************************************** >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor