Re: [Tutor] Reading .csv data vs. reading an array
On 7/11/19 8:15 AM, Chip Wachob wrote: kinda restating what Oscar said, he came to the same conclusions, I'm just being a lot more wordy: > So, here's where it gets interesting. And, I'm presuming that someone out > there knows exactly what is going on and can help me get past this hurdle. Well, each snippet has some "magic" variables (from our point of view, since we don't see where they are set up): 1: if(voltage > (avg + triglevel) 2: if((voltage > triggervolts) since the value you're comparing voltage to gates when you decide there's a transition, and thus what gets added to the transition list you're building, and the list size comes out different, and you claim the data are the same, then guess where a process of elimination suggests the difference is coming from? === Stylistic comment, I know this wasn't your question. > for row in range (len(TrigWind)): Don't do this. It's not a coding error giving you wrong results, but it's not efficient and makes for harder to read code. You already have an iterable in TrigWind. You then find the size of the iterable and use that size to generate a range object, which you then iterate over, producing index values which you use to index into the original iterable. Why not skip all that? Just do for row in TrigWind: now row is actually a row, as the variable name suggests, rather than an index you use to go retrieve the row. Further, the "row" entries in TrigWind are lists (or tuples, or some other indexable iterable, we can't tell), which means you end up indexing into two things - into the "array" to get the row, then into the row to get the individual values. It's nicer if you unpack the rows into variables so they can have meaningful names - indeed you already do that with one of them. Lets you avoid code snips like "x[7][1]" Conceptually then, you can take this: for row in range(len(Trigwind)): voltage = float(TrigWind[row][1]) ... edgearray.append([float(TrigWind[row][0]), float(TrigWind[row][1])]) ... and change to this: for row in TrigWind: time, voltage = row # unpack edgearray.append([float)time, float(voltage)]) or even more compactly you can unpack directly at the top: for time, voltage in TrigWind: ... edgearray.append([float)time, float(voltage)]) ... Now I left an issue to resolve with conversion - voltage is not converted before its use in the not-shown comparisons. Does it need to be? every usage of the values from the individual rows here uses them immediately after converting them to float. It's usually better not to convert all over the place, and since the creation of TrigWind is under your own control, you should do that at the point the data enters the program - that is as TrigWind is created; then you just consume data from it in its intended form. But if not, just convert voltage before using, as your original code does. You don't then need to convert voltage a second time in the list append statements. for time, voltage in TrigWind: voltage = float(voltage) ... edgearray.append([float)time, voltage]) ... ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to store output of Python program in XML
On 13/07/2019 07:40, Asad wrote: > want to print the output of the script in a xml file so that I can add some > tags . How can it be done ? XML is just text dso you can just use the normal Python string operations to format an XML string with your data. However there are XML libraries aplenty that can aid you in constructing a valid XML tree structure. The standard library contains an xml package which includes the dom module which might be a good starting place if you want to understand the concepts. The etree module is probably easier to use in the long term though. Look at the "Building XML documents" section in the etree documentation. -- 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] Multiprocessing with many input input parameters
Right, I meant tuple, not list. a = ('A string') b = ('A List Member',) print(a[0]) print(b[0]) The output for this is: A A List Member @mike -Original Message- From: Cameron Simpson Sent: Friday, July 12, 2019 7:59 PM To: Mike Barnett Cc: Shall, Sydney ; tutor@python.org Subject: Re: [Tutor] Multiprocessing with many input input parameters On 11Jul2019 15:40, Mike Barnett wrote: >If you're passing parameters as a list, then you need a "," at the end of the >items. Otherwise if you have something like a string as the only item, the >list will be the string. > >list_with_one_item = ['item one',] Actually, this isn't true. This is a one element list, no trailing coma required: [5] Mike has probably confused this with tuples. Because tuples are delineated with parentheses, there is ambiguity between a tuple's parentheses and normal "group these terms together" parentheses. So: x = 5 + 4 * (9 + 7) Here we just have parentheses causing the assignment "9 + 7" to occur before the multiplication by 4. And this is also legal: x = 5 + 4 * (9) where the parentheses don't add anything special in terma of behaviour. Here is a 2 element tuple: (9, 7) How does one write a one element tuple? Like this: (9,) Here the trailing comma is _required_ to syntacticly indicate that we intend a 1 element tuple instead of a plain "9 in parentheses") as in the earlier assignment statement. I'm not sure any of this is relevant to Sydney's question though. Cheers, Cameron Simpson ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] How to store output of Python program in XML
Hi All , I written a python script which opens a logfile and searches for error and based or error found it prints a solution to screen , instead I want to print the output of the script in a xml file so that I can add some tags . How can it be done ? Thanks, -- Asad Hasan +91 9582111698 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor