[Tutor] Need Help Modifying a wxPython GUI (scrolling display and logging)

Dave Angel davea at davea.name
Thu Jun 13 03:44:21 CEST 2013


On 06/12/2013 09:23 PM, Matt D wrote:
>
>> There are other ways a script might change the current directory.  For
>> example, some naive scripts use os.chdir()
>>
>> But how is it you don't know what the current directory was when the
>> code ran?   A simply pwd can tell you, if your prompt doesn't already
>> reveal it.
>>
>>
> hey i found the logfile.  just took a few minutes of looking round.  the
> file is logged all out of order

Do you have more than one thread?  Perhaps you have a race condition.

> so i have some work to do on that
> formatting issue.  if you have a sec can you take a look at my code please?
>
> def update(self, field_values):

>
>      	#  logger code---------------
>          #  first write the CURRENT date/time
> 		self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S", gmtime()))))

The return value of strftime is already a str, so why do you call str() 
on it?

> 		#  loop through each of the TextCtrl objects
> 		for k,v in self.fields.items():

items() returns an unordered list;  what order did you actually want?

>              #  get the value of the current TextCtrl field
> 			f = field_values.get(k, None)
> 			if f:
>                  #output the value with trailing comma
> 				self.logfile.write('%s,'%(str(f)))
> 				self.logfile.write('\n')

That looks like a newline, not a comma

> 		#end logger code ----------------
>
>          #if the field 'duid' == 'hdu', then clear all the fields
> 		if field_values['duid'] == 'hdu':
> 			self.clear()
> 		#loop through all TextCtrl fields storing the key/value pairs in k, v
> 		for k,v in self.fields.items():

Same ordering problem here.  If you have a specific order in mind, 
you'll need to preserve it in a list, not in a dict.

> 			# get the pickle value for this text control
> 			f = field_values.get(k, None)
> 			# if the value is empty then set the new value
> 			if f:
> 				v.SetValue(f)
>
>
> When i open the .csv file the fields are all out of order.  what i want
> is have them all in one row beginning with the date/time.  and idea?
> Thanks!
>
>

A dictionary is unsorted, so those two are probably your problem.  As I 
mentioned above, you can't count on the items() order.

Of course, self.items might not really be a dict.  This fragment doesn't 
prove that one way or another.


-- 
DaveA


More information about the Tutor mailing list