Re: [Tutor] Tutor Digest, Vol 26, Issue 56

2006-04-18 Thread nywbon001
Quoting [EMAIL PROTECTED]:

> Send Tutor mailing list submissions to
>   tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   [EMAIL PROTECTED]
>
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. Changing lists in place (Paul D. Kraus)
>2. Re: Changing lists in place (Paul D. Eden)
>3. Re: Changing lists in place (Bob Gailer)
>4. Re: Meaning of %g ? (Terry Carroll)
>5. Re: Changing lists in place (Kent Johnson)
>6. Re: Tutor Digest, Vol 26, Issue 55 (Carroll, Barry)
>7. Re: Changing lists in place (Paul D. Eden)
>8. Re: functions in Python (Alan Gauld)
>9. Raw Bits! (Control characters ahoy!) (doug shawhan)
>
>
> --
>
> Message: 1
> Date: Mon, 17 Apr 2006 14:02:37 -0400
> From: "Paul D. Kraus" <[EMAIL PROTECTED]>
> Subject: [Tutor] Changing lists in place
> To: tutor@python.org
> Message-ID:
>   <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> I have a list that I want to change in a for loop. It changes in the loop
> but the changes are not persistant outside of the loop.
> I thought lists were mutuable objects so I am a bit confused.
>
> Sample Code
> #!/usr/bin/env python
> """ Testing lists """
>
> mylist = [ 'One', '   two', '   three   ' ]
> print mylist
> for element in mylist:
> element = element.strip()
> print "<>" + element + "<>"
> print mylist
>
>
> Sample Output
> ['One', '   two', '   three   ']
> <>One<>
> <>two<>
> <>three<>
> ['One', '   two', '   three   ']
> -- next part --
> An HTML attachment was scrubbed...
> URL:
>
http://mail.python.org/pipermail/tutor/attachments/20060417/b1d0ae57/attachment-0001.html
>
> --
>
> Message: 2
> Date: Mon, 17 Apr 2006 11:11:44 -0700
> From: "Paul D. Eden" <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Changing lists in place
> To: [EMAIL PROTECTED]
> Cc: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Lists are mutable, you are right.
>
> But the code you gave does not change the list.  It changes the variable
> element which is separate from the list myList.
>
> If you want to change the list try something like this:
>
> mylist = [ 'One', '   two', '   three   ' ]
> print mylist
> newlist = []
> for element in mylist:
>  element = element.strip()
>  newlist.append(element)
>  print "<>" + element + "<>"
> print newlist
>
> OR
>
> mylist = [ 'One', '   two', '   three   ' ]
> print mylist
> mylist = [element.strip() for element in mylist]
> for element in mylist:
>  print "<>" + element + "<>"
> print mylist
>
> Paul
>
> Paul D. Kraus wrote:
> > I have a list that I want to change in a for loop. It changes in the
> > loop but the changes are not persistant outside of the loop.
> > I thought lists were mutuable objects so I am a bit confused.
> >
> > Sample Code
> > #!/usr/bin/env python
> > """ Testing lists """
> >
> > mylist = [ 'One', '   two', '   three   ' ]
> > print mylist
> > for element in mylist:
> > element = element.strip()
> > print "<>" + element + "<>"
> > print mylist
> >
> >
> > Sample Output
> > ['One', '   two', '   three   ']
> > <>One<>
> > <>two<>
> > <>three<>
> > ['One', '   two', '   three   ']
> >
> >
> > 
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
>
> --
>
> Message: 3
> Date: Mon, 17 Apr 2006 11:17:18 -0700
> From: Bob Gailer <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Changing lists in place
> To: [EMAIL PROTECTED]
> Cc: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Paul D. Kraus wrote:
> > I have a list that I want to change in a for loop. It changes in the
> > loop but the changes are not persistant outside of the loop.
> > I thought lists were mutuable objects
> They are.
> > so I am a bit confused.
> >
> > Sample Code
> > #!/usr/bin/env python
> > """ Testing lists """
> >
> > mylist = [ 'One', '   two', '   three   ' ]
> > print mylist
> > for element in mylist:
> element is a variable to which the successive items in mylist are
> assigned. element has no "magic" connection to the list.
> > element = element.strip()
> In order to change a list item you must do something like:
> mylist[itemIndex] = element.strip()
>
> So you need both the item's value and its position in the list. That's
> what enumer

Re: [Tutor] Tutor Digest, Vol 26, Issue 62

