Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Luke Paireepinart
Oops, you should probably have a "return True" at the end of the function so the return value is meaningful. On Tue, Jul 7, 2009 at 9:29 PM, Luke Paireepinart wrote: > I typically abuse the fact that "return" will get you out of a function to > make my code indented less.perhaps others would frown

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Luke Paireepinart
I typically abuse the fact that "return" will get you out of a function to make my code indented less.perhaps others would frown upon this but it makes sense to me. With various other changes, I'd make your function like so: from os import path, listdir, remove def clean(folder): if not path.e

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread David
Luke Paireepinart wrote: On Tue, Jul 7, 2009 at 8:36 PM, David > wrote: Hi Tutors, Hiya david. Cool e-mail address :) Thanks, want l...@pythontoo.com I have a few to spare :) But if there are no files in the directory it never gets to the else. Rig

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Marc Tompkins
On Tue, Jul 7, 2009 at 6:36 PM, David wrote: > My question is I tried to get it to print out when the directory was empty > like this; > > for file in fobj: >pathname = os.path.join(folder, file) >if os.path.exists(pathname): >print 'removing... ', file >os.remove(pathname

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Luke Paireepinart
On Tue, Jul 7, 2009 at 8:36 PM, David wrote: > Hi Tutors, Hiya david. Cool e-mail address :) > My question is I tried to get it to print out when the directory was empty > like this; > > for file in fobj: >pathname = os.path.join(folder, file) >if os.path.exists(pathname): >pri

[Tutor] if: else: can not get else to work

2009-07-07 Thread David
Hi Tutors, I have a web cam that saves files in /var/log/motion and it can get quite large so I clean it every few days. I came up with this; #!/usr/bin/python import commands import os from sys import exit def clean_motion(): folder = '/var/log/motion' if os.path.exists(folder):

Re: [Tutor] mac os x executable

2009-07-07 Thread wesley chun
>>> After all with Python 2.3 pre installed on MacOS X >> Is Python 2.3 really the most recent version of Python distributed with >> new Macs? > I think *new* Macs come with 2.5. My 2-year-old MacBook Pro has 2.3. i got a new MBP from work about half a year ago with leopard 10.5.6 installed, and

Re: [Tutor] mac os x executable

2009-07-07 Thread Pete Froslie
That's great Alan.. I see what you mean with the shortcut-- going to try it. Thanks for the suggestion on the Mac OS x manual.. I will certainly start looking more into OS fundamentals. I will say that I've been having a really good time with Python and am excited to see it start working further w

Re: [Tutor] mac os x executable

2009-07-07 Thread Kent Johnson
On Tue, Jul 7, 2009 at 5:51 PM, wrote: > Alan, > >> After all with Python 2.3 pre installed on MacOS X > > Is Python 2.3 really the most recent version of Python distributed with > new Macs? I think *new* Macs come with 2.5. My 2-year-old MacBook Pro has 2.3. > So if I wanted to distribute a Pyt

Re: [Tutor] mac os x executable

2009-07-07 Thread ALAN GAULD
> Yes, this makes sense to me.. but when treating a project as an artwork > I can't ask people to go through an effort beyond a simple start of the > app. For instance, I'm in Boston and the work is being show on a > computer in gallery in SF-- if it crashes, curators often will be > unenthusia

Re: [Tutor] mac os x executable

2009-07-07 Thread python
Alan, > After all with Python 2.3 pre installed on MacOS X Is Python 2.3 really the most recent version of Python distributed with new Macs? So if I wanted to distribute a Python 2.6 script to a Mac user, I would need to instruct the Mac user how to download and install a separate version of Py

Re: [Tutor] mac os x executable

2009-07-07 Thread Pete Froslie
Yes, this makes sense to me.. but when treating a project as an artwork I can't ask people to go through an effort beyond a simple start of the app. For instance, I'm in Boston and the work is being show on a computer in gallery in SF-- if it crashes, curators often will be unenthusiastic when bein

Re: [Tutor] mac os x executable

