[Tutor] Tutor Digest, Vol 69, Issue 73

Mario Cavett ma_development at hotmail.com
Mon Nov 16 13:51:38 CET 2009


I'm sorry I haven't been able to reply topython tutor, I was wondering couldyou guys send me some beginner issuesthat get straight to  basic problems. Beginners have when starting pythonand using it as a scripting language. And nothing else because I'm thinking thats the only way to use it when game designing.please reply
> From: tutor-request at python.org
> Subject: Tutor Digest, Vol 69, Issue 73
> To: tutor at python.org
> Date: Mon, 16 Nov 2009 13:39:38 +0100
> 
> Send Tutor mailing list submissions to
> 	tutor at 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
> 	tutor-request at python.org
> 
> You can reach the person managing the list at
> 	tutor-owner at python.org
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> 
> 
> Today's Topics:
> 
>    1. Re: GzipFile has no attribute '__exit__' (Sander Sweers)
>    2. Re: Writing code while tired, counterproductive?
>       (Albert-Jan Roskam)
>    3. Re: I love python / you guys :) (Luke Paireepinart)
>    4. Re: GzipFile has no attribute '__exit__' (Kent Johnson)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Mon, 16 Nov 2009 13:15:32 +0100
> From: Sander Sweers <sander.sweers at gmail.com>
> To: Dave Angel <davea at ieee.org>
> Cc: Python Tutor mailing list <tutor at python.org>
> Subject: Re: [Tutor] GzipFile has no attribute '__exit__'
> Message-ID:
> 	<b65fbb130911160415n1861860bif36d6afcee3ad918 at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
> 
> 2009/11/16 Dave Angel <davea at ieee.org>:
> > Alternatively, you could subclass it, and write your own. ?At a minimum, the
> > __exit__() method should close() the stream.
> 
> This triggered my to dig into this a bit. This is not fixed untill
> python 3.1 but seems easilly added to the ZipFile class. My attempt to
> backport this from python 3.1's gzip.py below seems to work.
> 
> Greets
> Sander
> 
> import gzip
> 
> class myGzipFile(gzip.GzipFile):
>     def __enter__(self):
>         if self.fileobj is None:
>             raise ValueError("I/O operation on closed GzipFile object")
>         return self
> 
>     def __exit__(self, *args):
>         self.close()
> 
> zfilepath = r'C:\test.gz'
> s = 'This is a test'
> 
> with myGzipFile(zfilepath,'w') as output:
>     output.write(s)
> 
> 
> ------------------------------
> 
> Message: 2
> Date: Mon, 16 Nov 2009 04:17:51 -0800 (PST)
> From: Albert-Jan Roskam <fomcl at yahoo.com>
> To: OkaMthembo <zebra05 at gmail.com>, Luke Paireepinart
> 	<rabidpoobear at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] Writing code while tired, counterproductive?
> Message-ID: <940960.30630.qm at web110706.mail.gq1.yahoo.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> I find that switching to a completely different approach or strategy becomes more difficult when tired. Depending on the context, that could be called persistence of perseverence (begin good or bad, respectively).?However, in my opinion, not being able to view things from a different angle is usually counterproductive.
> 
> Cheers!!
> Albert-Jan
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In the face of ambiguity, refuse the temptation to guess.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> --- On Mon, 11/16/09, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
> 
> 
> From: Luke Paireepinart <rabidpoobear at gmail.com>
> Subject: Re: [Tutor] Writing code while tired, counterproductive?
> To: "OkaMthembo" <zebra05 at gmail.com>
> Cc: tutor at python.org
> Date: Monday, November 16, 2009, 9:56 AM
> 
> 
> I hate to be the odd one out here, but I actually find that I am extremely productive when I'm tired.? It's easier for me to commit completely to the code, when I'm well-rested I dream about running through fields of sunflowers and such, get distracted more easily.? The code I write when I'm tired is usually of marginally worse quality, but it's usually easy to audit it when I'm rested and fix any problems.? Although if I'm trying to solve something particularly difficult, especially something I've never done before, sometimes I won't be able to do it until I wake up a bit.? Note that this is for being tired, not exhausted.? If I'm exhausted I write a whole lot of awful code that I have to completely rewrite when I wake up.
> 
> 
> On Mon, Nov 16, 2009 at 12:57 AM, OkaMthembo <zebra05 at gmail.com> wrote:
> 
> >From first-hand experience, i would concur :)
> 
> A refreshed mind will perform much better than an over-exerted one.
> 
> 
> 
> 
> 
> On Sat, Nov 14, 2009 at 8:57 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> 
> 
> "Modulok" <modulok at gmail.com> wrote
> 
> 
> Does anyone else find, writing code while tired to be counterproductive?
> 
> Yes. Doing anything that is mentally taxing is usually a bad idea when tired!
> 
> Alan G
> 
> _______________________________________________
> Tutor maillist ?- ?Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> -- 
> Regards,
> Lloyd
> 
> _______________________________________________
> Tutor maillist ?- ?Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> -----Inline Attachment Follows-----
> 
> 
> _______________________________________________
> Tutor maillist? -? Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
>       
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20091116/aaf52501/attachment-0001.htm>
> 
> ------------------------------
> 
> Message: 3
> Date: Mon, 16 Nov 2009 06:25:34 -0600
> From: Luke Paireepinart <rabidpoobear at gmail.com>
> To: "[tutor python]" <tutor at python.org>
> Subject: Re: [Tutor] I love python / you guys :)
> Message-ID:
> 	<dfeb4470911160425y72f0a251mbe83771a324b8168 at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
> 
> Accidental off-list reply.
> On Mon, Nov 16, 2009 at 5:36 AM, bibi midi <bibsmendez at gmail.com> wrote:
> 
> >
> > In the same lines of if-you-can-think-of-anything-python-can-do-it i got
> > inspired to ask a question for the gurus:
> >
> > When i use our company's LAN i set my proxy variable by hand in .bashrc.
> > There are 4 files to insert proxy variable:
> >
> > in ~/.bashrc, /root/.bashrc, /etc/wgetrc and /etc/apt/apt.conf.
> >
> > The last one is actually rename e.g. mv to apt.conf to activate proxy and
> > mv to apt.conf.bak to deactivate. The proxy variable is something like this
> >
> > export http_proxy=http://username:password@proxy:port
> > ftp_proxy=$http_proxy
> >
> > To activate i uncomment them then source .bashrc. To deactivate i put back
> > the comment sign. I do it all in vim e.g. vim -o the-3-files-above. For
> > apt.conf see rename above. I deactivate because i have another internet
> > connection option via 3G usb modem. But thats another story.
> >
> > I will do this myself in python so please show me the way. Surely this can
> > be done.
> >
> > Sure it can.
> 
> This is actually fairly easy to do.  I would just use regular expressions to
> match the lines and comment/uncomment them  depending on if you want to
> enable/disable.
> 
> 
> ####################
> Spoiler alert! don't read if you want to solve it yourself.
> ####################
> 
> #### Remove/Add comments to any line that matches a specified regular
> expression.
> ##    comments are assumed to be the '#' symbol.
> #### Warning - completely untested code.
> 
> import re
> regex =  # remove leading spaces and the # comment symbol from a line, if it
> exists.
> 
> def uncomment(filename, regex, newfile):
>     remove_comments_regex = ' *#*(.*$)'
>     for line in open(filename):
>         if re.match(regex, line): # if we have a matching line we should
> remove the comment.
>             newfile.write(re.match(remove_comments_regex, line).groups()[0])
> 
> def comment(filename, regex, newfile):
>     for line in open(filename):
>         if re.match(regex, line):
>             #avoid dual-commenting
>             if line.strip().startswith("#"):
>                 newfile.write(line)
>             else:
>                 newfile.write('#' + line)
> 
> ####################
> End of spoiler
> ####################
> 
> 
> As for renaming, look into the os module, there's an easy function for
> renaming in there.  Just add a check around the rename function for an
> os.path.exists(...) so you can ensure the file exists before you attempt to
> rename it, otherwise you might get an exception (or you could just try
> renaming it and just catch the exception, either way.)   Then just make a
> .py script that can enable and one that can disable, and make sure tehre's
> no harm if you run either one multiple times consecutively.
> 
> Hope that helps, and yes, we know you guys appreciate the help, that's why
> we do it!  We certainly don't get paid anything.  It's nice to hear you say
> it anyway though, so thanks!
> -Luke
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://mail.python.org/pipermail/tutor/attachments/20091116/b59758f5/attachment-0001.htm>
> 
> ------------------------------
> 
> Message: 4
> Date: Mon, 16 Nov 2009 07:39:33 -0500
> From: Kent Johnson <kent37 at tds.net>
> To: Sander Sweers <sander.sweers at gmail.com>
> Cc: Python Tutor mailing list <tutor at python.org>, Dave Angel
> 	<davea at ieee.org>
> Subject: Re: [Tutor] GzipFile has no attribute '__exit__'
> Message-ID:
> 	<1c2a2c590911160439g30a5892etca96926b3c9f64a8 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> On Mon, Nov 16, 2009 at 7:15 AM, Sander Sweers <sander.sweers at gmail.com> wrote:
> 
> > This triggered my to dig into this a bit. This is not fixed untill
> > python 3.1 but seems easilly added to the ZipFile class. My attempt to
> > backport this from python 3.1's gzip.py below seems to work.
> >
> > Greets
> > Sander
> >
> > import gzip
> >
> > class myGzipFile(gzip.GzipFile):
> > ? ?def __enter__(self):
> > ? ? ? ?if self.fileobj is None:
> > ? ? ? ? ? ?raise ValueError("I/O operation on closed GzipFile object")
> > ? ? ? ?return self
> >
> > ? ?def __exit__(self, *args):
> > ? ? ? ?self.close()
> 
> You might want to report this as a bug against 2.6 and submit this
> change as a proposed fix. It's easy to do, see
> http://www.python.org/dev/patches/
> 
> You could submit your change right in the body of the report if you
> don't want to make a diff file. You could suggest an update to the
> docs as well.
> 
> Kent
> 
> 
> ------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> End of Tutor Digest, Vol 69, Issue 73
> *************************************
 		 	   		  
_________________________________________________________________
Windows 7: It works the way you want. Learn more.
http://www.microsoft.com/Windows/windows-7/default.aspx?ocid=PID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_evergreen:112009v2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091116/09a5076a/attachment-0001.htm>


More information about the Tutor mailing list