Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread Dave Angel
(Don't top-post.  It confuses everything.  Put your reply at the bottom, 
or maybe inline)

bob smith wrote:
 
Thanks for the reply. Unfortunately, even when I include a variable, all of the buttons start out selected. I noticed that this is the case when I create a StringVar (rather than an IntVar, where the buttons start out correctly unselected). So, here's another simple example where all of the radio buttons start out incorrectly selected:


from tkinter import *

root = Tk()
root.grid()

v = StringVar()
Radiobutton(root, text = "Test RadioButton 1", variable=v, 
value="1").grid(row = 0, column = 0, sticky = W)
Radiobutton(root, text = "Test RadioButton 2", variable=v, 
value="2").grid(row = 1, column = 0, sticky = W)

root.mainloop()


Any ideas on how to have a StringVar() associated with a group of Radiobutton 
objects where all of the radio buttons start off unselected?

--Bob


  

Date: Thu, 8 Oct 2009 20:43:21 -0400
Subject: Re: [Tutor] Python 3 and tkinter Radiobuttons
From: ken...@tds.net
To: bobsmith...@hotmail.com
CC: tutor@python.org

On Thu, Oct 8, 2009 at 6:04 PM, bob smith  wrote:


Hi.  I’m using Tkinter to create a new Radiobutton in Python 3.  However,
when I create the button, it starts off looking selected instead of
unselected (though it behaves correctly like an unselected Radiobutton).  So
this means when I create a group of Radiobuttons they all look selected when
my program begins.
  

You have to associate the Radiobuttons with a variable, for example:

from tkinter import *

root = Tk()
root.grid()
v = IntVar()
button = Radiobutton(root, text = "Test RadioButton", variable=v, value=1)
button.grid(row = 0, column = 0, sticky = W)

button = Radiobutton(root, text = "Test RadioButton2", variable=v, value=2)
button.grid(row = 1, column = 0, sticky = W)

root.mainloop()


Kent

 
I think Kent forgot to include the v.set(), to set the initial state of 
that group of radiobuttons.  To go to your example, just add one line:


   from tkinter import *

   root = Tk()
   root.grid()

   v = StringVar()
   v.set("1")
   Radiobutton(root, text = "Test RadioButton 1", variable=v, 
value="1").grid(row = 0, column = 0, sticky = W)
   Radiobutton(root, text = "Test RadioButton 2", variable=v, 
value="2").grid(row = 1, column = 0, sticky = W)


   root.mainloop()


This will select button 1, and leave button 2 unselected.

DaveA

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


Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread Kent Johnson
On Sun, Oct 11, 2009 at 7:00 AM, Dave Angel  wrote:
> bob smith wrote:
>>
>>                  Thanks for the reply. Unfortunately, even when I include
>> a variable, all of the buttons start out selected.

What version of Python 3 are you using? What platform? If you are not
using the latest version, try upgrading. My example works as shown
using Python 3.1 on Mac OSX. The initial state of the buttons is "all
off".

> I think Kent forgot to include the v.set(), to set the initial state of that
> group of radiobuttons.

Without the v.set() it starts with no button selected. With v.set() it
starts with one button selected. Either way it satisfies the OP's
requirement; which one is correct depends on his needs.

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


[Tutor] Extracting columns from CSV

2009-10-11 Thread Utkarsh ""
Hello, I have a CSV file, from which I want to extract data.
The CSV file is arranged like this:

Time, InSec, Open, High, Low, Close, Qty
09:55:17,35717,41.95,41.95,41.95,41.95,105
09:56:03,35763,41.75,41.75,41.75,41.75,20785
09:56:40,35800,41.75,41.75,41.75,41.75,8950

I wanted to extract each column, and put the data in a list, with a list for
each column.
I'm using the following code to perform this action:

Time, InSec, Open, High, Low, Close, Volume = [], [], [], [], [], [], []
thefile = open('somefile.CSV', 'r')
linelist = thefile.readline()
while linelist != '':
b = linelist.split(',')
Time.append(b[0])
InSec.append(b[1])
Open.append(b[2])
High.append(b[3])
Low.append(b[4])
Close.append(b[5])
Volume.append(b[6])
linelist = thefile.readline()

Is there any other, better and more pythonic way to do this ?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Extracting columns from CSV

2009-10-11 Thread vishwajeet singh
On Sun, Oct 11, 2009 at 6:10 PM, Utkarsh ""  wrote:

> Hello, I have a CSV file, from which I want to extract data.
> The CSV file is arranged like this:
>
> Time, InSec, Open, High, Low, Close, Qty
> 09:55:17,35717,41.95,41.95,41.95,41.95,105
> 09:56:03,35763,41.75,41.75,41.75,41.75,20785
> 09:56:40,35800,41.75,41.75,41.75,41.75,8950
>
> I wanted to extract each column, and put the data in a list, with a list
> for each column.
> I'm using the following code to perform this action:
>
> Time, InSec, Open, High, Low, Close, Volume = [], [], [], [], [], [],
> []
> thefile = open('somefile.CSV', 'r')
> linelist = thefile.readline()
> while linelist != '':
> b = linelist.split(',')
> Time.append(b[0])
> InSec.append(b[1])
> Open.append(b[2])
> High.append(b[3])
> Low.append(b[4])
> Close.append(b[5])
> Volume.append(b[6])
> linelist = thefile.readline()
>
> Is there any other, better and more pythonic way to do this ?
>
>   you can take a look at csv module
http://docs.python.org/library/csv.html


> ___
> 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://singhvishwajeet.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


Re: [Tutor] Extracting columns from CSV

2009-10-11 Thread Kent Johnson
On Sun, Oct 11, 2009 at 8:40 AM, Utkarsh ""  wrote:
> Hello, I have a CSV file, from which I want to extract data.
> The CSV file is arranged like this:
> Time, InSec, Open, High, Low, Close, Qty
> 09:55:17,35717,41.95,41.95,41.95,41.95,105
> 09:56:03,35763,41.75,41.75,41.75,41.75,20785
> 09:56:40,35800,41.75,41.75,41.75,41.75,8950
> I wanted to extract each column, and put the data in a list, with a list for
> each column.
> I'm using the following code to perform this action:
>     Time, InSec, Open, High, Low, Close, Volume = [], [], [], [], [], [], []
>     thefile = open('somefile.CSV', 'r')
>     linelist = thefile.readline()
>     while linelist != '':
>         b = linelist.split(',')
>         Time.append(b[0])
>         InSec.append(b[1])
>         Open.append(b[2])
>         High.append(b[3])
>         Low.append(b[4])
>         Close.append(b[5])
>         Volume.append(b[6])
>         linelist = thefile.readline()
> Is there any other, better and more pythonic way to do this ?

First, you should use the csv module to read CSV files, it will do the
splitting for you and correctly handle any quoted values.
Second, a simple way to transpose a list of list is to use zip(*list_of_lists).

Putting these together gives

import csv

f = csv.reader(open('somefile.CSV'))
Time, InSec, Open, High, Low, Close, Volume = zip(*f)

(Pretty cool BTW that *f works, I wasn't sure if it could take an
iterable instead of a sequence.)

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


Re: [Tutor] [OT] Secure coding guidelines

2009-10-11 Thread Lie Ryan
Didar Hossain wrote:
> Hi,
> 
> This is a little off-topic, but, I though I might put this question in.
> 
> Since I am learning Python, I was wondering if there are any good
> references on secure
> coding practices. Books, guides or even any howtos would suffice.
> 
> Security seems to be almost always an after-thought rather than being
> ingrained into
> any course that I have come across including the ones that they have
> in college degrees.
> 
> If this question is inappropriate for this list then please let me
> know and accept my apologies
> (EAFP) ;-)

Common tips for python:

1. Don't trust the user! Any data from raw_input() (py2.x) or input()
(py3.x), etc must be validated.
2. Don't trust files! Data coming from open(), urlopen(), etc must go
through the same rigorous process as user input.
3. Use extreme caution when dynamically generating code. This includes
python's built-in eval/exec, SQL statements, shell call, etc. Prefer APIs.
4. In some cases, don't trust the environment! A malicious user or virus
could attach themselves to the OS's stdin/stdout/file-read/write/shell.
(Don't take this seriously, a program with no input and no output is a
waste of space and time)
5. In extreme situation, don't even trust external modules or even the
standard library.
6. And finally, in any case, don't assume that Guido don't have a hidden
agenda.

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


Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread Alan Gauld


