Re: [Tutor] Fwd: Re: need help

2016-08-12 Thread Alan Gauld via Tutor

> -- Forwarded message --
> From: "Pallab Amway" 
>> Respected sir,lots of thanks for your advice,but while i am compiling
>> those programe with python 2.7 no output is coming only showing the
>> masage "expected indented block"

The first thing is to point out that you are getting an output - an
error message. Error messages are output.

The error tells you that it expects an indented block.
Do you understand what that means? Indentation refers
to the amount of spacing before the text. specifically
there must be more space before the lines after a control
statement (like your 'if') than there is on the control
line.

In most programming languages this is a matter of good
style to make the code easier for humans to read.
But it is a fundamental principle in python because
the compiler uses the spacing to figure out how much
code is influenced by the control statement.

So an if statement should look like:


if :
an indented line
another indented line
end of if block
elif  can you sugest any ebook?and please

I am biased but you can try my tutorial (see .sig below)
or there is a full page for beginners on the python.org
web site

https://www.python.org/about/gettingstarted/


-- 
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] Fwd: Re: need help

2016-08-12 Thread boB Stepp
Pallab, please reply to the Tutor list.

-- Forwarded message --
From: "Pallab Amway" 
Date: Aug 12, 2016 1:05 AM
Subject: Re: [Tutor] need help
To: "boB Stepp" 
Cc:

> Respected sir,lots of thanks for your advice,but while i am compiling
> those programe with python 2.7 no output is coming only showing the
> masage "expected indented block"can you sugest any ebook?and please
> sent me a expample with if & loop statement which i can compile on my
> python 2.7 .yours faithfuly pallab kumar seal
>
> On 8/12/16, boB Stepp  wrote:
> > On Aug 11, 2016 12:15 PM, "Pallab Amway"  wrote:
> >>
> >> Respected sir
> >>
> >>  Myself pallab kumar seal from India I am using
> > python2.7
> >> in my window 7 but while  I am using python to compile my program I am
> >> getting following  error
> >>
> >> Programe1
> >>
> >> age = 21
> >>
> >> if age < 12:
> >>
> >> print( "You ' re still a child!" )
> >>
> >> elif age < 18:
> >>
> >> print( "You are a teenager!" )
> >>
> >> elif age < 30:
> >>
> >> print( "You ' re pretty young!" )
> >>
> >> elif age < 50:
> >>
> >> print( "Wisening up, are we?" )
> >>
> >> else:
> >>
> >> print( "Aren ' t the years weighing heavy?" )
> >>
> >> answer
> >>
> >>
> >> expected an indented block
> >>
> >
> > Do you understand how Python uses consistent indentation to delineate
> > blocks of code?  If not, then you need to research this.
> >
> > Also, you say you're using Python 2.7.  Python 2.x uses print
*statements*
> > => no parentheses, while Python 3.x uses print *functions*.  Something
else
> > to read up on.
> >
> > Hope this gives you enough hints to work through your current problems!
> >
> > And I hope sending from my phone results in a plain text format!
> >
> > boB
> >
> > P.S.:. Do you have a good book or online tutorial to use?  If not, there
> > are plenty of such resources online.
> >
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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

2013-06-14 Thread Dave Angel

On 06/14/2013 03:59 PM, Matt D wrote:

On 06/14/2013 03:14 PM, Dave Angel wrote:

On 06/14/2013 10:48 AM, Matt D wrote:

Hey,
here is a snip of my code.

#logger code--
 #  first new line
 #self.logfile.write('\n')
 #  date and time
 #self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
gmtime()
 #  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is
what we want
 tmplist = []
 tmplist.append(str(strftime("%Y-%m-%d %H:%M:%S", localtime(
 tmplist.append(field_values["nac"])
 tmplist.append(field_values["tgid"])
 tmplist.append(field_values["source"])
 tmplist.append(field_values["dest"])
 tmplist.append(field_values["algid"])



tmplist is an unnecessary complication.  Did you look at my sample loop,
which I'll repeat here with a correction:


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

This code preserves your original feature of not crashing when the C++
program fails to fill in all your expected keys. It also makes sure
there will be unadorned commas for missing fields, making it possible
for a spreadsheet to read the columns correctly.

If you want to populate a list first, by all means do so, but do it in a
loop, using the FIELD_LIST_NAMES as keys.

One thing I didn't handle was the date field.  I'd do that by adding it
to the field_values dict, or to a copy of it. That way, it's all
consistent, even though one field comes from local and the rest from the
pickle.



yes acutally this templist business broke my code.  the TectCtrls in the
traffic panel would were not being populated and the logfile.csv was
empty.

So should i replace:

#logger code---
 #  first new line
 self.logfile.write('\n')
 #  date and time
 self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
localtime()
#  loop through each of the TextCtrl objects
 for k,v in self.fields.items():
 #  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))) 
#end logger code 

With the code you posted above?


Don't replace anything till you understand it.  But if you think you do 
then my code replaces the part starting at the for loop.


I am pretty sure that the reason i don't get the 'source' and 'dest'
fields is because of this:

#if the field 'duid' == 'hdu', then clear all the fields
 if field_values['duid'] == 'hdu':
 self.clear()

since the 'source' and 'dest' are in the LUD1 and not the HDU so it
doesn't update when the LDU1 comes through (if the LDU1) does actually
get serialized.


I don't know anything about LUDI or HDU.  But perhaps you're saying that 
some fields aren't in every pickle, but the value in the csv for each 
line should be the last one pickled.  In that case, you have a big logic 
flaw in your code.  When you output your stuff to the logfile, you use 
only the values in field_values, not any values previously stored in 
self.fields.  Do you perhaps mean that whenever a value is missing from 
the pickle, you want to use the one from self.fields?


If you happened to want exactly this, you could add the two middle lines 
as below.  something like:


  f = field_values.get(k, None)
  if f is None:   #add me
  f = self.fields.get(k, None)#add me
  if not f is None:

But clearly, that's much more specific than you've ever been.  There are 
also better ways to do it if that's exactly what you want.




 still haven't found a way to get to view the serialized
data.


print field_values, right at the beginning of update().  Or you could 
pretty it up, by looping through its items().




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


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

2013-06-14 Thread Matt D
On 06/14/2013 03:14 PM, Dave Angel wrote:
> On 06/14/2013 10:48 AM, Matt D wrote:
>> Hey,
>> here is a snip of my code.
>>
>> #logger code--
>> #  first new line
>> #self.logfile.write('\n')
>> #  date and time
>> #self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
>> gmtime()
>> #  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is
>> what we want
>> tmplist = []
>> tmplist.append(str(strftime("%Y-%m-%d %H:%M:%S", localtime(
>> tmplist.append(field_values["nac"])
>> tmplist.append(field_values["tgid"])
>> tmplist.append(field_values["source"])
>> tmplist.append(field_values["dest"])
>> tmplist.append(field_values["algid"])
>>
> 
> tmplist is an unnecessary complication.  Did you look at my sample loop,
> which I'll repeat here with a correction:
> 
> 
> for k in FIELD_LIST_NAMES:
> #  get the value of the current TextCtrl field
> f = field_values.get(k, None)
> if not f is None:
> #output the value with trailing comma
> self.logfile.write('%s,'%(str(f)))
> else:
> self.logfile.write(",")
> self.logfile.write("\n")
> 
> This code preserves your original feature of not crashing when the C++
> program fails to fill in all your expected keys. It also makes sure
> there will be unadorned commas for missing fields, making it possible
> for a spreadsheet to read the columns correctly.
> 
> If you want to populate a list first, by all means do so, but do it in a
> loop, using the FIELD_LIST_NAMES as keys.
> 
> One thing I didn't handle was the date field.  I'd do that by adding it
> to the field_values dict, or to a copy of it. That way, it's all
> consistent, even though one field comes from local and the rest from the
> pickle.
> 
> 
yes acutally this templist business broke my code.  the TectCtrls in the
traffic panel would were not being populated and the logfile.csv was
empty.

So should i replace:

#logger code---
#  first new line
self.logfile.write('\n')
#  date and time
self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
localtime()
#  loop through each of the TextCtrl objects
for k,v in self.fields.items():
#  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)))  
#end logger code 

With the code you posted above?

I am pretty sure that the reason i don't get the 'source' and 'dest'
fields is because of this:

#if the field 'duid' == 'hdu', then clear all the fields
if field_values['duid'] == 'hdu':
self.clear()

since the 'source' and 'dest' are in the LUD1 and not the HDU so it
doesn't update when the LDU1 comes through (if the LDU1) does actually
get serialized.  still haven't found a way to get to view the serialized
data.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-14 Thread Dave Angel

On 06/14/2013 10:48 AM, Matt D wrote:

Hey,
here is a snip of my code.

#logger code--
#  first new line
#self.logfile.write('\n')
#  date and time
#self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S", 
gmtime()
#  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is 
what we want
tmplist = []
tmplist.append(str(strftime("%Y-%m-%d %H:%M:%S", localtime(
tmplist.append(field_values["nac"])
tmplist.append(field_values["tgid"])
tmplist.append(field_values["source"])
tmplist.append(field_values["dest"])
tmplist.append(field_values["algid"])



tmplist is an unnecessary complication.  Did you look at my sample loop, 
which I'll repeat here with a correction:



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

This code preserves your original feature of not crashing when the C++ 
program fails to fill in all your expected keys. It also makes sure 
there will be unadorned commas for missing fields, making it possible 
for a spreadsheet to read the columns correctly.


If you want to populate a list first, by all means do so, but do it in a 
loop, using the FIELD_LIST_NAMES as keys.


One thing I didn't handle was the date field.  I'd do that by adding it 
to the field_values dict, or to a copy of it. That way, it's all 
consistent, even though one field comes from local and the rest from the 
pickle.








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


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

2013-06-14 Thread Alan Gauld

On 14/06/13 15:37, Matt D wrote:


There is a difference between where an error *occurs* and
where an error is *detected*.


got it. the error can be in the previous line.


Yeah, or more. I've seen errors that originated 3 or 4 lines back
from the reported location. So just remember that if you can't
spot it immediately start working backwards.


--
Alan G
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] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Matt D
Hey,
here is a snip of my code.

#logger code--
#  first new line
#self.logfile.write('\n')
#  date and time
#self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S", 
gmtime()
#  blah = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is 
what we want
tmplist = []
tmplist.append(str(strftime("%Y-%m-%d %H:%M:%S", localtime(
tmplist.append(field_values["nac"])
tmplist.append(field_values["tgid"])
tmplist.append(field_values["source"])
tmplist.append(field_values["dest"])
tmplist.append(field_values["algid"])

#this prints the current row of data to the terminal
#print tmplist

# this prints the current row of data to the csv file
for item in tmplist:
self.logfile.write('%s,' % (str(item)))
self.logfile.write('\n')


#  loop through each of the TextCtrl objects
#for k,v in self.fields.items():
#  get the value of the current TextCtrl field
   # f = field_values.get(k, None)
#if f:
# check if k is the field you want
#  output the value with trailing comma
#self.logfile.write('%s,'%(str(f)))
# self.logfile.write('\n') # here is where you would put it
#end logger code---

i know its ugly.  but there is two ways to log here.  one makes a list
(current) and the other (commented out) loops through the TextCtrls and
writes.  is their a better way than what i have here? the TextCtrl
fields get their values from a pickle.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-14 Thread Matt D
On 06/14/2013 10:27 AM, Alan Gauld wrote:
> On 14/06/13 14:27, Matt D wrote:
>> im sorry i dont get it.  there is too many brackets in this lin:
>>
>> tmplist.append(field_values["nac"])
>>
>> Thats where the error is
> 
> No, that's where Python *detected* that an error existed.
> The actual error is on the previous line. This is quite
> common, especially in cases of mismatched parens or quotes.
> 
> There is a difference between where an error *occurs* and
> where an error is *detected*.
> 
got it. the error can be in the previous line.  its running now.
Thanks guys!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-14 Thread Alan Gauld

On 14/06/13 14:27, Matt D wrote:

im sorry i dont get it.  there is too many brackets in this lin:

tmplist.append(field_values["nac"])

Thats where the error is


No, that's where Python *detected* that an error existed.
The actual error is on the previous line. This is quite
common, especially in cases of mismatched parens or quotes.

There is a difference between where an error *occurs* and
where an error is *detected*.

--
Alan G
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] Fwd: Re: Need Help Modifying a wxPython GUI (scrolling display and logging)

2013-06-14 Thread Steven D'Aprano

On 14/06/13 22:45, Matt D wrote:


 tmplist = []
 tmplist.append((str(strftime("%Y-%m-%d %H:%M:%S", localtime(
 tmplist.append(field_values["nac"])

[...]


When i run the code program dies like this:

 tmplist.append(field_values["nac"])
   ^
SyntaxError: invalid syntax

I cant figure why it stops on the third line above? Anyone have an idea?



When you get a syntax error, sometimes the actual problem occurs on the 
PREVIOUS line, but isn't detected until this line.

Go back to the previous line, the one containing strftime, and match up each 
pair of round brackets. How many Open brackets ( do you count? How many Close 
brackets ) do you count?


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


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

2013-06-14 Thread Don Jennings

On Jun 14, 2013, at 9:27 AM, Matt D wrote:

> im sorry i dont get it.  there is too many brackets in this lin:
> 
>   tmplist.append(field_values["nac"])
> 
> Thats where the error is but i dont see too many brackets?

Please don't top post.

The error is not on this line, but on the previous one. See below.
> 
> On 06/14/2013 08:56 AM, Flynn, Stephen (L & P - IT) wrote:
>> Not enough closing brackets on the previous line... or actually too many
>> opening brackets - you don't need all those that you have there already.
>> 
>> 
>>> #  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what
>> we
>>> want
>>>tmplist = []
>>>tmplist.append((str(strftime("%Y-%m-%d %H:%M:%S",
>> localtime(

Count the number of opening and closing parentheses. I count five opening ones, 
and only four closing. I believe the extraneous one is right before "str".

Take care,
Don

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


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

2013-06-14 Thread Matt D
im sorry i dont get it.  there is too many brackets in this lin:

tmplist.append(field_values["nac"])

Thats where the error is but i dont see too many brackets?

On 06/14/2013 08:56 AM, Flynn, Stephen (L & P - IT) wrote:
> Not enough closing brackets on the previous line... or actually too many
> opening brackets - you don't need all those that you have there already.
> 
> 
>> #  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what
> we
>> want
>> tmplist = []
>> tmplist.append((str(strftime("%Y-%m-%d %H:%M:%S",
> localtime(
>> tmplist.append(field_values["nac"])
>>  tmplist.append(field_values["tgid"])
>> tmplist.append(field_values["source"])
>> tmplist.append(field_values["dest"])
>> tmplist.append(field_values["algid"])
>>
>> When i run the code program dies like this:
>>
>> tmplist.append(field_values["nac"])
>>   ^
>> SyntaxError: invalid syntax
>>
>> I cant figure why it stops on the third line above? Anyone have an
> idea?
>> Thanks!
> 
> 
> This email and any attachment to it are confidential.  Unless you are the 
> intended recipient, you may not use, copy or disclose either the message or 
> any information contained in the message. If you are not the intended 
> recipient, you should delete this email and notify the sender immediately.
> 
> Any views or opinions expressed in this email are those of the sender only, 
> unless otherwise stated.  All copyright in any Capita material in this email 
> is reserved.
> 
> All emails, incoming and outgoing, may be recorded by Capita and monitored 
> for legitimate business purposes. 
> 
> Capita exclude all liability for any loss or damage arising or resulting from 
> the receipt, use or transmission of this email to the fullest extent 
> permitted by law.
> 

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


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

2013-06-14 Thread Matt D
i am trying to figure a way to to use a list to log/print my data:


#  tmplist = [time, 'nac', 'tgid', 'source', 'dest', 'algid'] is what we
want
tmplist = []
tmplist.append((str(strftime("%Y-%m-%d %H:%M:%S", localtime(
tmplist.append(field_values["nac"])
tmplist.append(field_values["tgid"])
tmplist.append(field_values["source"])
tmplist.append(field_values["dest"])
tmplist.append(field_values["algid"])

When i run the code program dies like this:

tmplist.append(field_values["nac"])
  ^
SyntaxError: invalid syntax

I cant figure why it stops on the third line above? Anyone have an idea?
Thanks!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-13 Thread Dave Angel

On 06/13/2013 12:32 PM, Matt D wrote:

On 06/13/2013 11:23 AM, Dave Angel wrote:

On 06/13/2013 10:37 AM, Matt D wrote:

On 06/13/2013 08:22 AM, Dave Angel wrote:

On 06/13/2013 12:18 AM, Matt D wrote:



 






Hey,
line 202: self.logfile.write('%s,'%(str(f))) d
does put the comma in properly but,
line 203: self.logfile.write('\n')
was putting the newline after each value like you said.
I moved this back outside of the if statement to see (i am still a
little unsure about the indention and i have to test) if it will create
a new row only when all the k,v values have been looped through.


Then put it AFTER the loop, not after the if.  It should line up with
the for statement.  And if you mix spaces with tabs, heaven help you.
Different people have different preferences, but I despise tabs in
source code.  Notice that you've done it at least four places:

 #output the value with trailing comma
 #if the field 'duid' == 'hdu', then clear all the fields
 return 0
 main()

If your editor let you do that, you aren't using the right settings on
the editor (or the right editor).  This didn't affect anything, since
indentation doesn't matter on comments, and the other two lines are
isolated indentations.




the ordering:  yes this is quite a hole in my understanding of what is
going on here.  the pickle is created in a collection of pretty
complicated C++ code that doesn't explicitly show how the pickle is
ordered or whats in it even in the pickle.cc and pickle.h files. the
pickle files take in some sort of stream, pickle the data, and send it
to a message queue that the trafficpanel waits on.  i need to log this
pickle or at at least dump it to terminal because i am pretty sure the
'source' and 'dest' fields (which currently are not available) are in
the pickle, albeit in a different data unit. I have read
"http://www.python.org/doc//current/library/pickle.html"; two times
already and still cant find a way to print the pickle in human readable
form.  my understanding of pickling stinks.  The ordering at this point
is not so important (not nearly as important as getting the 'source'
'dest' fields) because the point of the .csv file is just to import it
into librecalc and work time series analysis on the data manually.  at
some later point in the development maybe this this task can be
automated but for now just an unordered file will suffice.


If you want a consistent ordering, then add the line I described to your
own source code, at module scope.  Since you have no access to (control
over) the C++ code, you'll just have to make up your own list, as you've
already effectively done with your GUI.  For every field that is NOT in
the dict, you should be outputting a simple comma.

So your if test is wrong, since it will eat zeros as well as missing
values.  And you need an else clause:

 for k,v in FIELD_LIST_NAMES:
 #  get the value of the current TextCtrl field
 f = field_values.get(k, None)2013-06-12 16:28:59,Unknown (0x658),

DES-OFB,
HDU,
0xa4d5010ca0bbdb0900,
0xfff,
Standard MFID (pre-2001),
00x1,

 if not f is None:
 #output the value with trailing comma
 self.logfile.write('%s,'%(str(f)))
 else:
 self.logfile.write(",")
 self.logfile.write("\n")

And don't forget to add in the header line to your csv file, naming the
fields that are to be used in every line.


as of now the order in the .csv file is like this:

2013-06-12 16:28:59,Unknown (0x658),
00x80,
$80 Clear,
0xa4d5010ca0bbdb0900,
0xfff,
Standard MFID (pre-2001),
00x1,

and keeps repeating this order as long as HUDs are coming in.  i am
unsure why the date/time is on the same line as NAC?


Because you don't have a bogus newline after the date/time, but do after 
all the other fields.


  Oh and i have not

tested yet with the '\n' newline command out of the if statement.  If i
have to i can modify the C++ code but was hoping not to have to do that
at this stage.  the C++ is used for what is computationally intense and
the Python is used mainly for the UI.  Any idea of a way to write the
pickle to file to see what it contains? because it is not explicit in
the C++ files, at least not as far as I can tell as of yet.
Thanks!



I don't see any need to modify the C++ sources.

I don't know how to examine a pickle, file or otherwise.  You can, 
however, trivially print out all the keys (and values even) in 
field_values, for each record, and make sure they match your 
FIELD_LIST_NAMES, other than for order. Perhaps they named source and 
dest as Source and dESt, respectively, or src and dst, or whatever.


If you really want the pickle as a file, you could write pickled_dict to 
a separate file.  Just be sure to create that file as binary, since 
(some ?) pickle formats are not text.




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or ch

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

2013-06-13 Thread Matt D
On 06/13/2013 11:23 AM, Dave Angel wrote:
> On 06/13/2013 10:37 AM, Matt D wrote:
>> On 06/13/2013 08:22 AM, Dave Angel wrote:
>>> On 06/13/2013 12:18 AM, Matt D wrote:


 
>
>
>>>
>> Hey,
>> line 202: self.logfile.write('%s,'%(str(f))) d
>> does put the comma in properly but,
>> line 203: self.logfile.write('\n')
>> was putting the newline after each value like you said.
>> I moved this back outside of the if statement to see (i am still a
>> little unsure about the indention and i have to test) if it will create
>> a new row only when all the k,v values have been looped through.
> 
> Then put it AFTER the loop, not after the if.  It should line up with
> the for statement.  And if you mix spaces with tabs, heaven help you.
> Different people have different preferences, but I despise tabs in
> source code.  Notice that you've done it at least four places:
> 
> #output the value with trailing comma
> #if the field 'duid' == 'hdu', then clear all the fields
> return 0
> main()
> 
> If your editor let you do that, you aren't using the right settings on
> the editor (or the right editor).  This didn't affect anything, since
> indentation doesn't matter on comments, and the other two lines are
> isolated indentations.
> 
> 
>>
>> the ordering:  yes this is quite a hole in my understanding of what is
>> going on here.  the pickle is created in a collection of pretty
>> complicated C++ code that doesn't explicitly show how the pickle is
>> ordered or whats in it even in the pickle.cc and pickle.h files. the
>> pickle files take in some sort of stream, pickle the data, and send it
>> to a message queue that the trafficpanel waits on.  i need to log this
>> pickle or at at least dump it to terminal because i am pretty sure the
>> 'source' and 'dest' fields (which currently are not available) are in
>> the pickle, albeit in a different data unit. I have read
>> "http://www.python.org/doc//current/library/pickle.html"; two times
>> already and still cant find a way to print the pickle in human readable
>> form.  my understanding of pickling stinks.  The ordering at this point
>> is not so important (not nearly as important as getting the 'source'
>> 'dest' fields) because the point of the .csv file is just to import it
>> into librecalc and work time series analysis on the data manually.  at
>> some later point in the development maybe this this task can be
>> automated but for now just an unordered file will suffice.
> 
> If you want a consistent ordering, then add the line I described to your
> own source code, at module scope.  Since you have no access to (control
> over) the C++ code, you'll just have to make up your own list, as you've
> already effectively done with your GUI.  For every field that is NOT in
> the dict, you should be outputting a simple comma.
> 
> So your if test is wrong, since it will eat zeros as well as missing
> values.  And you need an else clause:
> 
> for k,v in FIELD_LIST_NAMES:
> #  get the value of the current TextCtrl field
> f = field_values.get(k, None)2013-06-12 16:28:59,Unknown (0x658),
DES-OFB,
HDU,
0xa4d5010ca0bbdb0900,
0xfff,
Standard MFID (pre-2001),
00x1,
> if not f is None:
> #output the value with trailing comma
> self.logfile.write('%s,'%(str(f)))
> else:
> self.logfile.write(",")
> self.logfile.write("\n")
> 
> And don't forget to add in the header line to your csv file, naming the
> fields that are to be used in every line.
> 
as of now the order in the .csv file is like this:

2013-06-12 16:28:59,Unknown (0x658),
00x80,
$80 Clear,
0xa4d5010ca0bbdb0900,
0xfff,
Standard MFID (pre-2001),
00x1,

and keeps repeating this order as long as HUDs are coming in.  i am
unsure why the date/time is on the same line as NAC?  Oh and i have not
tested yet with the '\n' newline command out of the if statement.  If i
have to i can modify the C++ code but was hoping not to have to do that
at this stage.  the C++ is used for what is computationally intense and
the Python is used mainly for the UI.  Any idea of a way to write the
pickle to file to see what it contains? because it is not explicit in
the C++ files, at least not as far as I can tell as of yet.
Thanks!

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


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

2013-06-13 Thread Dave Angel

On 06/13/2013 10:37 AM, Matt D wrote:

On 06/13/2013 08:22 AM, Dave Angel wrote:

On 06/13/2013 12:18 AM, Matt D wrote:










Hey,
line 202: self.logfile.write('%s,'%(str(f))) d
does put the comma in properly but,
line 203: self.logfile.write('\n')
was putting the newline after each value like you said.
I moved this back outside of the if statement to see (i am still a
little unsure about the indention and i have to test) if it will create
a new row only when all the k,v values have been looped through.


Then put it AFTER the loop, not after the if.  It should line up with 
the for statement.  And if you mix spaces with tabs, heaven help you. 
Different people have different preferences, but I despise tabs in 
source code.  Notice that you've done it at least four places:


#output the value with trailing comma
#if the field 'duid' == 'hdu', then clear all the fields
return 0
main()

If your editor let you do that, you aren't using the right settings on 
the editor (or the right editor).  This didn't affect anything, since 
indentation doesn't matter on comments, and the other two lines are 
isolated indentations.





the ordering:  yes this is quite a hole in my understanding of what is
going on here.  the pickle is created in a collection of pretty
complicated C++ code that doesn't explicitly show how the pickle is
ordered or whats in it even in the pickle.cc and pickle.h files. the
pickle files take in some sort of stream, pickle the data, and send it
to a message queue that the trafficpanel waits on.  i need to log this
pickle or at at least dump it to terminal because i am pretty sure the
'source' and 'dest' fields (which currently are not available) are in
the pickle, albeit in a different data unit. I have read
"http://www.python.org/doc//current/library/pickle.html"; two times
already and still cant find a way to print the pickle in human readable
form.  my understanding of pickling stinks.  The ordering at this point
is not so important (not nearly as important as getting the 'source'
'dest' fields) because the point of the .csv file is just to import it
into librecalc and work time series analysis on the data manually.  at
some later point in the development maybe this this task can be
automated but for now just an unordered file will suffice.


If you want a consistent ordering, then add the line I described to your 
own source code, at module scope.  Since you have no access to (control 
over) the C++ code, you'll just have to make up your own list, as you've 
already effectively done with your GUI.  For every field that is NOT in 
the dict, you should be outputting a simple comma.


So your if test is wrong, since it will eat zeros as well as missing 
values.  And you need an else clause:


for k,v in FIELD_LIST_NAMES:
#  get the value of the current TextCtrl field
f = field_values.get(k, None)
if not f is None:
#output the value with trailing comma
self.logfile.write('%s,'%(str(f)))
else:
self.logfile.write(",")
self.logfile.write("\n")

And don't forget to add in the header line to your csv file, naming the 
fields that are to be used in every line.


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


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

2013-06-13 Thread Matt D
On 06/13/2013 08:22 AM, Dave Angel wrote:
> On 06/13/2013 12:18 AM, Matt D wrote:
>>
>>
>>
>>>
>>>
>> yes the .py file has TextCtrl fields that get there values from a
>> pickled dictionary.  Another peice of the code watches a thread for the
>> pickle.  this is why i didnt use a list.  I have been unable to find a
>> nice way to just make a list with the items i need.  would be nice to
>> have that simplicity.
>> What you said is true, the the list is unordered.  More importantly the
>> new line comes in at the wrong point.  I want all the values in a row
>> starting with time.  from there i will look for a way to remove some
>> unwanted items and ordering the others.
>> I attached the .py file for you to see the whole thing hoping this is
>> not too presumptuous.  Thanks.
>>
>>
> 
> I don't mind the attached source file.  Note that some readers may not
> be able to see it (attachments aren't guaranteed to survive), and others
> might find it excessive in length.  But I'm fine with it.
> 
> I notice you didn't change the newline to a comma, in the place that I
> commented earlier.  You explicitly separate the fields with newlines,
> while commenting that it's done with commas.
> 
> What you presumably want is to change the line inside the loop
> 
> self.logfile.write('\n')
> to
> self.logfile.write(',')
> 
> and add one of the former lines outside the loop, after writing the last
> field.
> 
> About the ordering:  Do you have a specific ordering in mind?  Who
> decides it?  The program that creates the pickle?  How tightly bound are
> the two?  Is there a 3rd program that's going to read the csv file?  Are
> all of these programs written in Python?  Will there be multiple
> versions, over time?
> 
> If all of these programs have to share the same definition for the csv
> file, then at least some of it should be in common code.  Simplest is to
> have the list/tuple of field names as a real list, defined in a module
> that they all import.  Then, instead of using self.fields.items(), you
> use something like common.FIELD_LIST_NAMES
> 
> common.py might have a line something like:
> 
> #define the tuple of names that will be used for the csv file
> FIELD_LIST_NAMES = ("date", "duid", "nac", "source", "dest", "mfid",
> "algid", "kid", "mi", "tgid")
> 
> Notice that TrafficPanel.init() might well collapse into a loop, if you
> add just a little more information into common.py  Then you'd find that
> editing the one place adds a new field, both to the csv file but also to
> the gui.
> 
> However, then if you add a new field, or remove one, you're obsoleting
> any csv files that may still be lying around, with no way to detect
> which ones are new and which ones are old.  Typically this is managed
> with a version field in the first line of the file.
> 
> But another, more standard, way to manage this is to make it a real csv
> file, with the field names in the first line (also comma separated).
> Python has a csv module, which solves another potential problem your
> logic may have:  what happens if any of those values has a comma in it?
> 
> 
> I know I only hinted at the possible implementations, but until you make
> some architectural choices clear, I really cannot add much more.
> 
> Here are some other remarks about the code:
> 
> line 53:  method Clone() should be lowercase, per Pep8.  I don't believe
> it does anything useful, but you don't call it anyway.
> 
> line 76:  deleting a local just before a method returns does exactly
> nothing.  When the method ends, the local will go out of scope, and the
> effect in either case is to decrement the refcount for the created
> DataEvent instance.
> 
> Incidentally, if you happen to be using Thunderbird, you might look for
> the Reply-List button.
> 
Hey,
line 202: self.logfile.write('%s,'%(str(f))) d
does put the comma in properly but,
line 203: self.logfile.write('\n')
was putting the newline after each value like you said.
I moved this back outside of the if statement to see (i am still a
little unsure about the indention and i have to test) if it will create
a new row only when all the k,v values have been looped through.

the ordering:  yes this is quite a hole in my understanding of what is
going on here.  the pickle is created in a collection of pretty
complicated C++ code that doesn't explicitly show how the pickle is
ordered or whats in it even in the pickle.cc and pickle.h files. the
pickle files take in some sort of stream, pickle the data, and send it
to a message queue that the trafficpanel waits on.  i need to log this
pickle or at at least dump it to terminal because i am pretty sure the
'source' and 'dest' fields (which currently are not available) are in
the pickle, albeit in a different data unit. I have read
"http://www.python.org/doc//current/library/pickle.html"; two times
already and still cant find a way to print the pickle in human readable
form.  my understanding of pickling stinks.  The ordering at this point
is not so impor

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

2013-06-13 Thread Dave Angel

On 06/13/2013 12:18 AM, Matt D wrote:



   




yes the .py file has TextCtrl fields that get there values from a
pickled dictionary.  Another peice of the code watches a thread for the
pickle.  this is why i didnt use a list.  I have been unable to find a
nice way to just make a list with the items i need.  would be nice to
have that simplicity.
What you said is true, the the list is unordered.  More importantly the
new line comes in at the wrong point.  I want all the values in a row
starting with time.  from there i will look for a way to remove some
unwanted items and ordering the others.
I attached the .py file for you to see the whole thing hoping this is
not too presumptuous.  Thanks.




I don't mind the attached source file.  Note that some readers may not 
be able to see it (attachments aren't guaranteed to survive), and others 
might find it excessive in length.  But I'm fine with it.


I notice you didn't change the newline to a comma, in the place that I 
commented earlier.  You explicitly separate the fields with newlines, 
while commenting that it's done with commas.


What you presumably want is to change the line inside the loop

self.logfile.write('\n')
to
self.logfile.write(',')

and add one of the former lines outside the loop, after writing the last 
field.


About the ordering:  Do you have a specific ordering in mind?  Who 
decides it?  The program that creates the pickle?  How tightly bound are 
the two?  Is there a 3rd program that's going to read the csv file?  Are 
all of these programs written in Python?  Will there be multiple 
versions, over time?


If all of these programs have to share the same definition for the csv 
file, then at least some of it should be in common code.  Simplest is to 
have the list/tuple of field names as a real list, defined in a module 
that they all import.  Then, instead of using self.fields.items(), you 
use something like common.FIELD_LIST_NAMES


common.py might have a line something like:

#define the tuple of names that will be used for the csv file
FIELD_LIST_NAMES = ("date", "duid", "nac", "source", "dest", "mfid", 
"algid", "kid", "mi", "tgid")


Notice that TrafficPanel.init() might well collapse into a loop, if you 
add just a little more information into common.py  Then you'd find that 
editing the one place adds a new field, both to the csv file but also to 
the gui.


However, then if you add a new field, or remove one, you're obsoleting 
any csv files that may still be lying around, with no way to detect 
which ones are new and which ones are old.  Typically this is managed 
with a version field in the first line of the file.


But another, more standard, way to manage this is to make it a real csv 
file, with the field names in the first line (also comma separated). 
Python has a csv module, which solves another potential problem your 
logic may have:  what happens if any of those values has a comma in it?



I know I only hinted at the possible implementations, but until you make 
some architectural choices clear, I really cannot add much more.


Here are some other remarks about the code:

line 53:  method Clone() should be lowercase, per Pep8.  I don't believe 
it does anything useful, but you don't call it anyway.


line 76:  deleting a local just before a method returns does exactly 
nothing.  When the method ends, the local will go out of scope, and the 
effect in either case is to decrement the refcount for the created 
DataEvent instance.


Incidentally, if you happen to be using Thunderbird, you might look for 
the Reply-List button.



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


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

2013-06-12 Thread Matt D



 Original Message 
Subject: Re: [Tutor] Need Help Modifying a wxPython GUI (scrolling
display and logging)
Date: Thu, 13 Jun 2013 00:17:44 -0400
From: Matt D 
To: Dave Angel 

On 06/12/2013 09:44 PM, Dave Angel wrote:
> 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.
> 
> 
yes the .py file has TextCtrl fields that get there values from a
pickled dictionary.  Another peice of the code watches a thread for the
pickle.  this is why i didnt use a list.  I have been unable to find a
nice way to just make a list with the items i need.  would be nice to
have that simplicity.
What you said is true, the the list is unordered.  More importantly the
new line comes in at the wrong point.  I want all the values in a row
starting with time.  from there i will look for a way to remove some
unwanted items and ordering the others.
I attached the .py file for you to see the whole thing hoping this is
not too presumptuous.  Thanks.



#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  op25_traffic_panel.py
#  
#  Copyright 2013 Balint Seeber 
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  

#  the import statements; very similar to #include in c++ 
#  this is the stuff for getting the current time
from time import gmtime, strftime
import wx
import cPickle as pickle
import gnuradio.gr.gr_threading as _threading

#  wx is the gui class. it implements a version of "events" -- objects that sit and wait for some data to change, and call a specified function when the change happens
wxDATA_EVENT = wx.NewEventType()

# this is a function that *sets* what happens when the event is triggered. it takes in an event (win) and a function (func) (and yes, functions can be passed around just like any other variable in python).
def EVT_DATA_EVENT(win, func):
win.Connect(-1, -1, wxDATA_E