[Tutor] Help
Good day, I am currently checking a piece of arcpy code. Where a point is shifted within a set distance to protect the privacy of said point. Please see the code below, and please advise me or correct the code where it is needed # Step 11 - SELECT By Attributes -> where FID == FID_1, export to new Feature Class # -- # Make a layer from the feature class arcpy.MakeFeatureLayer_management(in_features="RDiff_AreaIntersect_Dissolve", out_layer="lyr_eaten", where_clause="", workspace="", field_info= "OBJECTID OBJECTID VISIBLE NONE", "Shape Shape VISIBLE NONE", "ORIG_FID ORIG_FID VISIBLE NONE", "FIRST_Join_Count FIRST_Join_Count VISIBLE NONE" FIRST_OBJECTID_1 (VISIBLE NONE;FIRST_gps_latitu FIRST_gps_latitu VISIBLE NONE; FIRST_gps_longit; FIRST_gps_longit VISIBLE NONE;FIRST_OBJECTID FIRST_OBJECTID VISIBLE NONE; FIRST_R1 FIRST_R1 VISIBLE NONE;FIRST_ORIG_FID FIRST_ORIG_FID VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE; Shape_Area Shape_Area VISIBLE NONE) # SELECT by attribute arcpy.SelectLayerByAttribute_management(in_layer_or_view="lyr_eaten", selection_type="NEW_SELECTION", where_clause="FID_RDiffBuffer = ORIG_FID") # Write the selected features to a new featureclass arcpy.CopyFeatures_management(in_features="lyr_eaten",out_feature_class="C:/Users/Claudinho/Desktop/2016/ GIS_702/COPC_DATA/Altered_Data_sets/702.gdb/DonutFile", config_keyword="", spatial_grid_1="0", spatial_grid_2="0", spatial_grid_3="0") # -- # Step 12 - CreateRandomPoint constrained by DonutFile # -- arcpy.CreateRandomPoints_management(out_path="C:/Users/Claudinho/Desktop/2016/GIS_702/COPC_DATA/ Altered_Data_sets/702.gdb", out_name="RandomFile", constraining_feature_class="DonutFile", constraining_extent="0 0 250 250", number_of_points_or_field="1", minimum_allowed_distance="0 Meters", create_multipoint_output="POINT", multipoint_size="0") # JOIN RandomFile (CID) to DonutFile (OBJECTID) arcpy.JoinField_management(in_data="RandomFile", in_field="CID", join_table="DonutFile", join_field="OBJECTID", fields="") # DELETE unnecessary fields in RandomFile arcpy.DeleteField_management(in_table="RandomFile", drop_field="FIRST_OBJECTID_1;FIRST_FID_RDiffBuffer; FIRST_gps_latitu;FIRST_gps_longit;") Regards Adam ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
On 03/07/18 06:23, Adam Jones wrote: > Good day, I am currently checking a piece of arcpy code. Where a point is > shifted within a set distance to protect the privacy of said point. Please > see the code below, and please advise me or correct the code where it is > needed It would help us to help you if you explain what the problem is. Do you get an error message(if so include it). Is the data wrong (if so tell us what you expected and what you got) Do not assume we know much about arcpy, that's not part of standard Python, so you need to tell us what you are doing with it. > # Step 11 - SELECT By Attributes -> where FID == FID_1, export to new > Feature Class > # > -- > # Make a layer from the feature class > arcpy.MakeFeatureLayer_management(in_features="RDiff_AreaIntersect_Dissolve", > out_layer="lyr_eaten", > where_clause="", > workspace="", > field_info= "OBJECTID OBJECTID VISIBLE NONE", "Shape Shape VISIBLE NONE", > "ORIG_FID ORIG_FID VISIBLE NONE", "FIRST_Join_Count FIRST_Join_Count > VISIBLE NONE" > FIRST_OBJECTID_1 (VISIBLE NONE;FIRST_gps_latitu FIRST_gps_latitu VISIBLE > NONE; > FIRST_gps_longit; FIRST_gps_longit VISIBLE NONE;FIRST_OBJECTID > FIRST_OBJECTID VISIBLE NONE; > FIRST_R1 FIRST_R1 VISIBLE NONE;FIRST_ORIG_FID FIRST_ORIG_FID VISIBLE > NONE;Shape_Length Shape_Length VISIBLE NONE; > Shape_Area Shape_Area VISIBLE NONE) I would expect the above to give a syntax error because it doesn't look like valid Python. It starts out as a sequence of arguments but then semi colons start appearing in strange places amid a function call. And the parens don't seem to match either. All very odd. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need all values from while loop - only receiving one
On 02/07/18 23:52, Daryl Heppner wrote: > The two While Loops are the part I'm struggling with. The goal is to > list each bill month number and date for each month in the term. When you need multiple values you need to use a collection type such as a list or tuple. Your problem is that you are using single valued variables to collect data but as you go round the loops (not just the while loops) you are throwing away the data you have already collected so that when the loop ends you only have the last set of values. > this example, I'm trying to return 36 rows, listed from 1-36 instead > of one row followed by 24 rows numbered 37 to 60. Personally I'd create a dictionary per row and store those dictionaries in a list. (You could use a class instead of a dictionary but I'm guessing that might be too big a step for a beginner.) I'd also put all the parsing code into a function so that you pass it the raw xml and get back the row dictionary. That should simplify the structure of your code significantly and make it easier to see what's going on. It should also be easier to test the function on its own with some sample xml. If you need more help with that let us know. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] C++ or Python?
Hi, I have heard C++ is faster than python and I have a few questions 1.Is there a way to make python run just as fast 2.can I get in a serious game making team like 343 by using python 3. if C++ is better where can I get good 3d model libraries and libraries that make coding in C++ faster 4. Is there a way to transfer python files to C++ Thanks -- Bellamy iWYZE https://www.iwyze.co.za/products/car-insurance ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] C++ or Python?
Greetings -- Faster to do what? Develop faster? Run faster? Debug faster? In my experience, making the development and eventual debugging of programs as easy and quick as possible is very important. My experience and advice has been to design a clear algorithm, then program it in as clear and straightforward a manner as possible in a language that has good support. Test the program for correctness. After it works as hoped, test it for speed. Only then, and only if necessary, analyze, profile, and optimize the code for speed. Keep in mind that modifying the program to increase speed will make it less clear and will probably make it more difficult to maintain, even by its original programmer. That said, Python is much easier to code and to debug than C++ (I have considerable experience with both). When necessary, identify the portions of the program that are the bottleneck and optimize them in a step-by-step manner -- most constricting bottleneck first, then reevaluate, etc. That optimization may be as simple as replacing Python routines with Cython routines. http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html Best, Howard (50 years in computing, including commercial programming and university professor) On Tue, Jul 3, 2018 at 9:26 AM Bellamy Baron wrote: > Hi, > > I have heard C++ is faster than python and I have a few questions > 1.Is there a way to make python run just as fast > 2.can I get in a serious game making team like 343 by using python > 3. if C++ is better where can I get good 3d model libraries and libraries > that make coding in C++ faster > 4. Is there a way to transfer python files to C++ > > Thanks > > -- > > > Bellamy > iWYZE > https://www.iwyze.co.za/products/car-insurance > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] C++ or Python?
Howard is right. You will produce actual code doing actual stuff much faster with Python than with C++. There are ways to resolve performance bottlenecks but most people don't actually hit those sorts of issues. Leam On 07/03/2018 01:06 PM, Howard B wrote: Greetings -- Faster to do what? Develop faster? Run faster? Debug faster? In my experience, making the development and eventual debugging of programs as easy and quick as possible is very important. My experience and advice has been to design a clear algorithm, then program it in as clear and straightforward a manner as possible in a language that has good support. Test the program for correctness. After it works as hoped, test it for speed. Only then, and only if necessary, analyze, profile, and optimize the code for speed. Keep in mind that modifying the program to increase speed will make it less clear and will probably make it more difficult to maintain, even by its original programmer. That said, Python is much easier to code and to debug than C++ (I have considerable experience with both). When necessary, identify the portions of the program that are the bottleneck and optimize them in a step-by-step manner -- most constricting bottleneck first, then reevaluate, etc. That optimization may be as simple as replacing Python routines with Cython routines. http://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html Best, Howard (50 years in computing, including commercial programming and university professor) On Tue, Jul 3, 2018 at 9:26 AM Bellamy Baron wrote: Hi, I have heard C++ is faster than python and I have a few questions 1.Is there a way to make python run just as fast 2.can I get in a serious game making team like 343 by using python 3. if C++ is better where can I get good 3d model libraries and libraries that make coding in C++ faster 4. Is there a way to transfer python files to C++ Thanks -- Bellamy iWYZE https://www.iwyze.co.za/products/car-insurance ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] C++ or Python?
On 03/07/18 14:48, Bellamy Baron wrote: > I have heard C++ is faster than python and I have a few questions > 1.Is there a way to make python run just as fast Kind of. Nearly. But its limited to specific types of program. The most common approach is to identify the slow bits and rewrite them in C++ then expose that code to python as a library. You then call the C++ code from your Python program. That's how most of the core libraries are written. Most programs only need C++ speed for a tiny part of their functionality. Python is about speed of development not speed of execution. For most programming tasks modern computers mean that Python is fast enough. But games (or certain types of games) are one of the exceptions to that generalisation. > 2.can I get in a serious game making team like 343 by using python No idea, never even heard of them. But in general games programmers tend to favour C++. > 3. if C++ is better where can I get good 3d model libraries and libraries > that make coding in C++ faster You'd need to ask C++ programmers, and probably more specifically other games programmers. Gamers have very unique programming needs which is why many universities teach games programming as a separate course. The graphics libraries they use are likely to be different from the ones used by, for example, Adobe to create Photoshop... > 4. Is there a way to transfer python files to C++ If you mean convert then no, not directly. But projects like Cython allow you to write Python-like code that turns into C code eventually. Its very clever but not likely what you are looking for. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need all values from while loop - only receiving one
Again thank you so much! I truly appreciate your direction! The idea of a class is something I'd unsuccessfully tried but I'm up for the challenge! I'm very comfortable in Transact SQL but OOP is new to me. Here's my updated code with a sample XML. The full XML file is over 600K rows. I'd appreciate any feedback. Daryl import xml.etree.ElementTree as ET import pyodbc import dateutil.relativedelta as rd import dateutil.parser as pr from dateutil.rrule import rrule, MONTHLY tree = ET.parse(r'\\DealData.xml') root = tree.getroot() class BillDate: def __init__(self, begin, end): self.current = begin self.end = end def __iter__(self): return self def __next__(self): if self.current < self.end: billmo = self.current self.current += rd.relativedelta(months=1) return billmo else: raise StopIteration for deal in root.findall("Deals"): for dl in deal.findall("Deal"): dealid = dl.get("DealID") for dts in dl.findall("DealTerms/DealTerm"): dtid = dts.get("ID") dstart = pr.parse(dts.find("CommencementDate").text) dterm = int(dts.find("LeaseTerm").text) darea = dts.find("RentableArea").text for brrent in dts.findall("BaseRents/BaseRent"): brid = brrent.get("ID") begmo = int(brrent.find("BeginIn").text) if brrent.find("Duration").text is not None: duration = int(brrent.find("Duration").text) else: duration = 0 brentamt = brrent.find("Rent").text brper = brrent.find("Period").text perst = dstart + rd.relativedelta(months=begmo-1) perend = perst + rd.relativedelta(months=duration-1) months = [dt.strftime("%Y-%m-%d") for dt in rrule(MONTHLY, dtstart=perst, until=perend)] for billdt in BillDate(perst, perend): billdt if dealid == "706880": print(dealid, dtid, brid, begmo, dstart, dterm, darea, brentamt, brper, duration, perst, \ perend, billdt) c03528f241fdc8e4 12345_Place - Bldg 1 2015-10-28T04:09:07Z 2018-04-24T21:56:25Z SourceID 12345~12345 Calgary AB 1234 5 Ave S.W. T3P 0N7 Canada 800 11225 8 7 2016-04-20T13:47:13Z 2017-10-02T09:17:20Z SourceID 800 new 2017-12-20T22:36:21Z 2017-06-06T15:09:35Z dead_deal 0 2017-12-01 Office Tenant Name financial services 1013325 6000 7000 proposal 2017-06-06T15:09:35Z 2017-06-06T15:09:22Z 2017-06-06T15:09:22Z 2017-12-20 197 17699 Jessica Rabbit jessica.rab...@themovie.com dead_deal 2017-12-20T22:36:01Z 2017-12-20T22:36:01Z 2017-12-20T22:36:01Z 2017-12-20 0 24934 Leigh Vaughan leigh.vaug...@emails.com dead_deal 2017-12-20T22:36:21Z 2017-12-20T22:36:21Z 2017-12-20T22:36:21Z 169 price 24934 Leigh Vaughan leigh.vaug...@emails.com landlord 0.08 6200 triple net 60 2018-01-01 2017-06-06T15:16:23Z 20714.1144670763 2017-06-06 7.45 103367.15936951 640876388.09096 642137720.0 502200.0 64480.0 1 true 1 15.0 rsf/year 36 37 18.0 rsf/year 24 landlord Company1 2.9 rsf landlord Company2 7.5 rsf 186607 2017-06-06 ReimbursableExpenseCam 12.87 net 12.87 RealEstateTax 7.45 net 7.45 On Tue, Jul 3, 2018 at 3:42 AM Alan Gauld wrote: > > On 02/07/18 23:52, Daryl Heppner wrote: > > The two While Loops are the part I'm struggling with. The goal is to > > list each bill month number and date for each month in the term. > When you need multiple values you need to use a collection > type such as a list or tuple. Your problem is that you are using > single valued variables to collect data but as you go round the > loops (not just the while loops) you are throwing away the data > you have already collected so that when the loop ends you only > have the last set of values. > > > > this example, I'm trying to return 36 rows, listed from 1-36 instead > > of one row followed by 24 rows numbered 37 to 60. > > Personally I'd create a dictionary per row and store those > dictionaries in a list. (You could use a class instead of a dictionary > but I'm guessing that might be too big a step for a beginner.) > > I'd also put all the parsing code into a function so that you > pass it the raw xml and get back the row dictionary. > > That should simplify the structure of your code significantly > and make it easier to see what's going on. It should also be > easier to test the function on its own with some sample xml. > > If you need more help with that let us know. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail
Re: [Tutor] C++ or Python?
tir. 3. jul. 2018 18.25 skrev Bellamy Baron : > Hi, > > I have heard C++ is faster than python and I have a few questions > 1.Is there a way to make python run just as fast > Look Up cpython might be a bit faster 2.can I get in a serious game making team like 343 by using python > No > 3. if C++ is better where can I get good 3d model libraries and libraries > that make coding in C++ faster > Unity Maybe? > 4. Is there a way to transfer python files to C++ > What files? - they use different compilers.. > > Thanks > Np :) > -- > > > Bellamy > iWYZE > https://www.iwyze.co.za/products/car-insurance > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need all values from while loop - only receiving one
On 03/07/18 20:39, Daryl Heppner wrote: > The idea of a class is something I'd unsuccessfully tried but I'm up > for the challenge! I'm very comfortable in Transact SQL but OOP is > new to me. OK, What I meant by using a class was to define one (or more?) that encompassed all the data in one Deal. Then have the init method take a row of XML and populate all the fields. Something like this (Note this is not pretending to be correct, its just your own code reformed slightly): class DealTerm: def __init__(self,xml_dt): self.id = xml_dt.get("ID") self.start = pr.parse(dts.find("CommencementDate").text) self.term = int(xml_dt.find("LeaseTerm").text) self.area = xml_dt.find("RentableArea").text self.baseRents = [BaseRent(br) for br in xml_dt.findall("BaseRents/BaseRent")] class BaseRent: def __init__(self, xml_br): self.id = xml_br.get("ID") self.begmo = int(xml_br.find("BeginIn").text) if xml_br.find("Duration").text is not None: duration = int(xml_br.find("Duration").text) else: duration = 0 self.amt = xml_br.find("Rent").text self.per = xml_br.find("Period").text self.perst = dstart + rd.relativedelta(months=begmo-1) self.perend = perst + rd.relativedelta(months=duration-1) self.months = [dt.strftime("%Y-%m-%d") for dt in rrule(MONTHLY, dtstart=perst, until=perend)] class Deal: def __init__(self, dl): # use XT to parse the xml string self.id = dl.get("DealID") self.terms = [DealTerm(dts) for dts in dl.findall("DealTerms/DealTerm")] for billdt in BillDate(perst, perend): billdt def __str__(self): # returns string for print() etc ''' only uses first term value for convenience''' return self.id + terms[0].id + terms[0].baseRents[0].id + ... # The billdt line above makes no sense since it will do nothing. # Although in the >>> interpreter it would display the value # in a script it will do nothing. # I'm also not sure if the loop should be part of the # BaseRent or the DealTerm or the Deal. I suspect it # should be in BaseRent but I've left it where it was for now! # Now the main code just needs the outer loops: tree = ET.parse(r'\\DealData.xml') root = tree.getroot() deals = [] for deal in root.findall("Deals"): for dl in deal.findall("Deal"): deals.append( Deal(dl) ) if dl.id == "706880": print(dl) #uses __str__() to create string Hopefully you can see how, by putting the xml parsing into the classes that represent the actual real-world data objects that you are dealing with you simplify the logic of the higher level code and make it clearer what is being read and where? Notice also that in Deal I'm using a list to hold the DealTerms. And in DealTerm I use a list to hold the BaseRents. That way we don't just throw away the early values as your code currently does. You can extend this to cover the other data blocks in your XML if necessary, eg. Commission, Tenant, User etc. > Here's my updated code with a sample XML. The full XML > file is over 600K rows. > > I'd appreciate any feedback. > > Daryl > > import xml.etree.ElementTree as ET > import pyodbc > import dateutil.relativedelta as rd > import dateutil.parser as pr > from dateutil.rrule import rrule, MONTHLY > > tree = ET.parse(r'\\DealData.xml') > root = tree.getroot() > > class BillDate: > def __init__(self, begin, end): > self.current = begin > self.end = end > > def __iter__(self): > return self > > def __next__(self): > if self.current < self.end: > billmo = self.current > self.current += rd.relativedelta(months=1) > return billmo > else: > raise StopIteration Since this acts like a virtual collection you should probably call it BillDates - plural. Then the for loop reads more naturally as for date in BillDates(start, end): # do something with each date > > > for deal in root.findall("Deals"): > for dl in deal.findall("Deal"): > dealid = dl.get("DealID") > for dts in dl.findall("DealTerms/DealTerm"): > dtid = dts.get("ID") > dstart = pr.parse(dts.find("CommencementDate").text) > dterm = int(dts.find("LeaseTerm").text) > darea = dts.find("RentableArea").text > for brrent in dts.findall("BaseRents/BaseRent"): > brid = brrent.get("ID") > begmo = int(brrent.find("BeginIn").text) > if brrent.find("Duration").text is not None: > duration = int(brrent.find("Duration").text) > else: > duration = 0 > brentamt = brrent.find("Rent").text > brper = brrent.find("Period").text > perst = dstart + rd.relativedelta(months=begmo-
Re: [Tutor] Need all values from while loop - only receiving one
On 04/07/18 01:08, Alan Gauld via Tutor wrote: > # Now the main code just needs the outer loops: > tree = ET.parse(r'\\DealData.xml') > root = tree.getroot() > deals = [] > for deal in root.findall("Deals"): > for dl in deal.findall("Deal"): > deals.append( Deal(dl) ) > > if dl.id == "706880": >print(dl) #uses __str__() to create string Sorry, that last loop should be like this: for xml_dl in deal.findall("Deal"): theDeal = Deal(xml_dl) deals.append( theDeal ) if theDeal.id == "706880": print(theDeal) #uses __str__() to create string -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor