[Tutor] ArcGis 10 support materials for Python

2011-01-24 Thread saxon piggott

Hello,
 
I was wondering if there is any information anywhere on the use of Python 
scripts (How to..) for ESRIs ArcGIS 10? or alternatively, if ESRI press or 
perhaps some other publisher has released a book that details obect oriented 
programming (presumably with Python scripting) for ArcGIS 10?
 
A simialr book exists for VBA for ArcGIS 9 called Getting To Know ArcObjects 
released by Robert Burke for ESRI. However I cannot find a dedicated Python 
text or site for ArcGIS 9 or 10 anywhere.  Its a bit of a problem as ArcGIS is 
phasing out VBA which is no longer available in version 10.
 
Any help locating a relevent publication would be greatly appreciated as I can 
find very little information for this on the Esri site.
 
Best regards,
Saxon Piggott
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Weave - how to find the compiler on windows

2011-01-24 Thread CS
Hello!
I want to use weave.biltz(), but it doesn´t find the compiler. I installed 
minGW on windows in the path C:\MinGW\bin (so no spaces here) and added it to 
the path variable (and it works on the command line). 

I already installed python and scipy. Okay, now the question : 
How do I tell scipy where the compiler is?! Every time I call weave.blitz() it 
returns "The 'gcc' compiler was not found"

In the documentation it is written that the compiler used for building python 
is used for weave too. But I just installed python by an .exe - file...

Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] ArcGis 10 support materials for Python

2011-01-24 Thread Vern Ceder
I do know that ArgGIS and Python are used together a fair amount, but
I'm not aware of a book.

I'm assuming that you've already checked out pages like this?

http://gisweb.apsu.edu/blogs/arcgis-10-and-python

Cheers,
Vern


On Mon, Jan 24, 2011 at 4:28 AM, saxon piggott  wrote:
> Hello,
>
> I was wondering if there is any information anywhere on the use of Python
> scripts (How to..) for ESRIs ArcGIS 10? or alternatively, if ESRI press or
> perhaps some other publisher has released a book that details obect oriented
> programming (presumably with Python scripting) for ArcGIS 10?
>
> A simialr book exists for VBA for ArcGIS 9 called Getting To Know ArcObjects
> released by Robert Burke for ESRI. However I cannot find a dedicated Python
> text or site for ArcGIS 9 or 10 anywhere.  Its a bit of a problem as ArcGIS
> is phasing out VBA which is no longer available in version 10.
>
> Any help locating a relevent publication would be greatly appreciated as I
> can find very little information for this on the Esri site.
>
> Best regards,
> Saxon Piggott
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Vern Ceder
vce...@gmail.com, vce...@dogsinmotion.com
The Quick Python Book, 2nd Ed - http://bit.ly/bRsWDW
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help listing directory timestamps and deleting directories

2011-01-24 Thread bsd...@gmail.com
Hi, hoping for some help here. I've been trying to write a python script
(complete newb) and have spent several days trying to get this right with no
success.

I am trying to list timestamps in a directory and if they are older than x
amount of days delete the directories. It seems that in my for loop it is
only evaluating the last timestamp of the last directory and using that
timestamp to make the deletion decision. I realize that this script isn't
going to delete the directories with evaluate as true but I haven't been
able to get that far yet...



###start script##
###Modules###

import os
import time

###Global Variables###

curr_t = time.time()

days = 2629743 #2629743 is 30 days in epoch time.

directory=os.path.join("/home", "userid", "python")


for r,d,f in os.walk(directory):
for dir in d:
timestamp = os.path.getmtime(os.path.join(r,dir)) ## It seems that
the below "if" statement is only comparing the timestamp of the last
directory that this variable lists.
print timestamp
if curr_t - days < timestamp:   I am expecting
this statement to compare each timestamp of the "directory" variable and
print out if it should be deleted or not.
print "Your file will be deleted"

else:
print "File will NOT be deleted..."


###end of script#



Thank you for your time!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help listing directory timestamps and deleting directories

2011-01-24 Thread Vince Spicer
On Mon, Jan 24, 2011 at 11:25 AM, bsd...@gmail.com  wrote:

> Hi, hoping for some help here. I've been trying to write a python script
> (complete newb) and have spent several days trying to get this right with no
> success.
>
> I am trying to list timestamps in a directory and if they are older than x
> amount of days delete the directories. It seems that in my for loop it is
> only evaluating the last timestamp of the last directory and using that
> timestamp to make the deletion decision. I realize that this script isn't
> going to delete the directories with evaluate as true but I haven't been
> able to get that far yet...
>
>
>
> ###start script##
> ###Modules###
>
> import os
> import time
>
> ###Global Variables###
>
> curr_t = time.time()
>
> days = 2629743 #2629743 is 30 days in epoch time.
>
> directory=os.path.join("/home", "userid", "python")
>
>
> for r,d,f in os.walk(directory):
> for dir in d:
> timestamp = os.path.getmtime(os.path.join(r,dir)) ## It seems that
> the below "if" statement is only comparing the timestamp of the last
> directory that this variable lists.
> print timestamp
> if curr_t - days < timestamp:   I am expecting
> this statement to compare each timestamp of the "directory" variable and
> print out if it should be deleted or not.
> print "Your file will be deleted"
>
> else:
> print "File will NOT be deleted..."
>
>
> ###end of script#
>
>
>
> Thank you for your time!
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
First off, I would recommend using dates and not times, this can help make
things clearer
when dealing with dates, also the dateutil module can make date math a lot
simpler (easy_install dateutil)


from datetime import datetime
from dateutil.relativedelta import relativedelta

remove_after = datetime.now() - relativedelta(days=31)  # exactly 1 month
prior to today
check_dir = "/path/to/whatever"

for r,d,f in os.walk(check_dir):
for dir in d:
loc =  os.path.join(r,dir)
last_modified = datetime.fromtimestamp(os.path.getmtime(loc))
if last_modifed < remove_after:
print "delete old directory", loc
else:
print "keep recently modified", loc



Hope this helps,

Vince Spicer
Developer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help listing directory timestamps and deleting directories

2011-01-24 Thread Japhy Bartlett
I would check that os.path.join(r,dir) is giving you the directory you
think it is.

- japhy

On Mon, Jan 24, 2011 at 12:25 PM, bsd...@gmail.com  wrote:
> Hi, hoping for some help here. I've been trying to write a python script
> (complete newb) and have spent several days trying to get this right with no
> success.
>
> I am trying to list timestamps in a directory and if they are older than x
> amount of days delete the directories. It seems that in my for loop it is
> only evaluating the last timestamp of the last directory and using that
> timestamp to make the deletion decision. I realize that this script isn't
> going to delete the directories with evaluate as true but I haven't been
> able to get that far yet...
>
>
>
> ###start script##
> ###Modules###
>
> import os
> import time
>
> ###Global Variables###
>
> curr_t = time.time()
>
> days = 2629743 #2629743 is 30 days in epoch time.
>
> directory=os.path.join("/home", "userid", "python")
>
>
> for r,d,f in os.walk(directory):
>     for dir in d:
>     timestamp = os.path.getmtime(os.path.join(r,dir)) ## It seems that
> the below "if" statement is only comparing the timestamp of the last
> directory that this variable lists.
>     print timestamp
>     if curr_t - days < timestamp:   I am expecting
> this statement to compare each timestamp of the "directory" variable and
> print out if it should be deleted or not.
>     print "Your file will be deleted"
>
>     else:
>     print "File will NOT be deleted..."
>
>
> ###end of script#
>
>
>
> Thank you for your time!
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help listing directory timestamps and deleting directories

2011-01-24 Thread Karim


Hello,

Also working w/o external module just the standard one:

*>>> import datetime
>>> remove_after = datetime.datetime.now() - datetime.timedelta(days=31)
>>> remove_after
datetime.datetime(2010, 12, 24, 23, 21, 10, 11315)
*
Regards
Karim

On 01/24/2011 08:02 PM, Vince Spicer wrote:



On Mon, Jan 24, 2011 at 11:25 AM, bsd...@gmail.com 
 mailto:bsd...@gmail.com>> 
wrote:


Hi, hoping for some help here. I've been trying to write a python
script (complete newb) and have spent several days trying to get
this right with no success.

I am trying to list timestamps in a directory and if they are
older than x amount of days delete the directories. It seems that
in my for loop it is only evaluating the last timestamp of the
last directory and using that timestamp to make the deletion
decision. I realize that this script isn't going to delete the
directories with evaluate as true but I haven't been able to get
that far yet...



###start script##
###Modules###

import os
import time

###Global Variables###

curr_t = time.time()

days = 2629743 #2629743 is 30 days in epoch time.

directory=os.path.join("/home", "userid", "python")


for r,d,f in os.walk(directory):
for dir in d:
timestamp = os.path.getmtime(os.path.join(r,dir)) ## It
seems that the below "if" statement is only comparing the
timestamp of the last directory that this variable lists.
print timestamp
if curr_t - days < timestamp:   I am
expecting this statement to compare each timestamp of the
"directory" variable and print out if it should be deleted or not.
print "Your file will be deleted"

else:
print "File will NOT be deleted..."


###end of script#



Thank you for your time!

___
Tutor maillist  - Tutor@python.org 
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


First off, I would recommend using dates and not times, this can help 
make things clearer
when dealing with dates, also the dateutil module can make date math a 
lot simpler (easy_install dateutil)



from datetime import datetime
from dateutil.relativedelta import relativedelta

remove_after = datetime.now() - relativedelta(days=31)  # exactly 1 
month prior to today

check_dir = "/path/to/whatever"

for r,d,f in os.walk(check_dir):
for dir in d:
loc = os.path.join(r,dir)
last_modified = datetime.fromtimestamp(os.path.getmtime(loc))
if last_modifed < remove_after:
print "delete old directory", loc
else:
print "keep recently modified", loc



Hope this helps,

Vince Spicer
Developer



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Bill Allen
This is a bit embarrassing, but I have crafted a bit of code that does
EXACTLY what I what, but I am now a bit baffled as to precisely why.  I have
written a function to do a bit of webscraping by following links for a
project at work.  If I leave the code as is, it behaves like it is
recursively passing through the data tree- which is what I want.  However,
if I change it only slightly, it makes only one pass through the top level
data.  What I do not understand is why is ever behaves as if it is recursive
as the function is only called once.

If I comment out_list=[] and let out_list-=part_list be used the following
parses through the whole tree of data as if recursive.  If I use out_list=[]
and comment out_list=part_list, it only processes to top level of the data
tree.

The function is called only once as:  Exploded_BOM_List =
get_BOM(first_num)  in which I pass it a single part number to start with.
The webscraping bit goes to a particular webpage about that part where it
then picks up more part numbers and repeats the process.

So can anyone help me understand why this actually works?  Certainly no
complaints here about it, but I would like to better understand why changes
the behavior so profoundly.  All the print statements are just to I could
follow out the data flow while working on this.  By following the data flow,
I am finding that part_list is actually having values added to it during the
time the function is running.   Problem is, I don't see clearly why that
should be so.

def get_BOM(part_list):
x=re.compile('part='+'.*?'+'>')
BOM_List = []

#out_list = []
out_list = part_list
print("called get_BOM")
pass_num = 0
for part_num in part_list:
mypath = "http://xxx.xxx.xxx.xxx/cgi-bin/search/part-url.cgi?part=";
+ part_num
mylines = urllib.urlopen(mypath).readlines()
print("pass number ", pass_num)
print(mypath)
print("PL:",part_list)
for item in mylines:
if "http://"; in item:
if "part=" in item:
xstring=str(x.findall(item)).strip('"[\'part=>\']"')
BOM_List.append(xstring)
print("BL:",BOM_List)
for bom_item in BOM_List:
if bom_item not in out_list:
out_list.append(bom_item)
print("OL:",out_list)
pass_num += 1
return(out_list)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Bill Allen
By the way, my guess as to why this is working for me the way it does is
that the statement

out_list = part_list

is actually linking these two objects, making them one.   My intention had
been to just assign values from one to the other, but I think I have done
far more than that.   In this case, if that is true, then it has worked out
well for me, giving me a feedback loop through the data.  However, I can see
that it could also be a pitfall if this behavior is not clearly understood.
Am I right?   Am I way off base?  Either way, I could use some elaboration
about it.


--Bill





On Mon, Jan 24, 2011 at 23:56, Bill Allen  wrote:

> This is a bit embarrassing, but I have crafted a bit of code that does
> EXACTLY what I what, but I am now a bit baffled as to precisely why.  I have
> written a function to do a bit of webscraping by following links for a
> project at work.  If I leave the code as is, it behaves like it is
> recursively passing through the data tree- which is what I want.  However,
> if I change it only slightly, it makes only one pass through the top level
> data.  What I do not understand is why is ever behaves as if it is recursive
> as the function is only called once.
>
> If I comment out_list=[] and let out_list-=part_list be used the following
> parses through the whole tree of data as if recursive.  If I use out_list=[]
> and comment out_list=part_list, it only processes to top level of the data
> tree.
>
> The function is called only once as:  Exploded_BOM_List =
> get_BOM(first_num)  in which I pass it a single part number to start with.
> The webscraping bit goes to a particular webpage about that part where it
> then picks up more part numbers and repeats the process.
>
> So can anyone help me understand why this actually works?  Certainly no
> complaints here about it, but I would like to better understand why changes
> the behavior so profoundly.  All the print statements are just to I could
> follow out the data flow while working on this.  By following the data flow,
> I am finding that part_list is actually having values added to it during the
> time the function is running.   Problem is, I don't see clearly why that
> should be so.
>
> def get_BOM(part_list):
> x=re.compile('part='+'.*?'+'>')
> BOM_List = []
>
> #out_list = []
> out_list = part_list
> print("called get_BOM")
> pass_num = 0
> for part_num in part_list:
> mypath = "http://xxx.xxx.xxx.xxx/cgi-bin/search/part-url.cgi?part=";
> + part_num
> mylines = urllib.urlopen(mypath).readlines()
> print("pass number ", pass_num)
> print(mypath)
> print("PL:",part_list)
> for item in mylines:
> if "http://"; in item:
> if "part=" in item:
> xstring=str(x.findall(item)).strip('"[\'part=>\']"')
> BOM_List.append(xstring)
> print("BL:",BOM_List)
> for bom_item in BOM_List:
> if bom_item not in out_list:
> out_list.append(bom_item)
> print("OL:",out_list)
> pass_num += 1
> return(out_list)
>
>
>
>
>
>
>
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Bill Allen
Ok, I have definately verified this to myself.   The following works
perfectly and is a little easier to understand.  In this version, I am
plainly modifying my parts_list iterator thus producing the effect of an
iterator that is growing over the course of the operation of the code.  So,
I am convinced that I had previously assigned part_list to out_list by
reference, not value as I mistaken thought when I first wrote the code,
which explains it.  It was a silly mistake born from still being new in
Python and thinking in terms of another language I know that typically
assigns by value instead.  It had no occurred to me initially that it was
possible to modify an iterator in this way.  I do not think most languages
would allow this.

Question, is it possible to copy values from one object to another in such a
way as they are not just references one to the other?

Sorry about asking questions and then answering them.  Things began to
become more clear with each question I asked.


def get_BOM(part_list):
x=re.compile('part='+'.*?'+'>')
BOM_List = []

pass_num = 0
for part_num in part_list:
mypath = "http://172.25.8.13/cgi-bin/search/part-url.cgi?part="; +
part_num
mylines = urllib.urlopen(mypath).readlines()
for item in mylines:
if "http://"; in item:
if "part=" in item:
xstring=str(x.findall(item)).strip('"[\'part=>\']"')
BOM_List.append(xstring)
for bom_item in BOM_List:
if bom_item not in part_list:
part_list.append(bom_item)
pass_num += 1
return(part_list)









On Tue, Jan 25, 2011 at 00:05, Bill Allen  wrote:

