View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000459 | ascend | pygtk gui | public | 2010-05-21 10:57 | 2011-04-12 09:44 |
Reporter | john | ||||
Assigned To | |||||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | new | Resolution | open | ||
Product Version | |||||
Target Version | 1.0 | Fixed in Version | |||
Summary | 0000459: in Python, can't address range of array elements | ||||
Description | it would be useful to be able to assign values to a range of elements, eg M.a[1:5] = 5 or something like that. (Kelvin's suggestion) | ||||
Tags | No tags attached. | ||||
|
Overriding the __setslice__ method of a list object solves this one. I have uploaded a code to demonstrate this. Please verify that I have done it correctly. -- code -- class myList(list): def __setslice__(self, i, j, sequence): for x in range(i,j): self.__setitem__(x,sequence) a = myList('123456789'); a[1:4] = 5; -- code ends -- |
|
setslice.py (172 bytes) |
|
Please provide the modified code in the form of a patch for the ASCEND code (use "svn diff"). Be careful to think about what happens when the array indices are invalid (exception handling). |
|
I have made some changes to handle boundary cases and the new class now extends the original list object syntax instead of modifying it. I am uploading the file. But I feel it is better to use it in form of a separate file instead of modifying any existing python file. Please suggest a file in which I can ADD this new class and submit the changes as a patch. |
|
listExtend.py (713 bytes) |
|
The method for patches relating to new files is svn up # make your changes, including create a new file somedir/myfile.c svn add somedir/myfile.c svn diff > my.patch # if you had write access you could also then run # svn ci # to commit (check in) your changes. |
|
ujjaval-issue459.patch (1,547 bytes)
Index: ascend/system/system.c =================================================================== --- ascend/system/system.c (revision 3365) +++ ascend/system/system.c (working copy) @@ -88,12 +88,7 @@ slv_set_instance(sys,inst); #if DOTIME - comptime = tm_cpu_time() - comptime; - if(comptime >= 1e-3){ - CONSOLE_DEBUG("System built (time %5.3f s)",comptime); - }else{ - CONSOLE_DEBUG("System built (time <1ms)"); - } + FPRINTF(stderr,"Time to build system = %g s (outputs zero for build time < 1ms )\n", ((tm_cpu_time() - comptime)>=0.00001)?(tm_cpu_time()-comptime):0); #endif return(sys); } Index: pygtk/listExtend.py =================================================================== --- pygtk/listExtend.py (revision 0) +++ pygtk/listExtend.py (revision 0) @@ -0,0 +1,31 @@ +############################## +# Modified list class that enables assigning values to a range of elements +# Submited by : Ujjaval +# Addresses Issue 459 +############################## + +class myList(list): + def __setslice__(self, i, j, sequence): + if(isinstance(sequence,list)): + list.__setslice__(self, i, j, sequence) + else: + try: + for x in range(i,j): + self.__setitem__(x,sequence) + except: + print "Unexpected error:", sys.exc_info()[0] + +################################# +# SAMPLE USAGE : +# +# 1.Extended Syntax : +#a = myList('123456789'); +#print a; +#a[1:4] = 5; +#print a; +# 2.Original Syntax : +#b = myList('123456789'); +#print b; +#b[1:4] = [34,65]; +#print b; +################################# |
|
I have uploaded the new file as a patch. |
|
The attached code is not a patch at all... it is just an isolated code fragment. To fix this bug you need to incorporate the __setslice__ overloading into ASCEND's Python code. |
Date Modified | Username | Field | Change |
---|---|---|---|
2010-05-21 10:57 | john | New Issue | |
2011-02-22 17:34 | john | Target Version | => 1.0 |
2011-04-09 04:01 | ujjavalverma10 | Note Added: 0000718 | |
2011-04-09 04:13 | ujjavalverma10 | File Added: setslice.py | |
2011-04-09 04:14 | ujjavalverma10 | Note Edited: 0000718 | View Revisions |
2011-04-09 04:15 | ujjavalverma10 | Note Edited: 0000718 | View Revisions |
2011-04-09 13:28 | john | Note Added: 0000720 | |
2011-04-11 04:42 | ujjavalverma10 | Note Added: 0000724 | |
2011-04-11 04:43 | ujjavalverma10 | File Added: listExtend.py | |
2011-04-11 14:43 | john | Note Added: 0000725 | |
2011-04-12 06:02 | ujjavalverma10 | File Added: ujjaval-issue459.patch | |
2011-04-12 06:03 | ujjavalverma10 | Note Added: 0000731 | |
2011-04-12 09:44 | john | Note Added: 0000732 |