2009-07-07 Thread Alan Gauld
"Pete Froslie" wrote I'm having trouble finding good tutorials on creating standalone executable files for mac os x.. I've been looking at 'py2app', but can't seem get a solid grasp. Any help would be greatly appreciated! My first question would be do you need to? After all with Python 2.3

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread Alan Gauld
"John [H2O]" wrote ind = np.where( (X[:,0] > hr) & (X[:,0] < nhr) ) I have no idea what this is doing but do you really mean a bitwise and here? You are effectively bitwise anding two boolean values which seems odd to put it mildly... Well, effectively I am searching the array for v

Re: [Tutor] mac os x executable

2009-07-07 Thread Bill Campbell
On Tue, Jul 07, 2009, Pete Froslie wrote: > > Wesley, > What I meant is that I would like a file that can be double clicked in > order to run the python script.. so that I can drop it on another mac > where someone can execute it without worrying about Terminal. > Essentially, I need ever

Re: [Tutor] mac os x executable

2009-07-07 Thread Pete Froslie
Wesley, What I meant is that I would like a file that can be double clicked in order to run the python script.. so that I can drop it on another mac where someone can execute it without worrying about Terminal. Essentially, I need everything to be clean in the end.. My projects are artworks and f

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread David Kim
Thanks Kent, perhaps I'll cool the Python jets and move on to HTTP and HTML. I was hoping it would be something I could just pick up along the way, looks like I was wrong. dk On Tue, Jul 7, 2009 at 1:56 PM, Kent Johnson wrote: > On Tue, Jul 7, 2009 at 1:20 PM, David Kim wrote: >> On Tue, Jul 7, 2

Re: [Tutor] mac os x executable

2009-07-07 Thread wesley chun
>> >I'm having trouble finding good tutorials on creating standalone >> > executable >> >files for mac os x.. I've been looking at 'py2app', [...] pete, welcome to Python! in order for all to answer your question more appropriately, you'll have to describe the problem in slightly more detail.

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread Kent Johnson
On Tue, Jul 7, 2009 at 1:20 PM, David Kim wrote: > On Tue, Jul 7, 2009 at 7:26 AM, Kent Johnson wrote: >> >> curl works because it ignores the redirect to the ToS page, and the >> site is (astoundingly) dumb enough to serve the content with the >> redirect. You could make urllib2 behave the same wa

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread Sander Sweers
2009/7/7 David Kim : > opener = urllib2.build_opener(MyHTTPRedirectHandler, cookieprocessor) > urllib2.install_opener(opener) > > response = > urllib2.urlopen("http://www.dtcc.com/products/derivserv/data_table_i.php?id=table1";) > print response.read() > > > I suspect I am not understanding s

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread David Kim
On Tue, Jul 7, 2009 at 7:26 AM, Kent Johnson wrote: > > curl works because it ignores the redirect to the ToS page, and the > site is (astoundingly) dumb enough to serve the content with the > redirect. You could make urllib2 behave the same way by defining a 302 > handler that does nothing. Many

Re: [Tutor] mac os x executable

2009-07-07 Thread Pete Froslie
Thanks Bill, Terminal tells me, 'chmod: app_test.py: No such file or directory' I assume that's what you meant to do? Drop this at the start of the script: #!/usr/bin/env python Then go into terminal and type: `chmod +x mypython.py'' --pretty new to some of this stuff. cheers On Tue, Jul 7,

Re: [Tutor] mac os x executable

2009-07-07 Thread Bill Campbell
On Tue, Jul 07, 2009, Pete Froslie wrote: >Hi, > >I'm having trouble finding good tutorials on creating standalone executable >files for mac os x.. I've been looking at 'py2app', but can't seem get a >solid grasp. Any help would be greatly appreciated! For a python script, say mypython.py, it shou

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread Sander Sweers
2009/7/7 John [H2O] : > > The data is just x,y data where x = datetime objects from the datetime > module. y are just floats. It is bundled in a numpy array. I might be totally off but, did know that you can compare datetime objects? >>> from datetime import datetime >>> d1 = datetime.now() >>> d

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread John [H2O]
Alan Gauld wrote: > > > I assume there is a good reason to use a numpy array instead of > a regular list? ie You need a numpy array elsewhere in the code? > I've never used numpy bt there is a possibility that array access > is slower than list access, but I have no idea. It just adds an extra