> By the way, my guess as to why this is working for me the way it does is
> that the statement
>
> out_list = part_list
>
> is actually linking these two objects, making them one.   My intention had
> been to just assign values from one to the other, but I think I have done
> far more than that.   In this case, if that is true, then it has worked out
> well for me, giving me a feedback loop through the data.  However, I can see
> that it could also be a pitfall if this behavior is not clearly understood.
> Am I right?   Am I way off base?  Either way, I could use some elaboration
> about it.
>
>
> --Bill
>
>
>
>
>
>
> On Mon, Jan 24, 2011 at 23:56, Bill Allen  wrote:
>
>> This is a bit embarrassing, but I have crafted a bit of code that does
>> EXACTLY what I what, but I am now a bit baffled as to precisely why.  I have
>> written a function to do a bit of webscraping by following links for a
>> project at work.  If I leave the code as is, it behaves like it is
>> recursively passing through the data tree- which is what I want.  However,
>> if I change it only slightly, it makes only one pass through the top level
>> data.  What I do not understand is why is ever behaves as if it is recursive
>> as the function is only called once.
>>
>> If I comment out_list=[] and let out_list-=part_list be used the following
>> parses through the whole tree of data as if recursive.  If I use out_list=[]
>> and comment out_list=part_list, it only processes to top level of the data
>> tree.
>>
>> The function is called only once as:  Exploded_BOM_List =
>> get_BOM(first_num)  in which I pass it a single part number to start with.
>> The webscraping bit goes to a particular webpage about that part where it
>> then picks up more part numbers and repeats the process.
>>
>> So can anyone help me understand why this actually works?  Certainly no
>> complaints here about it, but I would like to better understand why changes
>> the behavior so profoundly.  All the print statements are just to I could
>> follow out the data flow while working on this.  By following the data flow,
>> I am finding that part_list is actually having values added to it during the
>> time the function is running.   Problem is, I don't see clearly why that
>> should be so.
>>
>> def get_BOM(part_list):
>> x=re.compile('part='+'.*?'+'>')
>> BOM_List = []
>>
>> #out_list = []
>> out_list = part_list
>> print("called get_BOM")
>> pass_num = 0
>> for part_num in part_list:
>> mypath = "
>> http://xxx.xxx.xxx.xxx/cgi-bin/search/part-url.cgi?part="; + part_num
>> mylines = urllib.urlopen(mypath).readlines()
>> print("pass number ", pass_num)
>> print(mypath)
>> print("PL:",part_list)
>> for item in mylines:
>> if "http://"; in item:
>> if "part=" in item:
>> xstring=str(x.findall(item)).strip('"[\'part=>\']"')
>> BOM_List.append(xstring)
>> print("BL:",BOM_List)
>> for bom_item in BOM_List:
>> if bom_item not in out_list:
>> out_list.append(bom_item)
>> print("OL:",out_list)
>> pass_num += 1
>> return(out_list)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
__

Re: [Tutor] Not understanding a bit of code behavior

2011-01-24 Thread Alan Gauld


"Bill Allen"  wrote

I am convinced that I had previously assigned part_list to out_list 
by
reference, not value as I mistaken thought when I first wrote the 
code,


In Python variables are names which refer to objects.
So your assignment made both names refer to the same object.

Question, is it possible to copy values from one object to another 
in such a

way as they are not just references one to the other?


If you want to copy a list the usual way is to create a new copy
using slicing:

newList = oldList[:]

You can also use the deepcopy module if the list is multi level.

Sorry about asking questions and then answering them.  Things began 
to

become more clear with each question I asked.


Thats often the way :-)
The act of articulating the problem forces you to think about it 
differently.


HTH

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Not understanding a bit of code behavior

2011-01-24 Thread David Hutto
On Tue, Jan 25, 2011 at 2:42 AM, Alan Gauld  wrote:
>
> "Bill Allen"  wrote
>
>> I am convinced that I had previously assigned part_list to out_list by
>> reference, not value as I mistaken thought when I first wrote the code,
>
> In Python variables are names which refer to objects.
> So your assignment made both names refer to the same object.
>
>> Question, is it possible to copy values from one object to another in such
>> a
>> way as they are not just references one to the other?
>
> If you want to copy a list the usual way is to create a new copy
> using slicing:
>
> newList = oldList[:]
>
> You can also use the deepcopy module if the list is multi level.
>
>> Sorry about asking questions and then answering them.  Things began to
>> become more clear with each question I asked.
>
> Thats often the way :-)
> The act of articulating the problem forces you to think about it
> differently.RTFM, before ask the list. No that they aren't helpful here, but 
> try on your own(and don't start off topic questions)

>
> HTH
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
The lawyer in me says argue...even if you're wrong. The scientist in
me... says shut up, listen, and then argue. But the lawyer won on
appeal, so now I have to argue due to a court order.

Furthermore, if you could be a scientific celebrity, would you want
einstein sitting around with you on saturday morning, while you're
sitting in your undies, watching Underdog?...Or better yet, would
Einstein want you to violate his Underdog time?

Can you imagine Einstein sitting around in his underware? Thinking
about the relativity between his pubic nardsac, and his Fruit of the
Looms, while knocking a few Dorito's crumbs off his inner brilliant
white thighs, and hailing E = mc**2, and licking the orangy,
delicious, Doritoey crust that layered his genetically rippled
fingertips?

But then again, J. Edgar Hoover would want his pantyhose intertwined
within the equation.

However, I digress, momentarily.

But Einstein gave freely, for humanity, not for gain, other than
personal freedom.

An equation that benefited all, and yet gain is a personal product.

Also, if you can answer it, is gravity anymore than interplanetary static cling?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor