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

2013-06-12 Thread Matt D
On 06/12/2013 09:54 PM, Dave Angel wrote:
> On 06/12/2013 09:14 PM, Matt D wrote:
>> On 06/12/2013 09:02 PM, Dave Angel wrote:
>>> On 06/12/2013 08:46 PM, Matt D wrote:
 On 06/12/2013 05:59 PM, Dave Angel wrote:
> On 06/12/2013 05:32 PM, Matt D wrote:
>>>
>>>
>>>  
>> Hey,
>> if i put:
>>
>> self.logfile = open('logfile.csv', 'w')
>>
>> in the .py file, within the 'class TrafficPane', then shouldn't
>> logfile.csv be written to the directory the .py file is in?  because
>> its
>> not there after running the program?  Where should i look for it?
>> Thanks
>> Matt
>>
>
> It should put it in the current directory.  That *may* be the
> directory
> the script is in, but not necessarily.  It's easy to run something
> like:
>
> python somdir/myscript.py
>
> in which case the file would be in the parent directory to myscript.py
>
> Note that in some environments, the current directory is invisibly set
> to some convenient place.  For example, when right-clicking on a
> script
> in Windows Explorer, they make the bald assumption that you want to
> set
> the current directory the same as the location of the script. That's
> about the worse place for it, but nevermind.
>
>
>
 Yes, that was my assumption (even thought I am using linux); and right
 again, it is a very inconvenient place for it to be.  however in the
 interest of speed of testing i figured i would make sure the log was
 logging the way i want it to and then try to find some sort of wx wigit
 to let the user of the gui name/save to desired location. meanwhile . .
 . so you think it saved somewhere right?
>>>
>>> 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.
>>>
>>>
>> i was assuming the file would write to where the .py file is located.
>> of course i know where that is because i put the file there but the
>> logfile.csv is not in there. i did a search in the file system and
>> nothing so i don't know what is going on here?  guess keep looking?  its
>> gota be here somewhere? no?
>>
> 
> So is somebody else running your program?  As I said before, how can you
> NOT know what your current directory (cwd) is when you ran the script?
> And again, the location of the script is irrelevant.
> 
> No more offlist messages.  This is a public forum, and I don't do private.
> 
> DaveA
> 
> 
please pardon mailing you only.  when i press reply your email and not
the list's email comes in.  listen; i run another program in terminal in
home directory; that program uses the .py file in the python directory.
I already told you i found the file?  why would someone else be running
the program?
___
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

[Tutor] Any speech to text conversation python library for Linux and mac box

2013-06-12 Thread Ranjith Kumar
Hello all,
I'm looking for speech to text conversation python library for linux and
mac box, I found few libraries but non of them supports any of these
platform.
I found following libraries speech, dragonfly and pyspeech supports only
windows and sphinx for linux.

Any suggestion?

-- 
Cheers,
Ranjith Kumar K,
Chennai.

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


Re: [Tutor] Value Error

2013-06-12 Thread Jim Mooney
On 12 June 2013 17:08, Marc Tompkins  wrote:

> On Wed, Jun 12, 2013 at 3:31 PM, Dave Angel  wrote:
>
>> >>> cmath.sqrt(float((math.e **(i * math.pi)).real))
>> 1j
>>
> Sh*t just got real.
>


I give up. When I got to Complex Analysis I decided to enlist instead. And
that was during Vietnam ;')

Jim
A noun is just a verb with the hiccups
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-12 Thread Dave Angel

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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-12 Thread Matt D

> 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 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()
#  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)))
self.logfile.write('\n')
#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():
# 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!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-12 Thread Dave Angel

On 06/12/2013 08:46 PM, Matt D wrote:

On 06/12/2013 05:59 PM, Dave Angel wrote:

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





Hey,
if i put:

   self.logfile = open('logfile.csv', 'w')

in the .py file, within the 'class TrafficPane', then shouldn't
logfile.csv be written to the directory the .py file is in?  because its
not there after running the program?  Where should i look for it?
Thanks
Matt



It should put it in the current directory.  That *may* be the directory
the script is in, but not necessarily.  It's easy to run something like:

python somdir/myscript.py

in which case the file would be in the parent directory to myscript.py

Note that in some environments, the current directory is invisibly set
to some convenient place.  For example, when right-clicking on a script
in Windows Explorer, they make the bald assumption that you want to set
the current directory the same as the location of the script. That's
about the worse place for it, but nevermind.




Yes, that was my assumption (even thought I am using linux); and right
again, it is a very inconvenient place for it to be.  however in the
interest of speed of testing i figured i would make sure the log was
logging the way i want it to and then try to find some sort of wx wigit
to let the user of the gui name/save to desired location. meanwhile . .
. so you think it saved somewhere right?


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.



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


[Tutor] hello.

2013-06-12 Thread Lolo Lolo
http://pictmania.com/tez.php___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2013-06-12 Thread Matt D
On 06/12/2013 05:59 PM, Dave Angel wrote:
> On 06/12/2013 05:32 PM, Matt D wrote:
>> On 06/10/2013 12:23 PM, Prasad, Ramit wrote:
>>> Matt D wrote:
 Ramit Prasad wrote:
>>> Scrolled panel is just a graphical container that allows for
>>> scrolling inside,
>>> but it is the window that scrolls not widgets inside it. This of
>>> it like
>>> a webpage that scrolls. If you use web email the text widget in the
>>> email needs to scroll so you can see your full email context and not
>>> just scroll the page.
>>>
>>> You will probably need to create a TextCtrl with the appropriate
>>> style
>>> and append your new data. I have given an example below that should
>>> automatically scroll with your new data.
>>>
>>> #in __init__
>>> self.scrolling_widget = wx.TextCtrl( self, wx.ID_ANY, '',
>>> size=(-1, 275),
>> style=wx.TE_AUTO_SCROLL|wx.TE_READONLY|wx.TE_PROCESS_ENTER|wx.TE_WORDWRAP|wx.TE_MULTILINE
>> )
>>>
 Hey,
 I added this the above 3 lines of code to my file and ran it.  the box
 shows up on the far left, mostly of the pane, to the left of the
 current
 text feilds.  I am having trouble positioning this textbox under where
 the current text fields are.
 I am not sure but maybe this sets up the grid on the pane:
 sizer = wx.GridBagSizer(hgap=10, vgap=10)
  self.fields = {}
 all the current TextCtrl fields are positioned at (1,1) through (5,5).
 I tried adding:
 sizer.Add(field, pos=(1,6))
 but it did not move the box to the position?
>>>
>>> Just to make sure, you did call it field and not self.scrolling_widget
>>> (which was in my example)?
>>>
>>> Odd that they don't start at (0,0) when adding to the bag. This is
>>> more a wxpython question and their mailing list might prove more
>>> useful. I could figure it out, but I cannot run the app. Trial
>>> and error here will probably help you the most. You can also
>>> try looking at a different sizer (like BoxSizer and GridSizer).
>>>
>>> Personally, I think BoxSizer is the most intuitive as it matches
>>> my thought process. You just set an orientation (vertical/horizontal)
>>> and add widgets to it. To get something in the other direction, you
>>> create another box sizer with the opposite orientation, add widgets
>>> to that sizer, and then add the new sizer to the original sizer. Not
>>> nearly as pretty as grid/grid bag though (by default), but super simple.
>>>
>>> BoxSizer API
>>> http://wxpython.org/docs/api/wx.BoxSizer-class.html
>>> Some other sizers are listed here:
>>> http://wxpython.org/docs/api/wx.Sizer-class.html
>>>

 THanks,
 Matt
>>>
>>>
>> Hey,
>> if i put:
>>
>>   self.logfile = open('logfile.csv', 'w')
>>
>> in the .py file, within the 'class TrafficPane', then shouldn't
>> logfile.csv be written to the directory the .py file is in?  because its
>> not there after running the program?  Where should i look for it?
>> Thanks
>> Matt
>>
> 
> It should put it in the current directory.  That *may* be the directory
> the script is in, but not necessarily.  It's easy to run something like:
> 
> python somdir/myscript.py
> 
> in which case the file would be in the parent directory to myscript.py
> 
> Note that in some environments, the current directory is invisibly set
> to some convenient place.  For example, when right-clicking on a script
> in Windows Explorer, they make the bald assumption that you want to set
> the current directory the same as the location of the script. That's
> about the worse place for it, but nevermind.
> 
> 
> 
Yes, that was my assumption (even thought I am using linux); and right
again, it is a very inconvenient place for it to be.  however in the
interest of speed of testing i figured i would make sure the log was
logging the way i want it to and then try to find some sort of wx wigit
to let the user of the gui name/save to desired location. meanwhile . .
. so you think it saved somewhere right?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Value Error

2013-06-12 Thread Alan Gauld

On 13/06/13 01:08, Marc Tompkins wrote:

On Wed, Jun 12, 2013 at 3:31 PM, Dave Angel mailto:da...@davea.name>> wrote:

 >>> cmath.sqrt(float((math.e **(i * math.pi)).real))
1j

Sh*t just got real.


no, it's imaginary. :-)


--
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] Value Error

2013-06-12 Thread Marc Tompkins
On Wed, Jun 12, 2013 at 3:31 PM, Dave Angel  wrote:

> >>> cmath.sqrt(float((math.e **(i * math.pi)).real))
> 1j
>
Sh*t just got real.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Value Error

2013-06-12 Thread Dave Angel

On 06/12/2013 06:07 PM, Jim Mooney wrote:

On 12 June 2013 14:16, Steve Willoughby  wrote:


or if you try to take the square root of a negative number, etc.



Or the log of -10. Although sqrt(-1) works fine for cmath.sqrt(-1) - I
think I get it.

Come to think of it you can do cmath.log(-10), but that's getting scary ;')

Jim


>>> import math, cmath
>>> i = complex(0,1)
>>> math.sqrt((math.e **(i * math.pi)).real)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: math domain error

>>> cmath.sqrt(float((math.e **(i * math.pi)).real))
1j



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


Re: [Tutor] Value Error

2013-06-12 Thread Jim Mooney
On 12 June 2013 14:16, Steve Willoughby  wrote:

> or if you try to take the square root of a negative number, etc.
>

Or the log of -10. Although sqrt(-1) works fine for cmath.sqrt(-1) - I
think I get it.

Come to think of it you can do cmath.log(-10), but that's getting scary ;')

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


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

2013-06-12 Thread Dave Angel

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

On 06/10/2013 12:23 PM, Prasad, Ramit wrote:

Matt D wrote:

Ramit Prasad wrote:

Scrolled panel is just a graphical container that allows for scrolling inside,
but it is the window that scrolls not widgets inside it. This of it like
a webpage that scrolls. If you use web email the text widget in the
email needs to scroll so you can see your full email context and not
just scroll the page.

You will probably need to create a TextCtrl with the appropriate style
and append your new data. I have given an example below that should
automatically scroll with your new data.

#in __init__
self.scrolling_widget = wx.TextCtrl( self, wx.ID_ANY, '', size=(-1, 275),

style=wx.TE_AUTO_SCROLL|wx.TE_READONLY|wx.TE_PROCESS_ENTER|wx.TE_WORDWRAP|wx.TE_MULTILINE
 )



Hey,
I added this the above 3 lines of code to my file and ran it.  the box
shows up on the far left, mostly of the pane, to the left of the current
text feilds.  I am having trouble positioning this textbox under where
the current text fields are.
I am not sure but maybe this sets up the grid on the pane:
sizer = wx.GridBagSizer(hgap=10, vgap=10)
 self.fields = {}
all the current TextCtrl fields are positioned at (1,1) through (5,5).
I tried adding:
sizer.Add(field, pos=(1,6))
but it did not move the box to the position?


Just to make sure, you did call it field and not self.scrolling_widget
(which was in my example)?

Odd that they don't start at (0,0) when adding to the bag. This is
more a wxpython question and their mailing list might prove more
useful. I could figure it out, but I cannot run the app. Trial
and error here will probably help you the most. You can also
try looking at a different sizer (like BoxSizer and GridSizer).

Personally, I think BoxSizer is the most intuitive as it matches
my thought process. You just set an orientation (vertical/horizontal)
and add widgets to it. To get something in the other direction, you
create another box sizer with the opposite orientation, add widgets
to that sizer, and then add the new sizer to the original sizer. Not
nearly as pretty as grid/grid bag though (by default), but super simple.

BoxSizer API
http://wxpython.org/docs/api/wx.BoxSizer-class.html
Some other sizers are listed here:
http://wxpython.org/docs/api/wx.Sizer-class.html



THanks,
Matt




Hey,
if i put:

  self.logfile = open('logfile.csv', 'w')

in the .py file, within the 'class TrafficPane', then shouldn't
logfile.csv be written to the directory the .py file is in?  because its
not there after running the program?  Where should i look for it?
Thanks
Matt



It should put it in the current directory.  That *may* be the directory 
the script is in, but not necessarily.  It's easy to run something like:


python somdir/myscript.py

in which case the file would be in the parent directory to myscript.py

Note that in some environments, the current directory is invisibly set 
to some convenient place.  For example, when right-clicking on a script 
in Windows Explorer, they make the bald assumption that you want to set 
the current directory the same as the location of the script. That's 
about the worse place for it, but nevermind.




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


Re: [Tutor] Value Error

2013-06-12 Thread Roel Schroeven

Jim Mooney schreef:

Although I'm not sure why int('blah') wouldn't be a type error rather
than a value error.


Because passing a string to int() is perfectly okay, as long as the 
string has an appropriate value: int('42') works, int('forty two') 
raises ValueError.


--
"People almost invariably arrive at their beliefs not on the basis of
proof but on the basis of what they find attractive."
-- Pascal Blaise

r...@roelschroeven.net

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


Re: [Tutor] Value Error

2013-06-12 Thread Steve Willoughby
int('blah') is not a type error because the int() function is expecting to be 
given a string, and it was given a string. The 'blah' is of the correct type.
The problem is that int() couldn't do anything useful with the value of that 
string.

Steve

On 12-Jun-2013, at 14:41, Jim Mooney  wrote:

> Dave Angel 
> 
>import math
> print math.sqrt(-1)
> 
> Ah, that's what I was looking for. I already saw it trip on type mismatches 
> like int('blah'). I was looking for what would be an actual inappropriate 
> value that was still the right type.  Although I'm not sure why int('blah') 
> wouldn't be a type error rather than a value error.
> 
> Jim 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Value Error

2013-06-12 Thread Steve Willoughby
or if you try to take the square root of a negative number, etc.

On 12-Jun-2013, at 14:06, Sander Sweers  wrote:

> On 06/12/2013 10:49 PM, Jim Mooney wrote:
>> Raised when a built-in operation or function receives an argument that has
>> the right type but an inappropriate value, and the situation is not
>> described by a more precise exception such as
>> IndexError
> 
> You get this when the function gets the right object but the value of
> that object is not correct. For example int() will attempt to create an
> integer object from a string object. However if that string is not a
> number represented as a sting you run into a ValueError.
> 
> int('test')
> 
> Traceback (most recent call last):
>  File "", line 1, in 
>int('test')
> ValueError: invalid literal for int() with base 10: 'test'
> 
> When we give it the string representation of 123 int() will convert the
> string to an integer.
> 
> int('123')
> 123
> 
> ~Sander
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Value Error

2013-06-12 Thread Jim Mooney
Dave Angel 

   import math

> print math.sqrt(-1)


Ah, that's what I was looking for. I already saw it trip on type mismatches
like int('blah'). I was looking for what would be an actual inappropriate
value that was still the right type.  Although I'm not sure why int('blah')
wouldn't be a type error rather than a value error.

Jim

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


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

2013-06-12 Thread Matt D
On 06/10/2013 12:23 PM, Prasad, Ramit wrote:
> Matt D wrote:
>> Ramit Prasad wrote: 
> Scrolled panel is just a graphical container that allows for scrolling 
> inside,
> but it is the window that scrolls not widgets inside it. This of it like
> a webpage that scrolls. If you use web email the text widget in the
> email needs to scroll so you can see your full email context and not
> just scroll the page.
>
> You will probably need to create a TextCtrl with the appropriate style
> and append your new data. I have given an example below that should
> automatically scroll with your new data.
>
> #in __init__
> self.scrolling_widget = wx.TextCtrl( self, wx.ID_ANY, '', size=(-1, 275),
 style=wx.TE_AUTO_SCROLL|wx.TE_READONLY|wx.TE_PROCESS_ENTER|wx.TE_WORDWRAP|wx.TE_MULTILINE
  )
>
>> Hey,
>> I added this the above 3 lines of code to my file and ran it.  the box
>> shows up on the far left, mostly of the pane, to the left of the current
>> text feilds.  I am having trouble positioning this textbox under where
>> the current text fields are.
>> I am not sure but maybe this sets up the grid on the pane:
>>  sizer = wx.GridBagSizer(hgap=10, vgap=10)
>> self.fields = {}
>> all the current TextCtrl fields are positioned at (1,1) through (5,5).
>> I tried adding:
>>  sizer.Add(field, pos=(1,6))
>> but it did not move the box to the position?
> 
> Just to make sure, you did call it field and not self.scrolling_widget
> (which was in my example)? 
> 
> Odd that they don't start at (0,0) when adding to the bag. This is
> more a wxpython question and their mailing list might prove more
> useful. I could figure it out, but I cannot run the app. Trial
> and error here will probably help you the most. You can also
> try looking at a different sizer (like BoxSizer and GridSizer).
> 
> Personally, I think BoxSizer is the most intuitive as it matches
> my thought process. You just set an orientation (vertical/horizontal) 
> and add widgets to it. To get something in the other direction, you 
> create another box sizer with the opposite orientation, add widgets
> to that sizer, and then add the new sizer to the original sizer. Not 
> nearly as pretty as grid/grid bag though (by default), but super simple.
> 
> BoxSizer API
> http://wxpython.org/docs/api/wx.BoxSizer-class.html
> Some other sizers are listed here: 
> http://wxpython.org/docs/api/wx.Sizer-class.html
> 
>>
>> THanks,
>> Matt
> 
> 
Hey,
if i put:

 self.logfile = open('logfile.csv', 'w')

in the .py file, within the 'class TrafficPane', then shouldn't
logfile.csv be written to the directory the .py file is in?  because its
not there after running the program?  Where should i look for it?
Thanks
Matt

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


Re: [Tutor] Value Error

2013-06-12 Thread Dave Angel

On 06/12/2013 04:49 PM, Jim Mooney wrote:

I'm going through the exceptions so I can recall and use the basic ones
(not much use for unicode errors at this point ;')  But I'm puzzled by an
aspect of the Value Error:
*exception *ValueError

Raised when a built-in operation or function receives an argument that has
the right type but an inappropriate value, and the situation is not
described by a more precise exception such as
IndexError
.

I know you can bring this error up easily with a wrong user input, but
within a program, what would be an example of something that is the "right
type but an inappropriate value"?



import math
print math.sqrt(-1)



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


Re: [Tutor] Value Error

2013-06-12 Thread Sander Sweers
On 06/12/2013 10:49 PM, Jim Mooney wrote:
> Raised when a built-in operation or function receives an argument that has
> the right type but an inappropriate value, and the situation is not
> described by a more precise exception such as
> IndexError

You get this when the function gets the right object but the value of
that object is not correct. For example int() will attempt to create an
integer object from a string object. However if that string is not a
number represented as a sting you run into a ValueError.

int('test')

Traceback (most recent call last):
  File "", line 1, in 
int('test')
ValueError: invalid literal for int() with base 10: 'test'

When we give it the string representation of 123 int() will convert the
string to an integer.

int('123')
123

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


[Tutor] Value Error

2013-06-12 Thread Jim Mooney
I'm going through the exceptions so I can recall and use the basic ones
(not much use for unicode errors at this point ;')  But I'm puzzled by an
aspect of the Value Error:
*exception *ValueError

Raised when a built-in operation or function receives an argument that has
the right type but an inappropriate value, and the situation is not
described by a more precise exception such as
IndexError
.

I know you can bring this error up easily with a wrong user input, but
within a program, what would be an example of something that is the "right
type but an inappropriate value"?
-- 
Jim
A noun is just a verb with the hiccups
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program after PyCamp

2013-06-12 Thread Chris Calloway

On 6/12/2013 11:18 AM, bja...@jamesgang.dyndns.org wrote:

I've updated this code and to make it more easily readible put it in a
github repo https://github.com/CyberCowboy/FindDuplicates

Everything is working, however the code is hard to read and I'll be
working on cleaning that up, as well as splitting the program into 3
different functions (one that gets hashes, one that finds and identifies
the duplicates, and one that outputs the results)

However I'm having a problem in that if during the hashing faze a filename
with non-ascii characters is encountered the file errors out.  Since this
is going to be used at work and we have a large number of Chinese and
Arabic filenames I need to have the search allow a unicode character set.
How would I go about doing this? Python 2.7 btw.


Feed os.walk a unicode path and you'll get unicode filenames back.

--
Sincerely,

Chris Calloway http://nccoos.org/Members/cbc
office: 3313 Venable Hall   phone: (919) 599-3530
mail: Campus Box #3300, UNC-CH, Chapel Hill, NC 27599
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] On a looping input, subsequent inputs are hidden

2013-06-12 Thread Jim Mooney
I guess that would be hard on Ben Flinkelstein ;') But I guess I could
still have give_cake = True to be more understandable.

Or keep the program the way it is, use   if '' in msg , and sell it to
Guantanamo.

Jim

On 11 June 2013 19:19, Steven D'Aprano  wrote:

> On 12/06/13 03:53, Jim Mooney wrote:
>
>  But I do like the idea of using plain old words, like "bad" as a
>> switch, instead of some inscrutable program-switch ;')
>>
>
>
> I don't. Trust me on this, you will regret it. As the Zen of Python says,
> "Explicit is better than implicit". It may seem like a good idea now, but
> some day you'll write code like this:
>
>
> def reward(msg):
> print(msg)
> if 'link' in msg:
> administer_electric_shock()
> else:
> give_cake()
>
>
> def administer_test(username):
> score = 0
> for question, answer in list_of_tests:
> response = input(question)
> if response == answer:
> score += 1
> if score > len(list_of_tests):
> msg = "Congratulations %s, you have passed!" % username
> else:
> msg = "%s, you are the weakest link!" % username
> reward(msg)
>
>
> Can you see the bug?
>
>
>
>
>
> --
> Steven
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>



-- 
Jim
Today is the day that would have been tomorrow if yesterday was today
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] First program after PyCamp

2013-06-12 Thread bjames
I've updated this code and to make it more easily readible put it in a
github repo https://github.com/CyberCowboy/FindDuplicates

Everything is working, however the code is hard to read and I'll be
working on cleaning that up, as well as splitting the program into 3
different functions (one that gets hashes, one that finds and identifies
the duplicates, and one that outputs the results)

However I'm having a problem in that if during the hashing faze a filename
with non-ascii characters is encountered the file errors out.  Since this
is going to be used at work and we have a large number of Chinese and
Arabic filenames I need to have the search allow a unicode character set. 
How would I go about doing this?

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


Re: [Tutor] First program after PyCamp

2013-06-12 Thread bjames
I've updated this code and to make it more easily readible put it in a
github repo https://github.com/CyberCowboy/FindDuplicates

Everything is working, however the code is hard to read and I'll be
working on cleaning that up, as well as splitting the program into 3
different functions (one that gets hashes, one that finds and identifies
the duplicates, and one that outputs the results)

However I'm having a problem in that if during the hashing faze a filename
with non-ascii characters is encountered the file errors out.  Since this
is going to be used at work and we have a large number of Chinese and
Arabic filenames I need to have the search allow a unicode character set. 
How would I go about doing this? Python 2.7 btw.

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


Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread Steven D'Aprano

On 12/06/13 19:32, Khalid Al-Ghamdi wrote:

Hi,

Why doesn't this work? And is there way to have an
object immediately return a value or object once it is instantiated with
using a method call?


It does return a value. It returns the object that was just instantiated.

Supposed you could do what you wanted:



1. >>> class k:
2. def __init__(self,n):
3. return n*n
4.
5.
6. >>> khalid=k(3)


and khalid receives the value 9. That would be useless, because the instance of 
class K would be immediately destroyed.

If you want to just return a value, use a function. This is the best solution:


def k(n):
return n*n

khalid = k(3)
assert khalid == 9



Another alternative is to create a callable object:

class K:
def __init__(self, n):
self.n = n
def __call__(self, arg):
return arg * self.n

k = K(3)
k(2)
=> returns 6
k(5)
=> returns 15


A third alternative is to use the __new__ method. This only works in Python 3, 
or for new-style classes that inherit from object:

class K(object):
def __new__(cls, n):
return n*n


but don't do this. Really, don't. There are advanced uses where this is useful, 
but for this trivial example, you should just use a function.




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


Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread Peter Otten
Khalid Al-Ghamdi wrote:

>1. >>> class k:
>2. def __init__(self,n):
>3. return n*n
>4.
>5.
>6. >>> khalid=k(3)
>7. Traceback (most recent call last):
>8.   File "", line 1, in 
>9. khalid=k(3)
>10. TypeError: __init__() should return None, not 'int'

> Why doesn't this work? 

Leaving out the details, for a class A

a = A(...)

is essentially a shortcut for

a = A.__new__(A, ...)
a.__init__(...)

__new__(), not __init__() determines what value is bound to the name a.

> And is there way to have an
> object immediately return a value or object once it is instantiated with
> using a method call?

You can write your own implementation of __new__(), but that is expert area 
and hardly ever needed. When you aren't interested in the class instance you 
shouldn't create one in the first place, and use a function instead:

def k(n):
return n*n
khalid = k(3)

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


Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread vishwajeet singh
On Wed, Jun 12, 2013 at 3:02 PM, Khalid Al-Ghamdi wrote:

> Hi,
>
> Why doesn't this work? And is there way to have an
> object immediately return a value or object once it is instantiated with
> using a method call?
>

__init__ returns the newly created object. You cannot (or at least
shouldn't) return something else.
Try making whatever you want to return an instance variable (or function).

Refer this thread
http://stackoverflow.com/questions/2491819/python-init-how-to-return-a-value


>
>1. >>> class k:
>2. def __init__(self,n):
>3. return n*n
>4.
>5.
>6. >>> khalid=k(3)
>7. Traceback (most recent call last):
>8.   File "", line 1, in 
>9. khalid=k(3)
>10. TypeError: __init__() should return None, not 'int'
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Vishwajeet Singh
+91-9657702154 | dextrou...@gmail.com | http://bootstraptoday.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Using __init__ to return a value

2013-06-12 Thread Khalid Al-Ghamdi
Hi,

Why doesn't this work? And is there way to have an
object immediately return a value or object once it is instantiated with
using a method call?


   1. >>> class k:
   2. def __init__(self,n):
   3. return n*n
   4.
   5.
   6. >>> khalid=k(3)
   7. Traceback (most recent call last):
   8.   File "", line 1, in 
   9. khalid=k(3)
   10. TypeError: __init__() should return None, not 'int'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Creating a Choose Your Own Adventure Game :p:

2013-06-12 Thread DragonDon
Thanks for the info Thomas.

I have heard of github but not bitbucket.  I have tried PyPI once from
another book(HeadFirst series) but never went further.  I don't even know
yet if this is something worthy of making available to a broader audience.
 Outside of my blog and a few select other people, this is my first foray
into a more public 'court of opinion' if you will.

If I find there is enough interest/feedback to make this a decent bit of
code, I'll put it up somewhere I think.

DragonDon


On Wed, Jun 12, 2013 at 1:59 PM, Paradox  wrote:

> >On 06/12/2013 12:24 PM, DragonDon wrote:
> >http://cosmopolitangeek.**wordpress.com<
> http://cosmopolitangeek.**wordpress.com
> >
>
> Dragon Don,
>
> I will check this out but I wonder if you have ever heard of git or
> mercurial?  Putting code for small projects up on github or bitbucket is
> very simple and makes the sharing, updating, etc. easier.  Also using a
> DVCS allows for rollbacks, updates, incorporating other people's changes,
> etc.
>
> github: github.com
> Bitbucket: bitbucket.org.
>
> thomas
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [OT]Death of VMS

2013-06-12 Thread Mark Lawrence
I figured some of the folks out there who appreciate real operating 
systems might be interested in this 
http://www.theregister.co.uk/2013/06/10/openvms_death_notice/


--
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

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