[Tutor] mac os x executable

2009-07-07 Thread Pete Froslie
Hi, I'm having trouble finding good tutorials on creating standalone executable files for mac os x.. I've been looking at 'py2app', but can't seem get a solid grasp. Any help would be greatly appreciated! cheers ___ Tutor maillist - Tutor@python.org h

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread Skipper Seabold
On Tue, Jul 7, 2009 at 6:16 AM, John [H2O] wrote: > > Here's a function I wrote to calculate hourly averages: > > It seems a bit slow, however... any thoughts on how to improve it? > > def calc_hravg(X): >    """Calculates hourly average from input data""" > >    X_hr = [] >    minX = X[:,0].min()

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread Alan Gauld
"John [H2O]" wrote The data is just x,y data where x = datetime objects from the datetime module. y are just floats. It is bundled in a numpy array. So the only import statements are: import datetime as dt import numpy as np I pass the array X, where X is a numpy array of shape [n,2] where n

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread John [H2O]
The data is just x,y data where x = datetime objects from the datetime module. y are just floats. It is bundled in a numpy array. So the only import statements are: import datetime as dt import numpy as np I pass the array X, where X is a numpy array of shape [n,2] where n is the number of poin

Re: [Tutor] using datetime and calculating hourly average

2009-07-07 Thread bob gailer
John [H2O] wrote: Here's a function I wrote to calculate hourly averages: It seems a bit slow, however... any thoughts on how to improve it? def calc_hravg(X): """Calculates hourly average from input data""" X_hr = [] minX = X[:,0].min() hr = dt.datetime(*minX.timetuple()[0:4])

Re: [Tutor] cx_oracle module problems

2009-07-07 Thread M8R-sjkk73
The $ORACLE_HOME variable probably isn't set for root. Try passing sudo the $ORACLE_HOME variable. sudo env ORACLE_HOME=$ORACLE_HOME python setup.py install - or - sudo env ORACLE_HOME=/path/to/instantclient python setup.py install Jeremiah Jester wrote: > > I've downloaded the cx_oracle s

Re: [Tutor] Urllib, mechanize, beautifulsoup, lxml do not compute (for me)!

2009-07-07 Thread Kent Johnson
On Mon, Jul 6, 2009 at 5:54 PM, David Kim wrote: > Hello all, > > I have two questions I'm hoping someone will have the patience to > answer as an act of mercy. > > I. How to get past a Terms of Service page? > > I've just started learning python (have never done any programming > prior) and am try

Re: [Tutor] HI

2009-07-07 Thread A.T.Hofkamp
Vishnu S wrote: Sir/Madame, i'm a begginner to Python help me in putting the first step to this world Welcome! A useful first page may be http://wiki.python.org/moin/BeginnersGuide for an overview, and http://wiki.python.org/moin/BeginnersGuide/NonProgrammers where you can find a lot of link

[Tutor] using datetime and calculating hourly average

2009-07-07 Thread John [H2O]
Here's a function I wrote to calculate hourly averages: It seems a bit slow, however... any thoughts on how to improve it? def calc_hravg(X): """Calculates hourly average from input data""" X_hr = [] minX = X[:,0].min() hr = dt.datetime(*minX.timetuple()[0:4]) while hr

[Tutor] HI

2009-07-07 Thread Vishnu S
Sir/Madame, i'm a begginner to Python help me in putting the first step to this world With regards Vishnu S ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-07 Thread Luis Galvan
Thanks for the responses! :) Hopefully Gmail's quoting feature shows up just fine. 1. http://www.challenge-you.com/ >> 2. http://projecteuler.net/index.php?section=logout >> 3. http://www.spoj.pl/problems/classical/ >> 4. http://codegolf.com/ >> 5. http://www.codechef.co

Re: [Tutor] Python Tutorials: How to create useful programs after learning the syntax?

2009-07-07 Thread Luis Galvan
Thanks for the responses! :) Hopefully Gmail's quoting feature shows up just fine. 1. http://www.challenge-you.com/ >> 2. http://projecteuler.net/index.php?section=logout >> 3. http://www.spoj.pl/problems/classical/ >> 4. http://codegolf.com/ >> 5. http://www.codechef.co