"Kent Johnson"  wrote 


Without the v.set() it starts with no button selected. With v.set() it
starts with one button selected. Either way it satisfies the OP's
requirement; which one is correct depends on his needs.


Unfortunately on Windows it seems to set them all selected 
without the var set. At least it does for me using Python 3.1


Alan G.

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


Re: [Tutor] Extracting columns from CSV

2009-10-11 Thread Lie Ryan
Kent Johnson wrote:
> (Pretty cool BTW that *f works, I wasn't sure if it could take an
> iterable instead of a sequence.)

Just be careful not to use zip(*f) on an infinite iterable...

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


Re: [Tutor] Finding and Inserting missing dates in a date range.

2009-10-11 Thread Lie Ryan
Glen Zangirolami wrote:
> Thats for all the responses. I'm going to use Kents method. I'll let you
> know what I work out.
> 
> Rudiger - I did think about that. Luckily I am generating the list with
> a start datetime and end datetime so if those don't exist 
> in either end if the list I can insert them after I check the dates between.
> 
> 

If you can safely assume that the list of dates are always sorted, you
can simply write something like range_date(date_list[0], date_list[-1]).

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


[Tutor] class with objects

2009-10-11 Thread shellc...@juno.com
I want to display the ship default value for zero and display the ship's 
initial fuel level. Also have a method called status that displays an object's 
name and  fuel values. I want to have several Ship objects and call their 
status() methods to test various aspects of the class constructor.

Here's my code: 

   class Ship(object):
"""A spaceship"""
total = 0
def __init__(self, name, fuel = 0):
   
print "My spaceship has arrived! The",name
self.name = name
self.fuel = fuel

print "My fuel level is", fuel

def status():
Ship.total += 1
print "The total number of objects is", Ship.total
status = staticmethod(status) 

#main
ship = Ship("Galaxia")

print "\nCreating objects."
ship1 = Ship("object 1")
ship2 = Ship("object 2")
ship3 = Ship("object 3")
Ship.status()


Find Top-Rated Pavers
Get competing bids on any driveway, patio or walk need. Free quotes!
http://thirdpartyoffers.juno.com/TGL2141/c?cp=mcvPp46j2ooOnKJe4-1LngAAJ1CmHaRKpeX3s0f3JfT8odq8AAQFALpJjD0AAANSABIXaQA=
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] class with objects

2009-10-11 Thread Wayne
On Sun, Oct 11, 2009 at 2:42 PM, shellc...@juno.com wrote:

> I want to display the ship default value for zero and display the ship's
> initial fuel level. Also have a method called status that displays an
> object's name and  fuel values. I want to have several Ship objects and call
> their status() methods to test various aspects of the class constructor.
>

And what problems have you run into? What would you like from us? This
sounds vaguely like homework which we don't do here. We are, however, more
than happy to offer pointers in the right direction if you get stuck.

For an explanation of /how/ to ask a good question, check out this:
http://catb.org/~esr/faqs/smart-questions.html#examples

HTH,
Wayne


>
> Here's my code:
>
>   class Ship(object):
>"""A spaceship"""
>total = 0
>def __init__(self, name, fuel = 0):
>
>print "My spaceship has arrived! The",name
>self.name = name
>self.fuel = fuel
>
>print "My fuel level is", fuel
>
>def status():
>Ship.total += 1
>print "The total number of objects is", Ship.total
>status = staticmethod(status)
>
> #main
> ship = Ship("Galaxia")
>
> print "\nCreating objects."
> ship1 = Ship("object 1")
> ship2 = Ship("object 2")
> ship3 = Ship("object 3")
> Ship.status()
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread bob smith


> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Sun, 11 Oct 2009 19:32:20 +0100
> Subject: Re: [Tutor] Python 3 and tkinter Radiobuttons
> 
> 
> "Kent Johnson"  wrote 
> 
> > Without the v.set() it starts with no button selected. With v.set() it
> > starts with one button selected. Either way it satisfies the OP's
> > requirement; which one is correct depends on his needs.
> 
> Unfortunately on Windows it seems to set them all selected 
> without the var set. At least it does for me using Python 3.1
> 
> Alan G.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor


Yes, on Windows with Python 3.1 and using a StringVar(), the initial state is 
that  all radio buttons look selected when the program first begins.  I'm able 
to work around it so that no radio buttons look selected when the program first 
begins with:

v.set(None)

But this seems a bit like a hack.  I know back in Python 2.x on Windows, I 
didn't need to do this.  Is this a bug in tkinter for Python 3?  (I know when 
using an IntVar, you don't need to do this).  Is this the best solution for now?

Thanks,

--Bob
  
_
Hotmail: Trusted email with powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141665/direct/01/___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3 and tkinter Radiobuttons

2009-10-11 Thread Kent Johnson
On Sun, Oct 11, 2009 at 5:16 PM, bob smith  wrote:
> Yes, on Windows with Python 3.1 and using a StringVar(), the initial state
> is that all radio buttons look selected when the program first begins.  I'm
> able to work around it so that no radio buttons look selected when the
> program first begins with:
>
> v.set(None)
>
> But this seems a bit like a hack.  I know back in Python 2.x on Windows, I
> didn't need to do this.  Is this a bug in tkinter for Python 3?

I don't see anything in the issue tracker. You could add one.
http://bugs.python.org/

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


Re: [Tutor] class with objects

2009-10-11 Thread Alan Gauld


 wrote 

I want to display the ship default value for zero and display the ship's 
initial fuel level. Also have a method called status that displays an 
object's name and  fuel values. 


So far so good.

I want to have several Ship objects and call their status() methods 
to test various aspects of the class constructor.


Now I'm confused.
Does status "test various aspects of the class constructor" or does it 
"display an objects name and fuel values"? These are not the same thing...


Here's my code: 


  class Ship(object):
   """A spaceship"""
   total = 0
   def __init__(self, name, fuel = 0):
  
   print "My spaceship has arrived! The",name

   self.name = name
   self.fuel = fuel
   
   print "My fuel level is", fuel


   def status():
   Ship.total += 1


What is the puropse of thoe above line?
Why is it part of status()?


   print "The total number of objects is", Ship.total
   status = staticmethod(status) 


And why is it a staticmethod?


ship = Ship("Galaxia")
print "\nCreating objects."
ship1 = Ship("object 1")
ship2 = Ship("object 2")
ship3 = Ship("object 3")
Ship.status()


What do you expect the output to be?
And what is it really? Are they different?

Why?

HTH,


--
Alan Gauld
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


[Tutor] Carriage return

2009-10-11 Thread Vineet Kothari
Hi Everyone

I see that python IDLE add ^M as carriage return while programming in
windows machine. How can I set IDLE not to do so. I don't see any option &
neither do I see any option to check for carriage return.

Can anyone help me as I use IDLE & I need to remove ^M from the end of every
line. Though it is not shown while programming but I can see that when I run
my scripts on debian linux environment & thus get errors.

Thanks

-- 
Regards,
Vineet Kothari
248-821-8105
http://www.vineetkothari.in

-
Its NICE 2 be IMPORTANT, but whats more IMPORTANT is 2 be NICE.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Carriage return

2009-10-11 Thread bob gailer

Vineet Kothari wrote:

Hi Everyone

I see that python IDLE add ^M as carriage return while programming in 
windows machine. How can I set IDLE not to do so. I don't see any 
option & neither do I see any option to check for carriage return.


Can anyone help me as I use IDLE & I need to remove ^M from the end of 
every line. Though it is not shown while programming but I can see 
that when I run my scripts on debian linux environment & thus get errors.


I don't understand. Please explain.


--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Carriage return

2009-10-11 Thread Wayne
On Sun, Oct 11, 2009 at 10:33 PM, Vineet Kothari
wrote:

> Hi Everyone
>
> I see that python IDLE add ^M as carriage return while programming in
> windows machine. How can I set IDLE not to do so. I don't see any option &
> neither do I see any option to check for carriage return.
>
> Can anyone help me as I use IDLE & I need to remove ^M from the end of
> every line. Though it is not shown while programming but I can see that when
> I run my scripts on debian linux environment & thus get errors.
>
>
That's not an issue with IDLE so much as windows/linux. IIRC, Linux only
uses a newline, while windows uses a CRLF. There's the dos2unix util:

http://linuxcommand.org/man_pages/dos2unix1.html

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