2006-04-19 Thread nywbon001
Quoting [EMAIL PROTECTED]:

> Send Tutor mailing list submissions to
>   tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>   [EMAIL PROTECTED]
>
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>1. Help Entry  !!! (Cesar Garcia)
>2. creating a tab delim file (Srinivas Iyyer)
>3. Re: Olle-Olla (Kent Johnson)
>4. Re: Tutorial on bitwise Python? (Alan Gauld)
>5. Re: creating a tab delim file (Karl Pfl?sterer)
>6. Version of a .pyc file (Don Taylor)
>7. unit testing raw_input() (Andre Roberge)
>8. Re: Version of a .pyc file (Terry Carroll)
>9. Re: unit testing raw_input() (Michael)
>   10. Re: unit testing raw_input() (Danny Yoo)
>
>
> --
>
> Message: 1
> Date: Tue, 18 Apr 2006 11:14:03 -0700 (PDT)
> From: Cesar Garcia <[EMAIL PROTECTED]>
> Subject: [Tutor] Help Entry  !!!
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi !!!
>   Friends, i nedd process Data Entry in python
>   Example
>
>   Entry = 20
>   Result = 20*10
>
>   This Result in Windows (Tkinter)
>   How do you do Think !!!
>
>   Regards
>   Cesar
>   Exmaple
>   from Tkinter import *
>   class MyDialog:
>   def __init__(self, parent):
> top = self.top = Toplevel(parent)
> Label(top, text="Valor").pack()
> self.e = Entry(top)
> self.e.pack(padx=5)
> b = Button(top, text="OK", command=self.ok)
> b.pack(pady=5)
>   def ok(self):
> print "value is", self.e.get()
> self.top.destroy()
>   root = Tk()
> root.update()
> d = MyDialog(root)
> root.wait_window(d.top)
>
>
> -
> New Yahoo! Messenger with Voice. Call regular phones from your PC and save
> big.
> -- next part --
> An HTML attachment was scrubbed...
> URL:
>
http://mail.python.org/pipermail/tutor/attachments/20060418/0bb19d34/attachment-0001.htm
>
> --
>
> Message: 2
> Date: Tue, 18 Apr 2006 11:53:58 -0700 (PDT)
> From: Srinivas Iyyer <[EMAIL PROTECTED]>
> Subject: [Tutor] creating a tab delim file
> To: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=iso-8859-1
>
> Hi group,
>  I asked similar questions in the past. I am unable to
> get to the crux of this problem so that I can solve on
> my own. apologies for my ignorance.
>
>
> The problem:
>
> I have 50 tab delim files. Each file has 500 rows and
> 50 columns.
>
> I have to read the first column of each file. Repeat
> the same for 50 files and write a tab delim text file
> containing 500 rows and 50 columns.
>
> code that works through half of the problem:
>
> import glob
>
> files = glob.glob('*.proc')
>
>
> for each in files:
>   f = open(each,'r')
>   da = f.read().split('\n')
>   dat = da[:-1]
>   for m in dat:
> mycol = m.split('\t')[0]
> ..
>
> >From here I am blanked out. Although I can extract the
> first column from each file:I have no idea how to
> store each list.
>
> thought 1. Create an empty string and join each by a
> tab.
> ##
>mycol = ''
>for m in dat:
> mycol = m.split('\t')[0]
> mstr = '\t'.join(mycol)
> how can i append the data from second file to that
> string.
>
>
> could tutors help me with this situation.
>
> Thanks
> srini
>
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
> --
>
> Message: 3
> Date: Tue, 18 Apr 2006 14:59:38 -0400
> From: Kent Johnson <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] Olle-Olla
> To: Python Tutor 
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> Andre Engels wrote:
> > 2006/4/18, Kent Johnson <[EMAIL PROTECTED]>:
> >> J?nos Juh?sz wrote:
> >>> Hi All,
> >>>
> >>> Is it possible to replace the print statement with one of mine function ?
> >>>
> >>> In reality, I would like to replace the print in my PyCrust app with the
> >>> log.write() function.
> >> Best: Use a good editor to change your print statements to log.write()
> >
> > Even better: Use a good editor to change your print statements to
> > myprint() and then def myprint() to be log.write(). This has the
> > advantage that if (for example) you want prints later to be "usually
> > log.write() but if redFlagHighestWarning is True, then both
> > log.write() and print()", you don't need to go through all this again,
> > but just have to change myprint().
>
> Or use the logging module, w