From emile at fenx.com  Tue Jul  1 00:32:36 2014
From: emile at fenx.com (Emile van Sebille)
Date: Mon, 30 Jun 2014 15:32:36 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <loq4n9$jgl$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org>
Message-ID: <losoid$tlf$1@ger.gmane.org>

On 6/29/2014 3:41 PM, Alan Gauld wrote:

> What are the best unofficial (ie not python.org)
> resources for people who have learned the basics
> but are not experts yet?

dejanews.com, no wait, that's now groups.google.com  -- oh wait, the 
just-don't-be-evil empire kinda killed that one off finally.  >sigh<

Emile





From dyoo at hashcollision.org  Tue Jul  1 00:48:01 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Mon, 30 Jun 2014 15:48:01 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <losoid$tlf$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org> <losoid$tlf$1@ger.gmane.org>
Message-ID: <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>

>> What are the best unofficial (ie not python.org)
>> resources for people who have learned the basics
>> but are not experts yet?
>
> dejanews.com, no wait, that's now groups.google.com  -- oh wait, the
> just-don't-be-evil empire kinda killed that one off finally.  >sigh<


Hi Emile,

I do not know what you are referring to.  Can you be more specific?
Are you referring to comp.lang.python, or a different newsgroup, or
something else entirely?  Are you talking about a particular mailing
list?

From emile at fenx.com  Tue Jul  1 01:01:14 2014
From: emile at fenx.com (Emile van Sebille)
Date: Mon, 30 Jun 2014 16:01:14 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>
References: <loq4n9$jgl$1@ger.gmane.org> <losoid$tlf$1@ger.gmane.org>
 <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>
Message-ID: <losq83$fln$1@ger.gmane.org>

On 6/30/2014 3:48 PM, Danny Yoo wrote:
>>> What are the best unofficial (ie not python.org)
>>> resources for people who have learned the basics
>>> but are not experts yet?
>>
>> dejanews.com, no wait, that's now groups.google.com  -- oh wait, the
>> just-don't-be-evil empire kinda killed that one off finally.  >sigh<
>
>
> Hi Emile,
>
> I do not know what you are referring to.  Can you be more specific?
> Are you referring to comp.lang.python, or a different newsgroup, or
> something else entirely?  Are you talking about a particular mailing
> list?

See http://en.wikipedia.org/wiki/Google_Groups for one version of the 
details, but the initial demise of deja.com took away what was then the 
best research tool around (IMHO) until google revived it (yay!), until 
google rewrote it (boo! hiss!).

Knowing-as-much-as-I-need-to-already-ly y'rs,

Emile



From dyoo at hashcollision.org  Tue Jul  1 01:14:15 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Mon, 30 Jun 2014 16:14:15 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <losq83$fln$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org> <losoid$tlf$1@ger.gmane.org>
 <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>
 <losq83$fln$1@ger.gmane.org>
Message-ID: <CAGZAPF5QiRokKpZZEWJwZomVMzzfBQwn4mwk4j0v5DcFw_0DYw@mail.gmail.com>

On Mon, Jun 30, 2014 at 4:01 PM, Emile van Sebille <emile at fenx.com> wrote:
> On 6/30/2014 3:48 PM, Danny Yoo wrote:
>>>>
>>>> What are the best unofficial (ie not python.org)
>>>> resources for people who have learned the basics
>>>> but are not experts yet?
>>>
>>>
>>> dejanews.com, no wait, that's now groups.google.com  -- oh wait, the
>>> just-don't-be-evil empire kinda killed that one off finally.  >sigh<


... Stay on topic... We're too close!... Stay on topic!


In any event, I did very much like Dave Beazley's "Python Essential
Reference".  At least, I remember thinking it was excellent it when it
was in its red cover.  :P   I don't know what the latest edition is
like, but it's probably of similar quality.

From emile at fenx.com  Tue Jul  1 01:29:58 2014
From: emile at fenx.com (Emile van Sebille)
Date: Mon, 30 Jun 2014 16:29:58 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <CAGZAPF5QiRokKpZZEWJwZomVMzzfBQwn4mwk4j0v5DcFw_0DYw@mail.gmail.com>
References: <loq4n9$jgl$1@ger.gmane.org> <losoid$tlf$1@ger.gmane.org>
 <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>
 <losq83$fln$1@ger.gmane.org>
 <CAGZAPF5QiRokKpZZEWJwZomVMzzfBQwn4mwk4j0v5DcFw_0DYw@mail.gmail.com>
Message-ID: <losrtv$1l1$1@ger.gmane.org>

On 6/30/2014 4:14 PM, Danny Yoo wrote:

> In any event, I did very much like Dave Beazley's "Python Essential
> Reference".  At least, I remember thinking it was excellent it when it
> was in its red cover.  :P   I don't know what the latest edition is
> like, but it's probably of similar quality.

Well, in that case I'd put forward effbot's guide to the python standard 
library, particularly for python 2.x, but most of the examples are still 
valid.  I paid for it back in the day, but now it's available on-line at 
http://effbot.org/librarybook/

Emile

<please excuse duplicates if they show up - I'm not sure I originally 
sent this from a valid account for the mailing list gateway>



From alan.gauld at btinternet.com  Tue Jul  1 01:35:06 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 01 Jul 2014 00:35:06 +0100
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <losq83$fln$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org> <losoid$tlf$1@ger.gmane.org>
 <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>
 <losq83$fln$1@ger.gmane.org>
Message-ID: <loss7a$48u$1@ger.gmane.org>

On 01/07/14 00:01, Emile van Sebille wrote:

>>> dejanews.com, no wait, that's now groups.google.com  -- oh wait, the
>>> just-don't-be-evil empire kinda killed that one off finally.  >sigh<

While deja-news wasn't exactly a Python resource I share your
regret that it disappeared. While you can, just about, find
the same information via Google Groups it is nowhere near
as effective as the old Deja-News was.

But I'm really looking for something a wee bit more Python
specific, otherwise I'll have to list every search engine! :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Tue Jul  1 01:42:28 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 01 Jul 2014 00:42:28 +0100
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <losrtv$1l1$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org> <losoid$tlf$1@ger.gmane.org>
 <CAGZAPF7XhtMyJX0dsUm+EycPLvQfDxSZMLgzwzzAAiW+DccK7A@mail.gmail.com>
 <losq83$fln$1@ger.gmane.org>
 <CAGZAPF5QiRokKpZZEWJwZomVMzzfBQwn4mwk4j0v5DcFw_0DYw@mail.gmail.com>
 <losrtv$1l1$1@ger.gmane.org>
Message-ID: <lossl4$7b0$1@ger.gmane.org>

On 01/07/14 00:29, Emile van Sebille wrote:

> Well, in that case I'd put forward effbot's guide to the python standard
> library, particularly for python 2.x, but most of the examples are still
> valid.

That's a good point, I omitted to say I'm specifically looking
at Python 3 only. The book code is all tested up to v3.4...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From antparris at yahoo.com  Tue Jul  1 02:12:00 2014
From: antparris at yahoo.com (Ant Parris)
Date: Mon, 30 Jun 2014 17:12:00 -0700
Subject: [Tutor] server / client program
Message-ID: <1404173520.3636.YahooMailNeo@web122101.mail.ne1.yahoo.com>

Hi, I am new to python and i am stuck on a lab I am working on. below is the lab instructions for creating a server and client program.

1) Both server and client program run continually
2) until no message is coming in the server. It means if a client hits the return key with no text
3) Then both client and server programs terminate.

Please help as soon as possible.. Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140630/beb283e1/attachment.html>

From varunaseneviratna at gmail.com  Tue Jul  1 03:57:45 2014
From: varunaseneviratna at gmail.com (Varuna Seneviratna)
Date: Tue, 1 Jul 2014 07:27:45 +0530
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <loq4n9$jgl$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org>
Message-ID: <CAKW-c0wxPkah-8wygyER_30jTCgsyvhixYQHjkYu-DXiSKLGPw@mail.gmail.com>

On 30 June 2014 04:11, Alan Gauld <alan.gauld at btinternet.com> wrote:
> I'm looking for tips for an appendix to a book that
> I'm working on.
>
> What are the best unofficial (ie not python.org)
> resources for people who have learned the basics
> but are not experts yet? ie Typical tutor list
> "graduates"...
>
> I'm thinking about web sites, blogs, books, videos etc.
> Anything that might be worth knowing about.
>
> I've got a few of my own - Activestate, O'Reilly,
> ByteOfPython, PythonChallenge, ShowMeDo etc.
>
> But I thought the tutor list readers might be an
> interesting source of alternatives that I hadn't
> thought of, or even heard of.
>
> All contributions considered :-)
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

Google Python Class http://www.youtube.com/watch?v=tKTZoB2Vjuk and the web
page of the lecturer Nick Parlante <http://cs.stanford.edu/people/nick/>,
there are a few Python resources at his web page I think you will find them
useful
                 http://codingbat.com/("is my main part-time project these
days" as described by Nick Parlante)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140701/00ba4cb7/attachment-0001.html>

From dyoo at hashcollision.org  Tue Jul  1 08:52:57 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Mon, 30 Jun 2014 23:52:57 -0700
Subject: [Tutor] server / client program
In-Reply-To: <1404173520.3636.YahooMailNeo@web122101.mail.ne1.yahoo.com>
References: <1404173520.3636.YahooMailNeo@web122101.mail.ne1.yahoo.com>
Message-ID: <CAGZAPF4yMOXy0qM=w_oDD63t1GM2t50ZX-U7fJTZYSZ-9gFBbQ@mail.gmail.com>

On Mon, Jun 30, 2014 at 5:12 PM, Ant Parris
<antparris at yahoo.com.dmarc.invalid> wrote:
> Hi, I am new to python and i am stuck on a lab I am working on. below is the
> lab instructions for creating a server and client program.
>
> 1) Both server and client program run continually
> 2) until no message is coming in the server. It means if a client hits the
> return key with no text
> 3) Then both client and server programs terminate.


Whoa.  Wait.  Are you sure you're taking the right class?  If you
don't have Python experience, do you have any other programming
experience?

If you are starting completely without programming experience, I think
you may be woefully unprepared to take a networking class.  The more
background you can tell us, the better our advice will be.

From alan.gauld at btinternet.com  Tue Jul  1 09:32:35 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 01 Jul 2014 08:32:35 +0100
Subject: [Tutor] server / client program
In-Reply-To: <1404173520.3636.YahooMailNeo@web122101.mail.ne1.yahoo.com>
References: <1404173520.3636.YahooMailNeo@web122101.mail.ne1.yahoo.com>
Message-ID: <loto6j$sn9$1@ger.gmane.org>

On 01/07/14 01:12, Ant Parris wrote:
> Hi, I am new to python and i am stuck on a lab I am working on. below is
> the lab instructions for creating a server and client program.
>
> 1) Both server and client program run continually
> 2) until no me ssage is coming in the server. It means if a client hits
> the return key with no text
> 3) Then both client and server programs terminate.
>
> Please help as soon as possible.. Thank you!

We need to know a bit more about how much you know.
Thus is a reasonably advanced lab so it looks like you have already 
covered the basic language structures like loops and conditional 
expressions?

So which bits of the lab don't you understand? Have you
written any code yet? If so let us see.

Meantime, which bits of the lab are you 'stuck' with?
Do you know how to build a client (of any kind not
just a networking one)? Do you understand what clients
and serves are?

Do you know how to send a message from one program to
another over the network?

We won't write your code for you but we will help you
fix the code you write. But we need to know what the
starting point is.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From james at uplinkzero.com  Tue Jul  1 12:56:12 2014
From: james at uplinkzero.com (James Chapman)
Date: Tue, 1 Jul 2014 11:56:12 +0100
Subject: [Tutor] How can I let the Python Console display more decimal
	precision?
In-Reply-To: <20140612123105.GD10355@ando>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
Message-ID: <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>

You could just initialise your variables with float()

>>> float(26)/float(12)
2.1666666666666665

>>> varA = float(26)
>>> varB = float(12)
>>> varA/varB
2.1666666666666665

And so on...

In fact, you only need to initialise one variable with float for this to
work:

>>> varA = float(26)
>>> varB = 12
>>> varA/varB
2.1666666666666665

This works in Python2 or Python3 without importing any extra libs.




--
James


On 12 June 2014 13:31, Steven D'Aprano <steve at pearwood.info> wrote:

> On Thu, Jun 12, 2014 at 08:48:25AM +0800, Marino David wrote:
> > Hi All:
> >
> > I am a newbie at the Python.
> >
> > I type "26/12" in Python Console and get result of "2".
> >
> > It is obvious that the corresponding result should be 2.3333...... I
> don't
> > know why the Console only returns the integer part of  true result.
> Anyone
> > can help me out?
>
> Try this instead:
>
> 26.0/12
>
> and it will print a fractional number instead of an int:
>
> py> 26.0/12
> 2.1666666666666665
>
>
> What's going on?
>
> Back in the early mists of time, when Python first came out, Python's
> creator Guido van Rossum decided that the / division operator should
> behave like in the C programming language. In C, division of two
> integers performs *integer division*, and drops the remainder, while
> division of one or more floating point number keeps the remainder as a
> fraction:
>
> 1/2 => 0
> 1/2.0 => 0.5
>
> That was one of those decisions that seemed like a good idea at the
> time, but turned out to be a mistake. But for backwards compatibility,
> Python had to keep it until recently.
>
> In Python version 3, / now does calculator division, like you expect.
> But in Python 2, you have to either convert one or both numbers to a
> float, or you can put this at the top of your program:
>
> from __future__ import division
>
> Note that there are TWO underscores at the beginning and end of
> "future".
>
>
> If you want integer division, where the remainder is ignored, you can
> use the // operator:
>
> py> 26.0//12
> 2.0
>
>
>
> --
> Steven
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140701/536e719e/attachment.html>

From s.shall at virginmedia.com  Tue Jul  1 19:04:39 2014
From: s.shall at virginmedia.com (Sydney Shall)
Date: Tue, 01 Jul 2014 19:04:39 +0200
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
Message-ID: <53B2EA27.8050900@virginmedia.com>

I am a beginner and I have always had problems with inheritance.

I can get inheritance to work with very simple classes.
But with more complex classes, I find that inheritance seems to work for 
simple variables, but I cannot get it to work with lists or arrays.
Specifically my problem is to access a numpy array in the parent class, 
from within the derived class.
When I test with instances in IPython everything works properly.
But I thought, perhaps wrongly, that with direct inheritance one does 
not need instances.
If one needs instances, how does one create them so that they are 
correctly recognised.

Perhaps, I need to read more about inheritance, Any suggestions for 
reading would be welcome.

With many thanks.

-- 
Sydney Shall

From alan.gauld at btinternet.com  Tue Jul  1 20:38:35 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 01 Jul 2014 19:38:35 +0100
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <53B2EA27.8050900@virginmedia.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
 <53B2EA27.8050900@virginmedia.com>
Message-ID: <louv7b$fot$1@ger.gmane.org>

On 01/07/14 18:04, Sydney Shall wrote:

> But with more complex classes, I find that inheritance seems to work for
> simple variables, but I cannot get it to work with lists or arrays.
> Specifically my problem is to access a numpy array in the parent class,
> from within the derived class.

Caveat: I know nothing about numpy or Scypy...

> But I thought, perhaps wrongly, that with direct inheritance one does
> not need instances.

You usually need instances for anything to work with objects. The 
instances are the objects. Classes are just templates that don't 
normally do very much of anything until you create instances.
If you write a class that you never instantiate then you should probably 
have written a module instead.

> If one needs instances, how does one create them so that they are
> correctly recognised.

anInstance = TheClass()

Beyond that, you need to explain your question in more detail.
What happens when you try to create an instance? In what way
is it not "correctly recognised"?

> Perhaps, I need to read more about inheritance,

Perhaps. Inheritance can be approached from several directions:

1) Its a way to extend or change the functions of an existing class

2) Its a way to save writing code(potentially dangerous assumption)

3) Its a way to access functions in another class (maybe you
should use delegation instead?)

4) Its purely an implementation trick to provide polymorphic
behaviour in a programming language.

5) Its a logical representation of family subtypes whereby
each subtype has a "kind of" relationship to its parent.
It is more about abstract models of reality than about coding.


All of the above are true to some degree.
Which of those views do you subscribe to? Which of those
aspects would you like to know more about?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From keithadu at live.com  Tue Jul  1 21:39:10 2014
From: keithadu at live.com (keith papa)
Date: Tue, 1 Jul 2014 15:39:10 -0400
Subject: [Tutor] learning to programming questions part 2
Message-ID: <COL130-W71632F4B4E23D8F9AB0D48A8070@phx.gbl>





Hi am leaning to program in python with the book "think python" I have read both chapters 1 and 2 about string and variables and keywords., so I decide to look online for some practice to help me and I found something on http://www.pyschools.com/
1.Write the function countA(word) that takes in a word as argument and returns the number of 'a' in that word.Examples    >>> countA("apple")
    1
    >>> countA("Apple")
    0
    >>> countA("Banana")
    3The code starts out with>>>def countA(word):I have tried many different code to get the answer but am getting it right.I have tried:1. >>>def countA(apple):("a")2. >>>print ("apple")
def count('a')3. >>>("apple").count("a")4. >>>countA= apple.count ("a")#help me solve this
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140701/367e66fd/attachment-0001.html>

From tedgillam at verizon.net  Tue Jul  1 21:06:33 2014
From: tedgillam at verizon.net (Ted Gillam)
Date: Tue, 01 Jul 2014 14:06:33 -0500
Subject: [Tutor] Installation Aborts
Message-ID: <003e01cf955f$92c3c910$b84b5b30$@verizon.net>

I?m trying to install 3..4.1. I downloads OK but about ? the way through it
aborts. I?m new to this can anyone give me any help?

 

Since the above is happening I downloaded 2.7.7. It seems to install OK but
when I try to run the GUI interface nothing happens. Any help here?

 

Thanks in advance, Ted

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140701/f450688f/attachment.html>

From tedgillam at verizon.net  Tue Jul  1 22:11:26 2014
From: tedgillam at verizon.net (Ted Gillam)
Date: Tue, 01 Jul 2014 15:11:26 -0500
Subject: [Tutor] Please excuse  and ignore prior message.
Message-ID: <005601cf9568$a36e3580$ea4aa080$@verizon.net>

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140701/0346afe1/attachment.html>

From alan.gauld at btinternet.com  Wed Jul  2 00:05:50 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 01 Jul 2014 23:05:50 +0100
Subject: [Tutor] learning to programming questions part 2
In-Reply-To: <COL130-W71632F4B4E23D8F9AB0D48A8070@phx.gbl>
References: <COL130-W71632F4B4E23D8F9AB0D48A8070@phx.gbl>
Message-ID: <lovbbu$674$1@ger.gmane.org>

On 01/07/14 20:39, keith papa wrote:

> read both chapters 1 and 2 about string and variables and keywords., so
> I decide to look online for some practice to help me and I found
> something on http://www.pyschools.com/
>
>
> 1.Write the function countA(word) that takes in a word as argument and
> returns the number of 'a' in that word.

The problem is that you are still quite a long way from
being able to define your own functions. You need to find
some simpler examples

> The code starts out with
>
>>>>def countA(word):

This is how you define your own fuinctions in Python.
You need to write the code that does the counting of
the 'a's in the word and return the result.

Once you've done that you an call it as in the examples
provided.

Here is a simpler example:
Write a function, add2 that takes a number as input and returns the 
number plus 2.
Examples:

 >>> add2(3)
5
 >>> add2(8)
10

The code:

 >>> def add2(n):
...     return n+2

 >>> add2(4)
6

> 1. >>>def countA(apple):("a")
>
> 2. >>>print ("apple")
> def count('a')
>
> 3. >>>("apple").count("a")
>
> 4. >>>countA= apple.count ("a")
>
> #help me solve this

None of these are close because you haven't covered how to write 
functions yet.

That will appear (quite a bit) later in your tutorial.
To use a musical analogy, you have just learned the notes of
the scale and tried to do a homework that asks you to write
a song in waltz time.
It's too advanced for your current level of skill.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Wed Jul  2 00:08:36 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 01 Jul 2014 23:08:36 +0100
Subject: [Tutor] Installation Aborts
In-Reply-To: <003e01cf955f$92c3c910$b84b5b30$@verizon.net>
References: <003e01cf955f$92c3c910$b84b5b30$@verizon.net>
Message-ID: <lovbh4$674$2@ger.gmane.org>

On 01/07/14 20:06, Ted Gillam wrote:
> I?m trying to install 3..4.1. I downloads OK but about ? the way through
> it aborts. I?m new to this can anyone give me any help?
>
> Since the above is happening I downloaded 2.7.7. It seems to install OK
> but when I try to run the GUI interface nothing happens. Any help here?

I see a later post saying ignore this.
However, for future reference, if asking these kinds of questions you 
need to tell us:
1) What OS you are running
2) Where you got the Python installer(there are several available)
3) What architecture(32/64 bit)

And send a cut n paste of any error messages.

Without those details we can only make wild guesses.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From dyoo at hashcollision.org  Wed Jul  2 00:44:14 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Tue, 1 Jul 2014 15:44:14 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <CAKW-c0wxPkah-8wygyER_30jTCgsyvhixYQHjkYu-DXiSKLGPw@mail.gmail.com>
References: <loq4n9$jgl$1@ger.gmane.org>
 <CAKW-c0wxPkah-8wygyER_30jTCgsyvhixYQHjkYu-DXiSKLGPw@mail.gmail.com>
Message-ID: <CAGZAPF6TyU+7U-ry1fQZyoi+VufFHnsu8HHcPb5KxO3+A+Z=ZA@mail.gmail.com>

Yikes, I completely forgot about Dive Into Python!
http://www.diveintopython.net/

From peter.romfeld.hk at gmail.com  Wed Jul  2 05:51:44 2014
From: peter.romfeld.hk at gmail.com (Peter Romfeld)
Date: Wed, 02 Jul 2014 11:51:44 +0800
Subject: [Tutor] Image Upload FalconFramework
Message-ID: <53B381D0.8050707@gmail.com>

Hi,

I try to make a simple image upload function, in django i just used:

for feature phones:
file = request.body

rest:
file = request.FILES['image'].read()

with falcon i tried but not working
req.stream.read()

Their Freenode Channel is quite empty and it seems unused, so i hope i
could find someone here.

Cheers,
Peter

From s.shall at virginmedia.com  Wed Jul  2 15:36:36 2014
From: s.shall at virginmedia.com (Sydney Shall)
Date: Wed, 02 Jul 2014 15:36:36 +0200
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <53B2EA27.8050900@virginmedia.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
 <53B2EA27.8050900@virginmedia.com>
Message-ID: <53B40AE4.1070404@virginmedia.com>

On 01/07/2014 19:04, Sydney Shall wrote:
> I am a beginner and I have always had problems with inheritance.
>
> I can get inheritance to work with very simple classes.
> But with more complex classes, I find that inheritance seems to work 
> for simple variables, but I cannot get it to work with lists or arrays.
> Specifically my problem is to access a numpy array in the parent 
> class, from within the derived class.
> When I test with instances in IPython everything works properly.
> But I thought, perhaps wrongly, that with direct inheritance one does 
> not need instances.
> If one needs instances, how does one create them so that they are 
> correctly recognised.
>
> Perhaps, I need to read more about inheritance, Any suggestions for 
> reading would be welcome.
>
> With many thanks.
>
My apologies to the tutors.
I have identified my error, which was predictably elementary.
With many thanks,
Sydney

-- 
Sydney Shall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140702/8254391d/attachment.html>

From tedgillam at verizon.net  Wed Jul  2 17:03:32 2014
From: tedgillam at verizon.net (Ted Gillam)
Date: Wed, 02 Jul 2014 10:03:32 -0500
Subject: [Tutor] 2.7.7 Initial Problem
Message-ID: <00ad01cf9606$caa3b410$5feb1c30$@verizon.net>

I got a reply. I did what was suggested with no results. I'm trying 2.7.7. I
have a 64 bit 3.2 GHz AMD processor with 8gb of memory running Windows 7
Home Premium and 587gb of free disk space. It seems to install OK but when I
try to run the GUI a window opens and quickly closes. That's all.

 

Any other suggestions or people I should ask?

 

Thanks again, Ted

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140702/432f3600/attachment.html>

From breamoreboy at yahoo.co.uk  Wed Jul  2 20:12:02 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Wed, 02 Jul 2014 19:12:02 +0100
Subject: [Tutor] 2.7.7 Initial Problem
In-Reply-To: <00ad01cf9606$caa3b410$5feb1c30$@verizon.net>
References: <00ad01cf9606$caa3b410$5feb1c30$@verizon.net>
Message-ID: <lp1i1k$76n$1@ger.gmane.org>

On 02/07/2014 16:03, Ted Gillam wrote:
> I got a reply. I did what was suggested with no results. I?m trying
> 2.7.7. I have a 64 bit 3.2 GHz AMD processor with 8gb of memory running
> Windows 7 Home Premium and 587gb of free disk space. It seems to install
> OK but when I try to run the GUI a window opens and quickly closes.
> That?s all.
>
> Any other suggestions or people I should ask?
>
> Thanks again, Ted
>

Please give us data, we're good but we're not mind readers :)  How do 
you try to "run the GUI"?  What is "the GUI"?  Do you see a windows 
command prompt or something else?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From alan.gauld at btinternet.com  Wed Jul  2 23:08:27 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 02 Jul 2014 22:08:27 +0100
Subject: [Tutor] 2.7.7 Initial Problem
In-Reply-To: <00ad01cf9606$caa3b410$5feb1c30$@verizon.net>
References: <00ad01cf9606$caa3b410$5feb1c30$@verizon.net>
Message-ID: <lp1scb$8ck$1@ger.gmane.org>

On 02/07/14 16:03, Ted Gillam wrote:
> I got a reply. I did what was suggested with no results. I?m trying
> 2.7.7. I have a 64 bit 3.2 GHz AMD processor with 8gb of memory running
> Windows 7 Home Premium and 587gb of free disk space.

That should be fine.

How are you downloading and installing it?

For windows users I strongly recommend the ActiveState version of Python.

It has a lot of Windows extras and the installer does a more
thorough job of setting paths etc correctly. And its default
IDE is better than the cross platform IDLE.

> OK but when I try to run the GUI a window opens and quickly closes.
> That?s all.

What happens if you start a CMD prompt and type python?
You should get a Python >>> prompt.

If that works then Python is installed and you probably
have path issues.


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From mariopy at gmx.com  Fri Jul  4 02:37:38 2014
From: mariopy at gmx.com (Mario Py)
Date: Thu, 03 Jul 2014 18:37:38 -0600
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported from
	Excel
Message-ID: <53B5F752.1040403@gmx.com>

Windows 7, Python 3.4.0

I have a simple translation refresher program that works.
For input I'm using TXT file, (prevedi.txt) words in it are separated by 
coma that I'm editing, adding manually. (adding new 'refresher' words as 
needed) And program works:

from random import shuffle

print('Write translation of Slovene word ')
print()

with open('c:\\prevedi.txt', 'r', encoding='utf8') as f:
     lines = f.readlines()

shuffle(lines)

for line in lines:
     question, rightAnswer = line.strip().split(',')
     answer = input(question + ' ')
     if answer.lower() != rightAnswer:
         print('Correct is: %s.' % rightAnswer,)
         print()

I would like to be able to add more 'refresher' words in Excel instead 
of TXT fine and then export it to CSV file from Excel. I don't know how 
to adjust the code for this.

 From my tries you can see, I don't have a clue about programing.
I'm searching the internet and inserting pieces of code I found with the 
hope that program would work. Whatever I do, I get different error trace 
backs, too many to post here.

I know is it simple, trivial task but I'm just not up to it.
Can anyone help me please?

This is what I'm trying:

from random import shuffle
import csv

print('Write translation of Slovene word ')
print()

with open('c:\\prevedi.csv', 'r', newline='', encoding='utf8') as f:
# with open('c:\\prevedi.csv', 'r', newline='', encoding='utf8') as csv: 
tried this one, didn't work
     lines = f.readlines()
     # lines = csv.readlines(f) - this one doesn't work as well
     # lines = cvs.readlines() - neither this one...

shuffle(lines)

for line in lines:
     question, rightAnswer = line.strip().split(',')
     answer = input(question + ' ')
     if answer.lower() != rightAnswer:
         print('Correct is: %s.' % rightAnswer,)
         print()

I have a feeling, there is a problem with that 'as f:' part

Also, I probably don't need that strip part, csv import probably deals 
with it, but I don't know how much or which part to delete out...
Any time I try to change something, new trace error appears...
I'm out of ideas and tries... Who said even blind squirrel... ?

Thank you for helping me out,
Mario

From mariopy at gmx.com  Fri Jul  4 03:07:51 2014
From: mariopy at gmx.com (Mario Py)
Date: Thu, 03 Jul 2014 19:07:51 -0600
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
	from Excel
In-Reply-To: <53B5F752.1040403@gmx.com>
References: <53B5F752.1040403@gmx.com>
Message-ID: <53B5FE67.3000101@gmx.com>

OK, I'm finally getting closer.

Code bellow (looks like) works if I comment out shuffle part
But I need it to shuffle so I get random picked words.

How do I get shuffle part to work?


from random import shuffle
import csv

print('Write translation of Slovene word ')
print()

out=open('c:\\prevedi.csv', 'r', newline='', encoding='utf8')
data=csv.reader(out)

# shuffle(data)

for line in data:
     question, rightAnswer = line
     answer = input(question + ' ')
     if answer.lower() != rightAnswer:
         print('Correct is: %s.' % rightAnswer,)
         print()




From mitesh.budhabhatti at gmail.com  Fri Jul  4 07:44:07 2014
From: mitesh.budhabhatti at gmail.com (Mitesh H. Budhabhatti)
Date: Fri, 4 Jul 2014 11:14:07 +0530
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
	from Excel
In-Reply-To: <53B5FE67.3000101@gmx.com>
References: <53B5F752.1040403@gmx.com>
	<53B5FE67.3000101@gmx.com>
Message-ID: <CADv7osgXZf58WMWqWzZ86ij0zRQ-QYLxqNey0AMh4O0tywg3EA@mail.gmail.com>

Hello Mario,

I think if you are facing the problem with shuffle, can the below solution
help:

import random
import csv
f = open('D:\\py.csv', 'r', newline='', encoding='utf8')
csvreader = csv.reader(f)
l = [row for row in csvreader]     #we get rows in the file as a list using
list comprehension
random.shuffle(l)

Thanks

Warm Regards,
Mitesh H. Budhabhatti
Cell# +91 99040 83855


On Fri, Jul 4, 2014 at 6:37 AM, Mario Py <mariopy at gmx.com> wrote:
>
> OK, I'm finally getting closer.
>
> Code bellow (looks like) works if I comment out shuffle part
> But I need it to shuffle so I get random picked words.
>
> How do I get shuffle part to work?
>
>
>
> from random import shuffle
> import csv
>
> print('Write translation of Slovene word ')
> print()
>
> out=open('c:\\prevedi.csv', 'r', newline='', encoding='utf8')
> data=csv.reader(out)
>
> # shuffle(data)
>
> for line in data:
>     question, rightAnswer = line
>
>     answer = input(question + ' ')
>     if answer.lower() != rightAnswer:
>         print('Correct is: %s.' % rightAnswer,)
>         print()
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140704/8aed4c4e/attachment.html>

From alan.gauld at btinternet.com  Fri Jul  4 07:55:56 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 04 Jul 2014 06:55:56 +0100
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
	from Excel
In-Reply-To: <53B5FE67.3000101@gmx.com>
References: <53B5F752.1040403@gmx.com> <53B5FE67.3000101@gmx.com>
Message-ID: <lp5flc$lqo$1@ger.gmane.org>

On 04/07/14 02:07, Mario Py wrote:

> How do I get shuffle part to work?

look at the random module.
there are several options in there, I think random.shuffle()
is your best bet.

hth
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From breamoreboy at yahoo.co.uk  Fri Jul  4 08:19:38 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 04 Jul 2014 07:19:38 +0100
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
	from Excel
In-Reply-To: <CADv7osgXZf58WMWqWzZ86ij0zRQ-QYLxqNey0AMh4O0tywg3EA@mail.gmail.com>
References: <53B5F752.1040403@gmx.com>	<53B5FE67.3000101@gmx.com>
 <CADv7osgXZf58WMWqWzZ86ij0zRQ-QYLxqNey0AMh4O0tywg3EA@mail.gmail.com>
Message-ID: <lp5h10$48l$1@ger.gmane.org>

On 04/07/2014 06:44, Mitesh H. Budhabhatti wrote:
> Hello Mario,
>
> I think if you are facing the problem with shuffle, can the below
> solution help:
>
> import random
> import csv
> f = open('D:\\py.csv', 'r', newline='', encoding='utf8')
> csvreader = csv.reader(f)
> l = [row for row in csvreader]     #we get rows in the file as a list
> using list comprehension
> random.shuffle(l)
>
> Thanks
>
> Warm Regards,
> Mitesh H. Budhabhatti
> Cell# +91 99040 83855
>
> On Fri, Jul 4, 2014 at 6:37 AM, Mario Py <mariopy at gmx.com
> <mailto:mariopy at gmx.com>> wrote:
>  >
>  > OK, I'm finally getting closer.
>  >
>  > Code bellow (looks like) works if I comment out shuffle part
>  > But I need it to shuffle so I get random picked words.
>  >
>  > How do I get shuffle part to work?
>  >
>  > from random import shuffle
>  > import csv
>  >
>  > print('Write translation of Slovene word ')
>  > print()
>  >
>  > out=open('c:\\prevedi.csv', 'r', newline='', encoding='utf8')
>  > data=csv.reader(out)
>  >
>  > # shuffle(data)
>  >
>  > for line in data:
>  >     question, rightAnswer = line
>  >
>  >     answer = input(question + ' ')
>  >     if answer.lower() != rightAnswer:
>  >         print('Correct is: %s.' % rightAnswer,)
>  >         print()
>  >

I appreciate you trying to help out, but please don't top post on this 
list, it makes following longer threads very difficult, thanks .

Slight aside, it appears from "cell#" that you're in prison.  Is that 
the case, or did you actually mean "mobile phone number"? :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From __peter__ at web.de  Fri Jul  4 09:21:52 2014
From: __peter__ at web.de (Peter Otten)
Date: Fri, 04 Jul 2014 09:21:52 +0200
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
	from Excel
References: <53B5F752.1040403@gmx.com> <53B5FE67.3000101@gmx.com>
Message-ID: <lp5kmk$c3i$1@ger.gmane.org>

Mario Py wrote:

> OK, I'm finally getting closer.
> 
> Code bellow (looks like) works if I comment out shuffle part
> But I need it to shuffle so I get random picked words.
> 
> How do I get shuffle part to work?

csv.reader() returns an iterator, i. e. an object that dynamically 
calculates new rows on a next() call:

>>> f = open("tmp.csv")
>>> rows = csv.reader(f)
>>> next(rows)
['1', '2']
>>> next(rows)
['3', '4']

But shuffle() wants all items at once, in a "mutable sequence", an object 
with a length, whose items can be updated so that shuffle can swap items. 
The most common mutable sequence is a list, so

> from random import shuffle
> import csv
> 
> print('Write translation of Slovene word ')
> print()
> 
> out=open('c:\\prevedi.csv', 'r', newline='', encoding='utf8')
> data=csv.reader(out)

  data = list(data)
  shuffle(data)

> for line in data:
>      question, rightAnswer = line
>      answer = input(question + ' ')
>      if answer.lower() != rightAnswer:
>          print('Correct is: %s.' % rightAnswer,)
>          print()



From mitesh.budhabhatti at gmail.com  Fri Jul  4 09:55:58 2014
From: mitesh.budhabhatti at gmail.com (Mitesh H. Budhabhatti)
Date: Fri, 4 Jul 2014 13:25:58 +0530
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
	from Excel
In-Reply-To: <lp5h10$48l$1@ger.gmane.org>
References: <53B5F752.1040403@gmx.com> <53B5FE67.3000101@gmx.com>
 <CADv7osgXZf58WMWqWzZ86ij0zRQ-QYLxqNey0AMh4O0tywg3EA@mail.gmail.com>
 <lp5h10$48l$1@ger.gmane.org>
Message-ID: <CADv7osjYGp2abAsvfaJMpCn2iU4UF5xOZhT3Ki88znMuZp_ULw@mail.gmail.com>

>
> Slight aside, it appears from "cell#" that you're in prison.  Is that the
> case, or did you actually mean "mobile phone number"? :)

Sorry for that.. I use gmail and I just missed to remove my signature.
 Replying here for the first time and learning etiquette.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140704/487dc8e8/attachment-0001.html>

From shenoy.sunil.r at gmail.com  Fri Jul  4 20:35:46 2014
From: shenoy.sunil.r at gmail.com (Sunil Shenoy)
Date: Fri, 4 Jul 2014 11:35:46 -0700
Subject: [Tutor] Python programming book material
Message-ID: <CAFcacJXf_p_pr+QrgWwM2wR8tn+ffb455xk2xuNpiwvSJo-DOA@mail.gmail.com>

Hello
I have just started to try and learn Python and purchased Dawson's book for
the absolute beginner. I cannot find the material referred to under
www.courseptr.... etc. Can you please help? I have the 3rd edition of the
book.
I did get Python installed etc. and tried some code fragments and right
away run into a syntax error in the following line:
print ("June", end=" ")
flags an error:
print ("a", end=" ")
SyntaxError: invalid syntax
Thanks for addressing my stupid beginner questions
Sunil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140704/d8ac4f8d/attachment.html>

From xperimental22 at gmail.com  Fri Jul  4 22:24:56 2014
From: xperimental22 at gmail.com (jh)
Date: Fri, 4 Jul 2014 16:24:56 -0400
Subject: [Tutor] Python programming book material
In-Reply-To: <CAFcacJXf_p_pr+QrgWwM2wR8tn+ffb455xk2xuNpiwvSJo-DOA@mail.gmail.com>
References: <CAFcacJXf_p_pr+QrgWwM2wR8tn+ffb455xk2xuNpiwvSJo-DOA@mail.gmail.com>
Message-ID: <01c901cf97c6$067feec0$137fcc40$@gmail.com>

 

From: Tutor [mailto:tutor-bounces+xperimental22=gmail.com at python.org] On Behalf Of Sunil Shenoy
Sent: Friday, July 04, 2014 2:36 PM
To: tutor at python.org
Subject: [Tutor] Python programming book material

 

Hello

I have just started to try and learn Python and purchased Dawson's book for the absolute beginner. I cannot find the material referred to under www.courseptr.... etc. 

 

__ snip__

 

Try here: http://www.programgames.com/

 

J

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140704/5af25f83/attachment.html>

From alan.gauld at btinternet.com  Sat Jul  5 00:07:29 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 04 Jul 2014 23:07:29 +0100
Subject: [Tutor] Python programming book material
In-Reply-To: <CAFcacJXf_p_pr+QrgWwM2wR8tn+ffb455xk2xuNpiwvSJo-DOA@mail.gmail.com>
References: <CAFcacJXf_p_pr+QrgWwM2wR8tn+ffb455xk2xuNpiwvSJo-DOA@mail.gmail.com>
Message-ID: <lp78j1$h10$1@ger.gmane.org>

On 04/07/14 19:35, Sunil Shenoy wrote:

> I did get Python installed etc. and tried some code fragments and right
> away run into a syntax error in the following line:
> print ("June", end=" ")

Looks like your book is for Python v3 but you have installed Python v2.

You need to get v3.

If you are using a Windows PC I recommend the ActiveState.com
version over the official p[ython.org one.

> Thanks for addressing my stupid beginner questions

Its not stupid and catches a lot of people out.
There were big changes between V2 and V3.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From mariopy at gmx.com  Sat Jul  5 02:52:18 2014
From: mariopy at gmx.com (Mario Py)
Date: Fri, 04 Jul 2014 18:52:18 -0600
Subject: [Tutor] Instead of *.TXT I would like to use *.CSV exported
 from Excel
In-Reply-To: <lp5kmk$c3i$1@ger.gmane.org>
References: <53B5F752.1040403@gmx.com> <53B5FE67.3000101@gmx.com>
 <lp5kmk$c3i$1@ger.gmane.org>
Message-ID: <53B74C42.9000207@gmx.com>

On 7/4/2014 1:21 AM, Peter Otten wrote:
> data = list(data)
>    shuffle(data)

Peter, Mitesh and Alan,

Thank you for your help! And thank you for explaining details.
Now I understand why it worked in my previous (*.TXT) version since it 
was already as list.

Thanks again, program works great now!

Mario

From codemonkey at inbox.com  Sat Jul  5 19:31:53 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 5 Jul 2014 09:31:53 -0800
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
Message-ID: <64B1761BA47.0000032Acodemonkey@inbox.com>

I am betting that a big reason newbies don't go straight to documentation for answers is because of the useless quick search.  You should be able to type 'dictionary' and get links to the dictionary info.  You get a bunch of links that are meaningless to someone who wants to learn about how to use dictionaries.  It frustrates me to death when I want to look up a detail about how a particular function works and I can't find it because quick search doesn't provide the link to the BASIC information.

Another example of what I am talking about, I just did a search of max(), a BUILT-IN function.  This is what quick search gives me:

Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories.

What is up with that???

I realize that this list doesn't have control over python.org, but there are enough of you who are experts about all this stuff that maybe some changes can be made.  If I ever learn enough, I hope to be part of the solution myself.  A working search engine would be most helpful.

Yes, I use Google all that time. But quick search should be useful. Thanks in advance for any insights and help.
  

Deb in WA, USA

____________________________________________________________
Receive Notifications of Incoming Messages
Easily monitor multiple email accounts & access them with a click.
Visit http://www.inbox.com/notifier and check it out!



From illusiontechniques at gmail.com  Sat Jul  5 19:46:18 2014
From: illusiontechniques at gmail.com (C Smith)
Date: Sat, 5 Jul 2014 13:46:18 -0400
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <64B1761BA47.0000032Acodemonkey@inbox.com>
References: <64B1761BA47.0000032Acodemonkey@inbox.com>
Message-ID: <CAL2Y8-SDfK=UMdZEaP1zxprzQf8O0E2jybVYCE1nPky618PtRA@mail.gmail.com>

I agree very much. I feel like I might have a learning disability when
I try to reference the official Python docs for something that seems
like it should be a very common task.

On Sat, Jul 5, 2014 at 1:31 PM, Deb Wyatt <codemonkey at inbox.com> wrote:
> I am betting that a big reason newbies don't go straight to documentation for answers is because of the useless quick search.  You should be able to type 'dictionary' and get links to the dictionary info.  You get a bunch of links that are meaningless to someone who wants to learn about how to use dictionaries.  It frustrates me to death when I want to look up a detail about how a particular function works and I can't find it because quick search doesn't provide the link to the BASIC information.
>
> Another example of what I am talking about, I just did a search of max(), a BUILT-IN function.  This is what quick search gives me:
>
> Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories.
>
> What is up with that???
>
> I realize that this list doesn't have control over python.org, but there are enough of you who are experts about all this stuff that maybe some changes can be made.  If I ever learn enough, I hope to be part of the solution myself.  A working search engine would be most helpful.
>
> Yes, I use Google all that time. But quick search should be useful. Thanks in advance for any insights and help.
>
>
> Deb in WA, USA
>
> ____________________________________________________________
> Receive Notifications of Incoming Messages
> Easily monitor multiple email accounts & access them with a click.
> Visit http://www.inbox.com/notifier and check it out!
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From breamoreboy at yahoo.co.uk  Sat Jul  5 20:26:41 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sat, 05 Jul 2014 19:26:41 +0100
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <64B1761BA47.0000032Acodemonkey@inbox.com>
References: <64B1761BA47.0000032Acodemonkey@inbox.com>
Message-ID: <lp9g0f$sgu$1@ger.gmane.org>

On 05/07/2014 18:31, Deb Wyatt wrote:
> I am betting that a big reason newbies don't go straight to documentation for answers is because of the useless quick search.  You should be able to type 'dictionary' and get links to the dictionary info.  You get a bunch of links that are meaningless to someone who wants to learn about how to use dictionaries.  It frustrates me to death when I want to look up a detail about how a particular function works and I can't find it because quick search doesn't provide the link to the BASIC information.
>
> Another example of what I am talking about, I just did a search of max(), a BUILT-IN function.  This is what quick search gives me:
>
> Your search did not match any documents. Please make sure that all words are spelled correctly and that you've selected enough categories.
>
> What is up with that???
>
> I realize that this list doesn't have control over python.org, but there are enough of you who are experts about all this stuff that maybe some changes can be made.  If I ever learn enough, I hope to be part of the solution myself.  A working search engine would be most helpful.
>
> Yes, I use Google all that time. But quick search should be useful. Thanks in advance for any insights and help.
>
>
> Deb in WA, USA
>

It's known to be useless so don't bother, use a google site specific 
search instead.

Aside, your paragraphs are on one line, hope you're not using the 
dreaded google groups? :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From varunaseneviratna at gmail.com  Sat Jul  5 20:09:53 2014
From: varunaseneviratna at gmail.com (Varuna Seneviratna)
Date: Sat, 5 Jul 2014 23:39:53 +0530
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <loq4n9$jgl$1@ger.gmane.org>
References: <loq4n9$jgl$1@ger.gmane.org>
Message-ID: <CAKW-c0wxRCh63vtdEzJOUr_nfZdymvJdfY+80hQEqc6nUBxXsw@mail.gmail.com>

On 30 June 2014 04:11, Alan Gauld <alan.gauld at btinternet.com> wrote:
> I'm looking for tips for an appendix to a book that
> I'm working on.
>
> What are the best unofficial (ie not python.org)
> resources for people who have learned the basics
> but are not experts yet? ie Typical tutor list
> "graduates"...
>
> I'm thinking about web sites, blogs, books, videos etc.
> Anything that might be worth knowing about.
>
> I've got a few of my own - Activestate, O'Reilly,
> ByteOfPython, PythonChallenge, ShowMeDo etc.
>
> But I thought the tutor list readers might be an
> interesting source of alternatives that I hadn't
> thought of, or even heard of.
>
> All contributions considered :-)
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


I got the following link from the Pycoder's weekly
newsletter(http://pycoders.com/)
http://www.reddit.com/r/Python/comments/29qd6x/ask_recommended_python_books_for_experienced/

From codemonkey at inbox.com  Sat Jul  5 20:40:07 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 5 Jul 2014 10:40:07 -0800
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <lp9g0f$sgu$1@ger.gmane.org>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
Message-ID: <6549F8D2F15.000003A7codemonkey@inbox.com>


> -----Original Message-----
> From: breamoreboy at yahoo.co.uk
> Sent: Sat, 05 Jul 2014 19:26:41 +0100
> To: tutor at python.org
> Subject: Re: [Tutor] Why is Quick Search at docs.Python.org so useless?
> 
> On 05/07/2014 18:31, Deb Wyatt wrote:
>> I am betting that a big reason newbies don't go straight to
>> documentation for answers is because of the useless quick search.  You
>> should be able to type 'dictionary' and get links to the dictionary
>> info.  You get a bunch of links that are meaningless to someone who
>> wants to learn about how to use dictionaries.  It frustrates me to death
>> when I want to look up a detail about how a particular function works
>> and I can't find it because quick search doesn't provide the link to the
>> BASIC information.
>> 
>> Another example of what I am talking about, I just did a search of
>> max(), a BUILT-IN function.  This is what quick search gives me:
>> 
>> Your search did not match any documents. Please make sure that all words
>> are spelled correctly and that you've selected enough categories.
>> 
>> What is up with that???
>> 
>> I realize that this list doesn't have control over python.org, but there
>> are enough of you who are experts about all this stuff that maybe some
>> changes can be made.  If I ever learn enough, I hope to be part of the
>> solution myself.  A working search engine would be most helpful.
>> 
>> Yes, I use Google all that time. But quick search should be useful.
>> Thanks in advance for any insights and help.
>> 
>> 
>> Deb in WA, USA
>> 
> 
> It's known to be useless so don't bother, use a google site specific
> search instead.
> 
> Aside, your paragraphs are on one line, hope you're not using the
> dreaded google groups? :)
> 
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence
> 

It shouldn't be useless.

No I'm NOT using goggle groups.  I'd be using a news reader if accessing
news was still free.  I'm just using an on-line email provider with text only,
and a subscription to the group.  I was not aware that Python Tutor was
even available in Google groups...

Hey, what you can do for your language is help make the search useful.  

Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



From fomcl at yahoo.com  Sat Jul  5 20:37:27 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Sat, 5 Jul 2014 11:37:27 -0700
Subject: [Tutor] What are your favourite unofficial resources
Message-ID: <1404585447.52508.BPMail_high_noncarrier@web163803.mail.gq1.yahoo.com>






------------------------------
On Sat, Jul 5, 2014 8:09 PM CEST Varuna Seneviratna wrote:

>On 30 June 2014 04:11, Alan Gauld <alan.gauld at btinternet.com> wrote:
>> I'm looking for tips for an appendix to a book that
>> I'm working on.
>>
>> What are the best unofficial (ie not python.org)
>> resources for people who have learned the basics
>> but are not experts yet? ie Typical tutor list
>> "graduates"...
>>
>> I'm thinking about web sites, blogs, books, videos etc.
>> Anything that might be worth knowing about.
>>
>> I've got a few of my own - Activestate, O'Reilly,
>> ByteOfPython, PythonChallenge, ShowMeDo etc.
>>
>> But I thought the tutor list readers might be an
>> interesting source of alternatives that I hadn't
>> thought of, or even heard of.
>>
>> All contributions considered :-)
>>
>> --
>> Alan G
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>> http://www.flickr.com/photos/alangauldphotos
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>
>
>I got the following link from the Pycoder's weekly
>newsletter(http://pycoders.com/)
>http://www.reddit.com/r/Python/comments/29qd6x/ask_recommended_python_books_for_experienced/

For tkinter, this is a great resource: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html 

From breamoreboy at yahoo.co.uk  Sat Jul  5 20:53:48 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sat, 05 Jul 2014 19:53:48 +0100
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <6549F8D2F15.000003A7codemonkey@inbox.com>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com>
Message-ID: <lp9hj6$e04$1@ger.gmane.org>

On 05/07/2014 19:40, Deb Wyatt wrote:
>
>> -----Original Message-----
>> From: breamoreboy at yahoo.co.uk
>> Sent: Sat, 05 Jul 2014 19:26:41 +0100
>> To: tutor at python.org
>> Subject: Re: [Tutor] Why is Quick Search at docs.Python.org so useless?
>>
>> On 05/07/2014 18:31, Deb Wyatt wrote:
>>> I am betting that a big reason newbies don't go straight to
>>> documentation for answers is because of the useless quick search.  You
>>> should be able to type 'dictionary' and get links to the dictionary
>>> info.  You get a bunch of links that are meaningless to someone who
>>> wants to learn about how to use dictionaries.  It frustrates me to death
>>> when I want to look up a detail about how a particular function works
>>> and I can't find it because quick search doesn't provide the link to the
>>> BASIC information.
>>>
>>> Another example of what I am talking about, I just did a search of
>>> max(), a BUILT-IN function.  This is what quick search gives me:
>>>
>>> Your search did not match any documents. Please make sure that all words
>>> are spelled correctly and that you've selected enough categories.
>>>
>>> What is up with that???
>>>
>>> I realize that this list doesn't have control over python.org, but there
>>> are enough of you who are experts about all this stuff that maybe some
>>> changes can be made.  If I ever learn enough, I hope to be part of the
>>> solution myself.  A working search engine would be most helpful.
>>>
>>> Yes, I use Google all that time. But quick search should be useful.
>>> Thanks in advance for any insights and help.
>>>
>>>
>>> Deb in WA, USA
>>>
>>
>> It's known to be useless so don't bother, use a google site specific
>> search instead.
>>
>> Aside, your paragraphs are on one line, hope you're not using the
>> dreaded google groups? :)
>>
>> --
>> My fellow Pythonistas, ask not what our language can do for you, ask
>> what you can do for our language.
>>
>> Mark Lawrence
>>
>
> It shouldn't be useless.
>
> No I'm NOT using goggle groups.  I'd be using a news reader if accessing
> news was still free.  I'm just using an on-line email provider with text only,
> and a subscription to the group.  I was not aware that Python Tutor was
> even available in Google groups...
>
> Hey, what you can do for your language is help make the search useful.
>
> Deb in WA, USA
>

As I said it's a known problem, but then so are the 4600 bugs at 
bugs.python.org.  So why bother spending the time making the search 
useful when there is a well known workaround, I prefer my time to go on 
the bug tracker.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From dyoo at hashcollision.org  Sat Jul  5 23:26:36 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sat, 5 Jul 2014 14:26:36 -0700
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <64B1761BA47.0000032Acodemonkey@inbox.com>
References: <64B1761BA47.0000032Acodemonkey@inbox.com>
Message-ID: <CAGZAPF5u9pcN9oLyMXtDTMTqwxkSVSut4bGX5eCx-LFnMv68bQ@mail.gmail.com>

> I realize that this list doesn't have control over python.org, but there
are enough of you who are experts about all this stuff that maybe some
changes can be made.  If I ever learn enough, I hope to be part of the
solution myself.  A working search engine would be most helpful.

Hi Deb,

Yeah, unfortunately I don't think anyone here is part of the group that
manages the web site.  You might want to contact them directly?  I think
you should be able to reach them at:

https://www.python.org/dev/pydotorg/

It would be good if the web page search engine were to be improved.  Let's
get the feedback to the right people so that it can be fixed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140705/d9bec625/attachment.html>

From codemonkey at inbox.com  Sat Jul  5 23:48:48 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 5 Jul 2014 13:48:48 -0800
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <CAGZAPF5u9pcN9oLyMXtDTMTqwxkSVSut4bGX5eCx-LFnMv68bQ@mail.gmail.com>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
Message-ID: <66EFB94B84C.0000049Ecodemonkey@inbox.com>



> -----Original Message-----
> From: dyoo at hashcollision.org
> Sent: Sat, 5 Jul 2014 14:26:36 -0700
> To: codemonkey at inbox.com
> Subject: Re: [Tutor] Why is Quick Search at docs.Python.org so useless?
> 
>> I realize that this list doesn't have control over python.org, but there
> are enough of you who are experts about all this stuff that maybe some
> changes can be made.  If I ever learn enough, I hope to be part of the
> solution myself.  A working search engine would be most helpful.
> 
> Hi Deb,
> 
> Yeah, unfortunately I don't think anyone here is part of the group that
> manages the web site.  You might want to contact them directly?  I think
> you should be able to reach them at:
> 
> https://www.python.org/dev/pydotorg/
> 
> It would be good if the web page search engine were to be improved.
> Let's
> get the feedback to the right people so that it can be fixed.

Thank you for the link.  That is very helpful.
Deb in WA, USA

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth



From emile at fenx.com  Sun Jul  6 17:43:49 2014
From: emile at fenx.com (Emile van Sebille)
Date: Sun, 06 Jul 2014 08:43:49 -0700
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <6549F8D2F15.000003A7codemonkey@inbox.com>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com>
Message-ID: <lpbqs7$gcr$1@ger.gmane.org>

On 7/5/2014 11:40 AM, Deb Wyatt wrote:

> I'd be using a news reader if accessing
> news was still free.

Try news.gmane.org.

Emile


From memilanuk at gmail.com  Sun Jul  6 20:08:08 2014
From: memilanuk at gmail.com (memilanuk)
Date: Sun, 06 Jul 2014 11:08:08 -0700
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <lp9hj6$e04$1@ger.gmane.org>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com> <lp9hj6$e04$1@ger.gmane.org>
Message-ID: <lpc3a8$8vg$1@ger.gmane.org>

On 07/05/2014 11:53 AM, Mark Lawrence wrote:
>
> As I said it's a known problem, but then so are the 4600 bugs at
> bugs.python.org.  So why bother spending the time making the search
> useful when there is a well known workaround

Because it's supposed to be the first place new (and old) users go to 
find their answers.

Because the work-around isn't published right *there* where people who 
aren't 'in the know' would expect to find it.

Because it looks kind of sketchy that the search function of the main 
documentation section of *the* primary web site for a programming 
language doesn't work right, and hasn't for some time even though its a 
'well-known' issue because it isn't considered a sexy enough problem to 
be addressed.

In my mind, that doesn't say very many *good* things about that language...

And before you say, 'Go for it, fix it yourself'... I'm one of those 
new-ish folks myself, and you probably don't want me tinkering around 
anywhere near the guts of any search engine ;)






From breamoreboy at yahoo.co.uk  Sun Jul  6 20:55:01 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sun, 06 Jul 2014 19:55:01 +0100
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <lpc3a8$8vg$1@ger.gmane.org>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com> <lp9hj6$e04$1@ger.gmane.org>
 <lpc3a8$8vg$1@ger.gmane.org>
Message-ID: <lpc625$c06$1@ger.gmane.org>

On 06/07/2014 19:08, memilanuk wrote:
> On 07/05/2014 11:53 AM, Mark Lawrence wrote:
>>
>> As I said it's a known problem, but then so are the 4600 bugs at
>> bugs.python.org.  So why bother spending the time making the search
>> useful when there is a well known workaround
>
> Because it's supposed to be the first place new (and old) users go to
> find their answers.
>

Not for me.  I'm on Windows and have a link on my desktop to the 
compiled help file for (currently) Python 3.4.1 that comes as part of 
the installation process.  I can find everything I need there in no time.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From dyoo at hashcollision.org  Sun Jul  6 22:57:19 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 6 Jul 2014 13:57:19 -0700
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <lpc625$c06$1@ger.gmane.org>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com>
 <lp9hj6$e04$1@ger.gmane.org> <lpc3a8$8vg$1@ger.gmane.org>
 <lpc625$c06$1@ger.gmane.org>
Message-ID: <CAGZAPF7sUBT05k1biS0MO76OiZKC4aQjDqWx1xsy1mr5ChaT-g@mail.gmail.com>

Let's summarize.  As it stands, this really is out of our direct
control, as Deb mentions.


The actions we can do seems to be:

  1.  To point folks to alternative search engines that are effective
in searching through Python documentation.

  2.  Direct feedback to the Python web site maintainers so that
either they fix the problem or are at least aware that something is
deficient.

  3.  Raise a call for volunteers.

  4.  Ignore.


I think all these actions have been proposed or approached in this thread.

* I think option #2 is ultimately the right long-term approach.  Given
that it's long term, I don't think the fix will come quickly, but as
long as the right people are notified about the problem, I trust it
will get fixed eventually.  I believe
https://www.python.org/dev/pydotorg/ should have links to the right
people.

* In my opinion, option #3 is probably more suited for a general
Python forum, rather than on Python-Tutor.  If we want to do that, I
think python-list or docs-sig are the right forums to do this:

    https://mail.python.org/mailman/listinfo/python-list
    https://mail.python.org/mailman/listinfo/docs

* Option #1 appears to work effectively on the example given in the
original post.  A search for the term [python max] reaches relevant
documentation on the major search engines.

* I will ignore option #4.

Other than those options, is there anything we're missing or anything
to add to the conversation?

From dyoo at hashcollision.org  Sun Jul  6 23:06:50 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 6 Jul 2014 14:06:50 -0700
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <53B40AE4.1070404@virginmedia.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
 <53B2EA27.8050900@virginmedia.com> <53B40AE4.1070404@virginmedia.com>
Message-ID: <CAGZAPF5aXm5s7qA2fVcTD5RNkLOBrMj7m0AVqWCmKSKHnhv3Vg@mail.gmail.com>

> My apologies to the tutors.
> I have identified my error, which was predictably elementary.
> With many thanks,


By the way, can you say what your conceptual error was or give an
example?  It might help the other folks here who are learning and who
may be making a similar mistake.  (And I'm curious!)  But if you don't
want to say, that's ok too.


Good luck!

From marc.tompkins at gmail.com  Sun Jul  6 23:44:11 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 6 Jul 2014 14:44:11 -0700
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <CAGZAPF7sUBT05k1biS0MO76OiZKC4aQjDqWx1xsy1mr5ChaT-g@mail.gmail.com>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com>
 <lp9hj6$e04$1@ger.gmane.org> <lpc3a8$8vg$1@ger.gmane.org>
 <lpc625$c06$1@ger.gmane.org>
 <CAGZAPF7sUBT05k1biS0MO76OiZKC4aQjDqWx1xsy1mr5ChaT-g@mail.gmail.com>
Message-ID: <CAKK8jXYE8yuDnQahNUvzy5CSpY7PmrWGNddo6aTm6eJO4fxHXg@mail.gmail.com>

On Sun, Jul 6, 2014 at 1:57 PM, Danny Yoo <dyoo at hashcollision.org> wrote:

>  2.  Direct feedback to the Python web site maintainers so that either
they fix the problem or are at least aware that something is deficient.

Google offers a per-site custom search; it's free for very basic
functionality and not very expensive for the whole enchilada.  (In any
case, Google has got enough value out of Python over the years that I bet
they'd provide it for free, if asked.)  I suppose there might be a bit of
DIY pride to be lost in using an out-of-the box solution, but...

>  4.  Ignore.
>  * I will ignore option #4.

I see what you did there.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140706/5fb18515/attachment.html>

From breamoreboy at yahoo.co.uk  Mon Jul  7 00:59:45 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sun, 06 Jul 2014 23:59:45 +0100
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <CAGZAPF7sUBT05k1biS0MO76OiZKC4aQjDqWx1xsy1mr5ChaT-g@mail.gmail.com>
References: <64b1761ba47.0000032acodemonkey@inbox.com>
 <6549F8D2F15.000003A7codemonkey@inbox.com> <lp9hj6$e04$1@ger.gmane.org>
 <lpc3a8$8vg$1@ger.gmane.org> <lpc625$c06$1@ger.gmane.org>
 <CAGZAPF7sUBT05k1biS0MO76OiZKC4aQjDqWx1xsy1mr5ChaT-g@mail.gmail.com>
Message-ID: <lpckcn$bjq$1@ger.gmane.org>

On 06/07/2014 21:57, Danny Yoo wrote:
> Let's summarize.  As it stands, this really is out of our direct
> control, as Deb mentions.
>
> The actions we can do seems to be:
>
>    2.  Direct feedback to the Python web site maintainers so that
> either they fix the problem or are at least aware that something is
> deficient.
>

This has been known about for years.  If my understanding is correct 
much of the web support is done on the same basis as (c)Python support, 
i.e. volunteers.  Given that the completely updated site only went live 
within the past few months, I believe that fixing the search was not 
very high up the priority list, possibly not even on it :(

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From assp1r1n3 at gmail.com  Sun Jul  6 23:00:38 2014
From: assp1r1n3 at gmail.com (Ali Mammadov)
Date: Sun, 6 Jul 2014 23:00:38 +0200
Subject: [Tutor] Resuming one block of code continuously after exception in
	try/except construction
Message-ID: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>

Hello fellow coders!
Today I encountered a small difficulty while working with files.As a common
pratice, I want my function to check user's input(in this case it's file
name) and re-ask it again and again(until correct) offering him two
choices: re-enter file name or close program.I've decided to use try/except
construction in this particular task. After a bit of googling, I still
didn't figure out how and if it's possible to re-run code in try part again
if exception raises. Should I use try/except or you would recommend me
another way(god bless, we have plenty of them! :))? What are the pros&cons
of this method?

BTW, I created a small gist located here
<https://gist.github.com/bca59570ea5fd365c672> which demonstrates my
problem.

Thank you in advance for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140706/e68017c9/attachment.html>

From alan.gauld at btinternet.com  Mon Jul  7 01:28:24 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 07 Jul 2014 00:28:24 +0100
Subject: [Tutor] Resuming one block of code continuously after exception
 in try/except construction
In-Reply-To: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
References: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
Message-ID: <lpcm2p$rjs$1@ger.gmane.org>

On 06/07/14 22:00, Ali Mammadov wrote:

> common pratice, I want my function to check user's input(in this case
> it's file name) and re-ask it again and again(until correct) offering
> him two choices: re-enter file name or close program.I've decided to use
> try/except construction in this particular task.

Thats the wrong solution.
try/except is for catching errors not repeating actions.
You need to combine the try/except with a loop.

> BTW, I created a small gist located here
> <https://gist.github.com/bca59570ea5fd365c672> which demonstrates my
> problem.

For short (<100lines) example just post it in your message, it saves a 
lot of extra jumping around. Here it is:

---------------
def makelgpwdcombs(brutelistname):
	try:
		blst = open(brutelistname, 'r')
	except:
		print("[-] Invalid file name or insufficient priviliges")
	else:
		print("[+] File opened. Working...")
--------------------

Drop the else clause and put the try/except inside a while...

def makelgpwdcombs(brutelistname):
     while True:
        try:
	  blst = open(brutelistname, 'r')
           break # exit loop if no error
        except:
           print("[-] Invalid file name or insufficient priviliges")

     print("[+] File opened. Working...")   # only after valid input

loops are for repeating, try/except is for catching errors.
Use the right tool for the job.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Mon Jul  7 01:34:03 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 07 Jul 2014 00:34:03 +0100
Subject: [Tutor] Resuming one block of code continuously after exception
 in try/except construction
In-Reply-To: <lpcm2p$rjs$1@ger.gmane.org>
References: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
 <lpcm2p$rjs$1@ger.gmane.org>
Message-ID: <lpcmdb$tbr$2@ger.gmane.org>

On 07/07/14 00:28, Alan Gauld wrote:

> Drop the else clause and put the try/except inside a while...
>
> def makelgpwdcombs(brutelistname):
>      while True:
>        try:
>         blst = open(brutelistname, 'r')
>            break # exit loop if no error

oops, indentation error there. Sorry
       while True:
           try:
              blst = open(brutelistname, 'r')
              break # exit loop if no error

>         except:
>            print("[-] Invalid file name or insufficient priviliges")
>
>      print("[+] File opened. Working...")   # only after valid input


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Mon Jul  7 01:31:37 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 07 Jul 2014 00:31:37 +0100
Subject: [Tutor] Resuming one block of code continuously after exception
 in try/except construction
In-Reply-To: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
References: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
Message-ID: <lpcm8p$tbr$1@ger.gmane.org>

On 06/07/14 22:00, Ali Mammadov wrote:

> BTW, I created a small gist located here
> <https://gist.github.com/bca59570ea5fd365c672> which demonstrates my
> problem.

I forgot one other thing...

-----------------
def makelgpwdcombs(brutelistname):
     try:
	blst = open(brutelistname, 'r')
     except:
	print("[-] Invalid file name or insufficient priviliges")--


Don't use a bare except here./ catch the specific errror(s) you expect 
to get. In this case its probably IOError...

Then any unexpected errors will generate a stacktrace and not a 
confusing (and wrong) error message



Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From steve at pearwood.info  Mon Jul  7 05:19:11 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Mon, 7 Jul 2014 13:19:11 +1000
Subject: [Tutor] Resuming one block of code continuously after exception
	in try/except construction
In-Reply-To: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
References: <CAPWQhd5TxRDnatO_=gC6+=TxaUPzwOqhWLVRF+TvkrWtJaQCcw@mail.gmail.com>
Message-ID: <20140707031911.GC13014@ando>

On Sun, Jul 06, 2014 at 11:00:38PM +0200, Ali Mammadov wrote:
> Hello fellow coders!
> Today I encountered a small difficulty while working with files.As a common
> pratice, I want my function to check user's input(in this case it's file
> name) and re-ask it again and again(until correct) offering him two
> choices: re-enter file name or close program.I've decided to use try/except
> construction in this particular task. After a bit of googling, I still
> didn't figure out how and if it's possible to re-run code in try part again
> if exception raises.

That's kind of tricky, because you have two different exceptional 
circumstances, and you want to do something different in each case. 
The best way, I think, is two separate the two parts into two 
functions:


import sys

def get_filename(extra_prompt):
    if extra_prompt:
        print(extra_prompt)
    print("Enter a file name, or type Ctrl-D to exit the program.")
    # On Windows, I think you need Ctrl-Z [enter] instead of Ctrl-D.
    try:
        return input("File name: ")  # Use raw_input in Python 2.
    except EOFError:
        sys.exit()


def get_file():
    f = None
    prompt = ""
    while f is None:
        name = get_filename(prompt)
        try:
            f = open(name, "r")
        # Python 3 exceptions. For Python 2, see below.
        except FileNotFoundError:
            prompt = "File not found; please try again."
        except IsADirectoryError:
            prompt = "That is a directory; please try again."
        except PermissionError:
            prompt = ("You do not have permission to open that"
                      + " file. Please try again.")
        # This must come last.
        except IOError as err:
            prompt = "%s : please try again." % err
    return f


with get_file() as f:
    for line in f:
         print(line)




In Python 2, we don't have all the different sorts of exceptions. 
Instead, you have to catch IOError only, and then inspect the errno 
attribute of the exception to find out what it is:

        try:
            f = open(name, "r")
        except IOError as err:
            if err.errno == 2:
                prompt = "File not found; please try again."
            elif err.errno == 21:
                prompt = "That is a directory; please try again."
            elif err.errno == 13:
                prompt = ("You do not have permission to open that"
                          + " file. Please try again.")


Unfortunately, the error codes can be different on different operating 
systems. To write platform-independent code, you should import the errno 
module and check the error code by name:

           if err.errno == errno.ENOENT:

etc.



-- 
Steven

From cs at zip.com.au  Mon Jul  7 06:08:47 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Mon, 7 Jul 2014 14:08:47 +1000
Subject: [Tutor] Why is Quick Search at docs.Python.org so useless?
In-Reply-To: <6549F8D2F15.000003A7codemonkey@inbox.com>
References: <6549F8D2F15.000003A7codemonkey@inbox.com>
Message-ID: <20140707040847.GA29399@cskk.homeip.net>

Not a fix, but I for one always start at the index:

   https://docs.python.org/3/genindex.html

(or the python 2 version) for ad hoc stuff.

For speed and convenience I always have a fairly current copy of the docs on my 
desktop, making browsing them near instant.
-- 

Each new user of a new system uncovers a new class of bugs.     - Kernighan

From pamela.wightley at morgij.com.au  Mon Jul  7 07:10:16 2014
From: pamela.wightley at morgij.com.au (Pamela Wightley)
Date: Mon, 7 Jul 2014 05:10:16 +0000
Subject: [Tutor] Python Socket Error: Connection refused
Message-ID: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>

Hi,

I need some help, I  have no programming skills and am trying to teach myself python. I keep on getting an error message as follows:

Socket Error: Connection refused,

and the following error as well


[cid:image001.png at 01CF99F5.90253AF0]


Any assistance is appreciated.

Pamela Wightley
[MorgijAnalytics e-sig][MorgijAnalytics e-apple]
Level 3 | 10 Bond Street |  Sydney | NSW 2000 | Australia
[P] (02) 8197 1828 |  [M] 0400 892 714  |
pamela.wightley at morgij.com.au<mailto:pamela.wightley at morgij.com.au>  |  www.morgij.com.au<http://www.morgij.com.au/> |   www.marqservices.com<http://www.morgij.com.au/>

The contents of this email and any attachments are strictly confidential and intended solely for the attention and use of the named addressee(s). If you are not the intended recipient you are not authorised to and must not disclose, copy, distribute, or retain this message without our authority. This email and all of its contents are subject to copyright. If you have received this email in error, please notify the sender by a return e-mail immediately. Please note that we do not accept responsibility for viruses and you should therefore scan any attachments.

[E-sig Green Message]


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/78f123cb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 8446 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/78f123cb/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 9079 bytes
Desc: image002.png
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/78f123cb/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 5884 bytes
Desc: image003.png
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/78f123cb/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.jpg
Type: image/jpeg
Size: 2152 bytes
Desc: image004.jpg
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/78f123cb/attachment-0001.jpg>

From dyoo at hashcollision.org  Mon Jul  7 08:49:21 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 6 Jul 2014 23:49:21 -0700
Subject: [Tutor] Python Socket Error: Connection refused
In-Reply-To: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
References: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
Message-ID: <CAGZAPF69BRnM4Y=7RGv3OAhrgj5tb0so0N7dfEsDMGdALuf7+A@mail.gmail.com>

> I need some help, I  have no programming skills and am trying to teach myself python. I keep on getting an error message as follows:

[content cut]

It appears from the screenshot that you are running some version of
Windows that has software that's interfering with IDLE.  As the error
message says,

"IDLE's subprocess didn't make connection.  Either IDLE can't start a
subprocess or personal firewall software is blocking the connection."

I would believe the error message.  The IDLE program is trying to
create a network connection, but fails to do so.

Windows machines typically have a restrictive firewall that limit
certain operations.  Do you know if you have a firewall running on
your computer?  Note that there are other kinds of software that will
interfere, such as proxy network software.  See:
http://bugs.python.org/issue14576 for an example of such interference
by an external piece of software.


Software installation is stupid-hard.  If you are just starting off,
you might be able to use one of the "online" Python-based
environments, at least as a temporary workaround until you can resolve
your installation issue.  See:

    http://repl.it/languages/Python

It's not a perfect solution, but at least you may be able to start
doing simple experiments with Python without having to fight with
installation.

From fomcl at yahoo.com  Mon Jul  7 10:33:43 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Mon, 7 Jul 2014 01:33:43 -0700
Subject: [Tutor] What are your favourite unofficial resources
In-Reply-To: <1404585447.52508.BPMail_high_noncarrier@web163803.mail.gq1.yahoo.com>
References: <1404585447.52508.BPMail_high_noncarrier@web163803.mail.gq1.yahoo.com>
Message-ID: <1404722023.81069.YahooMailNeo@web163804.mail.gq1.yahoo.com>

>> On 30 June 2014 04:11, Alan Gauld <alan.gauld at btinternet.com> wrote:

>>>  I'm looking for tips for an appendix to a book that
>>>  I'm working on.
>>> 
>>>  What are the best unofficial (ie not python.org)
>>>  resources for people who have learned the basics
>>>  but are not experts yet? ie Typical tutor list
>>>  "graduates"...
>>> 
>>>  I'm thinking about web sites, blogs, books, videos etc.
>>>  Anything that might be worth knowing about.
>>> 
>>>  I've got a few of my own - Activestate, O'Reilly,
>>>  ByteOfPython, PythonChallenge, ShowMeDo etc.
>>> 
>>>  But I thought the tutor list readers might be an
>>>  interesting source of alternatives that I hadn't
>>>  thought of, or even heard of.
>>> 
>>>  All contributions considered :-)

Not sure if this one has been mentioned already: effbot.org. An absolute must!

From davea at davea.name  Mon Jul  7 13:55:22 2014
From: davea at davea.name (Dave Angel)
Date: Mon, 7 Jul 2014 07:55:22 -0400 (EDT)
Subject: [Tutor] Python Socket Error: Connection refused
References: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
Message-ID: <lpe1nb$kbm$1@ger.gmane.org>

Pamela Wightley <pamela.wightley at morgij.com.au> Wrote in message:
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

You apparently are running Windows, and in a corporate
 environment. You don't tell us your Python version,  but in this
 case my advice doesn?t care.

IDLE works by creating two processes,  IDLE itself and your Python
 code. Those processes then have to talk to each other, 
 presumably by using network sockets. 

Any computer with network access should protect itself from
 hackers and network intrusions, and first line of defense is
 usually a firewall. If you're in a corporate environment,  the IT
 department has probably got that tightly controlled. So the next
 step would presumably be getting them to open a cat door for you.
 They'll have to know IDLE enough to figure out what port to use, 
 or to configure IDLE to use one they already have open. I haven't
 done anything important in Windows for years so I can't be more
 specific than that. 

A better answer is probably to skip IDLE.  I've never used it, nor
 missed it. You can do most anything you want from a cmd prompt
 (DOS box). Start python from there, and play to learn from there.
 You'll also need a good programming editor (not Notepad), but
 there are many free choices.  One is Komodo Editor, but I only
 mention that because it's a subset of the not-free Komodo IDE
 that I use sometimes.  Mostly I use emacs.

You will want to configure your DOS Box to make it easier to cut
 and paste. That way you can copy back and forth between there and
 the editor or a browser window or an email program.
 

-- 
DaveA


From chigga101 at gmail.com  Mon Jul  7 19:16:59 2014
From: chigga101 at gmail.com (Matthew Ngaha)
Date: Mon, 7 Jul 2014 18:16:59 +0100
Subject: [Tutor] Python Socket Error: Connection refused
In-Reply-To: <lpe1nb$kbm$1@ger.gmane.org>
References: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
 <lpe1nb$kbm$1@ger.gmane.org>
Message-ID: <CACzNyA1ZMfQyZUBVX5Jg_sfp1w3nzbsAunsCiZp1eK0_v4=XRQ@mail.gmail.com>

On Mon, Jul 7, 2014 at 12:55 PM, Dave Angel <davea at davea.name> wrote:

> You will want to configure your DOS Box to make it easier to cut
>  and paste.

How is this done? I'm not on windows atm to test it.

From emile at fenx.com  Mon Jul  7 19:37:27 2014
From: emile at fenx.com (Emile van Sebille)
Date: Mon, 07 Jul 2014 10:37:27 -0700
Subject: [Tutor] Python Socket Error: Connection refused
In-Reply-To: <CACzNyA1ZMfQyZUBVX5Jg_sfp1w3nzbsAunsCiZp1eK0_v4=XRQ@mail.gmail.com>
References: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
 <lpe1nb$kbm$1@ger.gmane.org>
 <CACzNyA1ZMfQyZUBVX5Jg_sfp1w3nzbsAunsCiZp1eK0_v4=XRQ@mail.gmail.com>
Message-ID: <lpelta$urt$1@ger.gmane.org>

On 7/7/2014 10:16 AM, Matthew Ngaha wrote:
> On Mon, Jul 7, 2014 at 12:55 PM, Dave Angel <davea at davea.name> wrote:
>
>> You will want to configure your DOS Box to make it easier to cut
>>   and paste.
>
> How is this done? I'm not on windows atm to test it.

I think it's referring to the two edit options on the options tab of the 
cmd.exe properties.

Emile



From alan.gauld at btinternet.com  Mon Jul  7 19:57:39 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 07 Jul 2014 18:57:39 +0100
Subject: [Tutor] Python Socket Error: Connection refused
In-Reply-To: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
References: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>
Message-ID: <lpen2j$hbp$1@ger.gmane.org>

On 07/07/14 06:10, Pamela Wightley wrote:
> Hi,
>
> I need some help, I  have no programming skills and am trying to teach
> myself python. I keep on getting an error message as follows:
>
> Socket Error: Connection refused,


This is a common problem with IDLE in some environments.
There is a workaround by providing a command line switch to IDLE that 
prevents it using sockets.

You probably need to edit your Windows shortcut to say something
like:

idle -n

Alternatively if you are on Windows use the ActiveState download of 
Python instead since it is much better at setting paths etc and includes 
Pythonwin which is much better than IDLE. Make sure you
get the free (Community?) edition.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From pamela.wightley at morgij.com.au  Mon Jul  7 09:18:12 2014
From: pamela.wightley at morgij.com.au (Pamela Wightley)
Date: Mon, 7 Jul 2014 07:18:12 +0000
Subject: [Tutor] Python Socket Error: Connection refused
In-Reply-To: <CAGZAPF69BRnM4Y=7RGv3OAhrgj5tb0so0N7dfEsDMGdALuf7+A@mail.gmail.com>
References: <98E0EC724B3C884A9A081632D3A9554A088D6122@exmbx1.hesp.local>,
 <CAGZAPF69BRnM4Y=7RGv3OAhrgj5tb0so0N7dfEsDMGdALuf7+A@mail.gmail.com>
Message-ID: <EAD6DB2C-1173-4A9C-A101-10ECC1FC2EB3@morgij.com.au>

Thank you for your response. I installed python last week and it has been working fine until this afternoon. I will investigate the firewall prohibitions.

Pamela Wightley
MARQ Services
Tel: 040 089 2714

On 7 Jul 2014, at 4:49 pm, "Danny Yoo" <dyoo at hashcollision.org> wrote:

>> I need some help, I  have no programming skills and am trying to teach myself python. I keep on getting an error message as follows:
> 
> [content cut]
> 
> It appears from the screenshot that you are running some version of
> Windows that has software that's interfering with IDLE.  As the error
> message says,
> 
> "IDLE's subprocess didn't make connection.  Either IDLE can't start a
> subprocess or personal firewall software is blocking the connection."
> 
> I would believe the error message.  The IDLE program is trying to
> create a network connection, but fails to do so.
> 
> Windows machines typically have a restrictive firewall that limit
> certain operations.  Do you know if you have a firewall running on
> your computer?  Note that there are other kinds of software that will
> interfere, such as proxy network software.  See:
> http://bugs.python.org/issue14576 for an example of such interference
> by an external piece of software.
> 
> 
> Software installation is stupid-hard.  If you are just starting off,
> you might be able to use one of the "online" Python-based
> environments, at least as a temporary workaround until you can resolve
> your installation issue.  See:
> 
>    http://repl.it/languages/Python
> 
> It's not a perfect solution, but at least you may be able to start
> doing simple experiments with Python without having to fight with
> installation.

From keithadu at live.com  Mon Jul  7 20:29:07 2014
From: keithadu at live.com (keith papa)
Date: Mon, 7 Jul 2014 14:29:07 -0400
Subject: [Tutor] need help reading the code
Message-ID: <COL130-W81D6183EDE5A49CFD3F3CEA80D0@phx.gbl>

 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/2fcf4dc6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: problem set-1.py
Type: text/x-script.phyton
Size: 1131 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/2fcf4dc6/attachment.bin>

From alan.gauld at btinternet.com  Mon Jul  7 21:49:34 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 07 Jul 2014 20:49:34 +0100
Subject: [Tutor] need help reading the code
In-Reply-To: <COL130-W81D6183EDE5A49CFD3F3CEA80D0@phx.gbl>
References: <COL130-W81D6183EDE5A49CFD3F3CEA80D0@phx.gbl>
Message-ID: <lpetkf$7au$1@ger.gmane.org>

On 07/07/14 19:29, keith papa wrote:

Please post in plain text and avoid attachments if possible.
Just paste code directly into the email.

I've had to cut n paste everything to write this which is a pain...

 >>> print '{0} was {1} years old when he wrote this book'.format(name, age)

 >>> print 'Why is {0} playing with that python?'.format(name)

# I no that the code will give you the same output even without numbers:

Yes the numbers are not needed here but consider this example:

 >>> print "{0} loves {1} but {2} hates {0}!".format('Joe', 'food', 'Anne')

Now you need the numbers because you are using the same value (0)twice.

I'll look at the other issues in separate mails.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Tue Jul  8 00:21:40 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 07 Jul 2014 23:21:40 +0100
Subject: [Tutor] need help reading the code
In-Reply-To: <COL130-W81D6183EDE5A49CFD3F3CEA80D0@phx.gbl>
References: <COL130-W81D6183EDE5A49CFD3F3CEA80D0@phx.gbl>
Message-ID: <lpf6hk$j2n$1@ger.gmane.org>

On 07/07/14 19:29, keith papa wrote:
# decimal (.) precision of 3 for float '0.333'

 >>> print '{0:.3f}'.format(1.0/3)

The best way to see how this works is to try it
with different values:

 >>> print('{0:.3f}'.format(1.0/3))
0.333
 >>> print('{0:.5f}'.format(1.0/3))
0.33333
 >>> print('{0:.1f}'.format(1.0/3))
0.3
 >>> print('{0:.5f}'.format(1.0/2))
0.50000
 >>>

Look at how many digits appear after the decimal
point in each case.


# fill with underscores (_) with the text centered
# (^) to 11 width '___hello___'

 >>> print '{0:_^11}'.format('hello')

Again, try it out with different values.
The tricky thing here is that he is showing 3 different features in one 
example.
Try breaking them down into 3 different sets then
building them back up:

set width of field:

 >>> print('{:11}'.format('hello'))
hello
 >>> print('{:3}'.format('hello'))
hello
 >>>

Hmmm, Doesn't seem to do anything...Lets add some justification

 >>> print('{:<11}'.format('hello'))
hello
 >>> print('{:>11}'.format('hello'))
       hello
 >>> print('{:^11}'.format('hello'))
    hello

Somethings happening, but to really see what it is...

add a padding character so you see the 'spaces;:

 >>> print('{:_>11}'.format('hello'))
______hello
 >>> print('{:_<11}'.format('hello'))
hello______
 >>> print('{:_^11}'.format('hello'))
___hello___

Which is where we came in...

Try different padding characters and change the width values.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From niihung at gmail.com  Tue Jul  8 05:51:33 2014
From: niihung at gmail.com (Ni Hung)
Date: Mon, 7 Jul 2014 20:51:33 -0700
Subject: [Tutor] Next steps...
Message-ID: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>

ok, I am now able to write scripts in python. I can read/modify scripts
written by others (true to some level).  I understand the basics of
libraries (how are they different from modules or are the same thing with
two names?)  like urllib2, json, sys, os etc. and have used them in some
scripts.

What should I do next to advance my knowledge of python? Should I study/use
libraries/modules?  Which ones?  Any other suggestions?

Thanks and Regards
Nii
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140707/e46b720d/attachment.html>

From pamela.wightley at morgij.com.au  Tue Jul  8 03:41:33 2014
From: pamela.wightley at morgij.com.au (Pamela Wightley)
Date: Tue, 8 Jul 2014 01:41:33 +0000
Subject: [Tutor] SyntaxError Message
Message-ID: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>

Hi All,

I have no programming experience and am trying to  teaching myself python. Am trying to replicate the code below but I get the error message below highlighted in yellow:

choice = input("Choose your option: ")
    if choice == 1:
        add1 = input("Add this: ")
        add2 = input("to this: ")
        print add1, "+", add2, "=", add1 + add2
    elif choice == 2:
        sub2 = input("Subtract this: ")
        sub1 = input("from this: ")
        print sub1, "-", sub2, "=", sub1 - sub2
    elif choice == 3:
        mul1 = input("Multiply this: ")
        mul2 = input("with this: ")
        print mul1, "*", mul2, "=", mul1 * mul2
    elif choice == 4:
        div1 = input("Divide this: ")
        div2 = input("by this: ")
        print div1, "/", div2, "=", div1 / div2
    elif choice == 5:
        loop = 0


Any assistance appreciated.

ERROR MESSAGE

>>> return input (1)
  File "<stdin>", line 1
SyntaxError: 'return' outside function
>>> return ("1")
  File "<stdin>", line 1
SyntaxError: 'return' outside function
>>> return input ("1")
  File "<stdin>", line 1
SyntaxError: 'return' outside function
>>> return input ("choose your option:")
  File "<stdin>", line 1
SyntaxError: 'return' outside function
>>> return input ("1:")
  File "<stdin>", line 1
SyntaxError: 'return' outside function
>>>


Pamela Wightley
[MorgijAnalytics e-sig][MorgijAnalytics e-apple]
Level 3 | 10 Bond Street |  Sydney | NSW 2000 | Australia
[P] (02) 8197 1828 |  [M] 0400 892 714  |
pamela.wightley at morgij.com.au<mailto:pamela.wightley at morgij.com.au>  |  www.morgij.com.au<http://www.morgij.com.au/> |   www.marqservices.com<http://www.morgij.com.au/>

The contents of this email and any attachments are strictly confidential and intended solely for the attention and use of the named addressee(s). If you are not the intended recipient you are not authorised to and must not disclose, copy, distribute, or retain this message without our authority. This email and all of its contents are subject to copyright. If you have received this email in error, please notify the sender by a return e-mail immediately. Please note that we do not accept responsibility for viruses and you should therefore scan any attachments.

[E-sig Green Message]


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140708/9c9d05c6/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 9079 bytes
Desc: image001.png
URL: <http://mail.python.org/pipermail/tutor/attachments/20140708/9c9d05c6/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 5884 bytes
Desc: image002.png
URL: <http://mail.python.org/pipermail/tutor/attachments/20140708/9c9d05c6/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 2152 bytes
Desc: image003.jpg
URL: <http://mail.python.org/pipermail/tutor/attachments/20140708/9c9d05c6/attachment-0001.jpg>

From dyoo at hashcollision.org  Tue Jul  8 09:07:37 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Tue, 8 Jul 2014 00:07:37 -0700
Subject: [Tutor] SyntaxError Message
In-Reply-To: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>
References: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>
Message-ID: <CAGZAPF4ojhNjejo+zgt5XE7KbM1MYPv4pKtzoQhmAX49Q20tTQ@mail.gmail.com>

> I have no programming experience and am trying to  teaching myself python.
> Am trying to replicate the code below but I get the error message below
> highlighted in yellow:


We need a little more information.  Where does this code come from?
What text book or instructional material are you using?


I ask because the code you're doing is unusual looking, and appears to
be out-of-context.  To be more specific, the following part of your
program:

        return input ("1")

doesn't make too much sense in isolation.

The errors you're seeing are due to the fish-out-of-waterness of the
code: the "return" statement only makes sense if you're writing a
function definition, but if you're just getting started, you probably
haven't learned about how to write function definitions yet.

If you can point us to the instructional material you're looking at,
we might give better suggestions as to what's missing.

But alternatively, have you tried the following tutorial instead?

    http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3

It may be a gentler introduction to the language than what you're
looking at now.


Good luck!  If you have more questions, please feel free to ask.

From dyoo at hashcollision.org  Tue Jul  8 09:36:06 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Tue, 8 Jul 2014 00:36:06 -0700
Subject: [Tutor] SyntaxError Message
In-Reply-To: <CAGZAPF4ojhNjejo+zgt5XE7KbM1MYPv4pKtzoQhmAX49Q20tTQ@mail.gmail.com>
References: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>
 <CAGZAPF4ojhNjejo+zgt5XE7KbM1MYPv4pKtzoQhmAX49Q20tTQ@mail.gmail.com>
Message-ID: <CAGZAPF71x0r4D521sSr7U28U_aP28U3w6d-4LuyMnHouUWMFxA@mail.gmail.com>

Following up.  I can guess that you're looking at:

    http://www.sthurlow.com/python/lesson05/

But I would like not to guess unless I have no choice. In the future,
if you're asking for help, provide context.  The reason why it's very
useful to say where you're learning from is because we can then look
at previous things you have seen before, and try to relate those past
things with what you're doing now.

In this case, now that I know the context more, I can look at the
material myself and see if it makes sense.  Sometimes tutorials can be
confusingly written.

Ah.  In particular, the "Code Example 9" in the link above is not
presented well.  I say this because it is not even a complete program!
 And yet the author is notating it as if it were a complete program by
putting it in its own figure.  If you tried to do Code Example 9, it
would raise the exact same error messages you're seeing now.

Hmm... I have other reservations about this tutorial.  It's presumably
trying to teach functions, but it is not really using the functions as
things that return useful values.  add(), sub(), mul(), and div() in
Code Example 14 are not great examples of functions.


I think you may want to switch to a different tutorial and see if it
is easier to approach.  Since you're using Python 2, I have to
backtrack on the tutorial I linked in a previous message: I needed to
have referred to a tutorial that used Python 2, not Python 3.  My
apologies!

Here is a link to a good tutorial:
http://openbookproject.net/thinkcs/python/english2e/

Please try that one instead and see if it makes more sense.

From dyoo at hashcollision.org  Tue Jul  8 09:55:44 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Tue, 8 Jul 2014 00:55:44 -0700
Subject: [Tutor] Next steps...
In-Reply-To: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>
References: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>
Message-ID: <CAGZAPF621RrdWUsEu0dtHaFhSgQQFnqQCb1E_Hr6TXX+MV+Pkw@mail.gmail.com>

On Mon, Jul 7, 2014 at 8:51 PM, Ni Hung <niihung at gmail.com> wrote:
> ok, I am now able to write scripts in python. I can read/modify scripts
> written by others (true to some level).  I understand the basics of
> libraries (how are they different from modules or are the same thing with
> two names?)  like urllib2, json, sys, os etc. and have used them in some
> scripts.
>
> What should I do next to advance my knowledge of python? Should I study/use
> libraries/modules?  Which ones?  Any other suggestions?


This is hard to say since it depends on your learning style.

Some folks tend to really integrate what they've learned by doing a
project.  Do you have any interesting ideas of something you'd like to
do?  Any hobbies?

For example, I like playing Go (aka "Baduk"), so sometimes I look into
writing programs that are related to Go in some way.  I'm planning to
write a program to parse the file format used to record Go games, the
Smart Game Format, or "SGF" format.  Such programs already exist, of
course!  But reinvention is fine when we're learning.  And rather than
write it in Python, I'm thinking of writing it in the Go programming
language, for maximal confusion.  :P


So that's one possibility.  Another possibility is doing something
like The Python Challenge.  Have you seen the following?

    http://www.pythonchallenge.com/

For some people, the Python Challenge web site helps them cement their
programming a little more.


The others on this list will have more suggestions; I'm sure of it.
:P  Good luck.

From davea at davea.name  Tue Jul  8 13:31:58 2014
From: davea at davea.name (Dave Angel)
Date: Tue, 8 Jul 2014 07:31:58 -0400 (EDT)
Subject: [Tutor] SyntaxError Message
References: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>
Message-ID: <lpgknc$goh$1@ger.gmane.org>

Pamela Wightley <pamela.wightley at morgij.com.au> Wrote in message:
> 
> 

This is a text mailing list.  So leaving an html message blocks
 some of us from seeing what you intended.  Color and other
 formatting vanishes for many.  Please tell your email program to
 post in text mode.

The problem with your fragment is that the return statement only
 makes sense inside a function,  but you don't begin with a def
 statement. 

-- 
DaveA


From alan.gauld at btinternet.com  Tue Jul  8 15:40:12 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 08 Jul 2014 14:40:12 +0100
Subject: [Tutor] SyntaxError Message
In-Reply-To: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>
References: <98E0EC724B3C884A9A081632D3A9554A088D6E8B@exmbx1.hesp.local>
Message-ID: <lpgsbs$n5p$1@ger.gmane.org>

On 08/07/14 02:41, Pamela Wightley wrote:
> Hi All,
>
> I have no programming experience and am trying to  teaching myself
> python. Am trying to replicate the code below but I get the error
> message below highlighted in yellow:

Unfortunately I can't see anything in yellow, probably due to enmail 
losing the formatting.

But the code below has several errors and looks like its part
of a bigger program. It also looks completely unrelated to the
errors you show us further down.


> choice = input("Choose your option: ")

You seem to be using Python 2 in which case using input() is
frowned upon. Its better to use raw_input() and convert the
resultant string to a number using int() or float() as needed.
[ In Python 3 input() has been rwe oved and raw_input renamed to input()...]

>
>      if choice == 1:

indentation(spacing) is very importanbt in Python.
You should only indent the code inside a code block that follows a 
structural statement such as if/for/while/def/class etc.

Indenting the if statement after the input() will raise an error.

>          add1 = input("Add this: ")


But this should e indented because its part of the if block.

>
>          add2 = input("to this: ")
>
>          print add1, "+", add2, "=", add1 + add2
>
>      elif choice == 2:
>
>          sub2 = input("Subtract this: ")
>
>          sub1 = input("from this: ")
>
>          print sub1, "-", sub2, "=", sub1 - sub2
>
>      elif choice == 3:
>
>          mul1 = input("Multiply this: ")
>
>          mul2 = input("with this: ")
>
>          print mul1, "*", mul2, "=", mul1 * mul2
>
>      elif choice == 4:
>
>          div1 = input("Divide this: ")
>
>          div2 = input("by this: ")
>
>          print div1, "/", div2, "=", div1 / div2
>
>      elif choice == 5:
>
>          loop = 0
>
> Any assistance appreciated.
>
> ERROR MESSAGE
>
>>>> return input (1)
>
>    File "<stdin>", line 1
>
> SyntaxError: 'return' outside function
>

This seems completely unrelated to the choice code?
You can only use return inside a function (ie a block
starting def....)


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Tue Jul  8 15:45:04 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 08 Jul 2014 14:45:04 +0100
Subject: [Tutor] Next steps...
In-Reply-To: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>
References: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>
Message-ID: <lpgsl0$qc3$1@ger.gmane.org>

On 08/07/14 04:51, Ni Hung wrote:

> libraries (how are they different from modules or are the same thing
> with two names?)

In Python libraries and modules are nearly the same. Libraries are a 
concept in Python which are realized using modules (or packages).

In other languages libraries are the reality and modules are the logical 
concept.

And in still other languages you have modules and libraries where 
libraries are (usually binary) files containing several code modules.

Some day computing science will get around to making its language 
consistent!

> What should I do next to advance my knowledge of python? Should I
> study/use libraries/modules?  Which ones?  Any other suggestions?

Danny suggested a project or the Python challenge.
I'd agree with those two suggestions, and personally I'd
favour a project. It doesn't matter what it is - don't be too
ambitious, but something bigger than a single file of code.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From fomcl at yahoo.com  Tue Jul  8 17:46:36 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Tue, 8 Jul 2014 08:46:36 -0700
Subject: [Tutor] Tkinter resizable menu??
Message-ID: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>

Hi,

I created a small menu with Tkinter. It has two listboxes: a source and a destination box. The user can select files from the source box and 'move' them to the destination box. It now does what I want, except for one thing: when I resize it, the listboxes will not (*will* not, grrr) increase in size.

I followed these instructions: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/root-resize.html


I added background colors to the various frames to see what's happening. I pasted the code here because it is a bit much (sorry): http://pastebin.com/waeACc4B. Any idea what I am doing wrong in the function createListbox (line 80)? I am using sticky=NESW in the grid() calls.?

Thank you in advance!


Regards,

Albert-Jan




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From fomcl at yahoo.com  Tue Jul  8 18:00:36 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Tue, 8 Jul 2014 09:00:36 -0700
Subject: [Tutor] Tkinter resizable menu??
In-Reply-To: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
References: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
Message-ID: <1404835236.82116.YahooMailNeo@web163802.mail.gq1.yahoo.com>



?

> I added background colors to the various frames to see what's happening. I 
> pasted the code here because it is a bit much (sorry): 
> http://pastebin.com/waeACc4B. Any idea what I am doing wrong in the function 
> createListbox (line 80)? I am using sticky=NESW in the grid() calls.?

PS: The trailing dot was not part of the URL: http://pastebin.com/waeACc4B

From __peter__ at web.de  Tue Jul  8 18:07:40 2014
From: __peter__ at web.de (Peter Otten)
Date: Tue, 08 Jul 2014 18:07:40 +0200
Subject: [Tutor] Tkinter resizable menu??
References: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
Message-ID: <lph512$fvk$1@ger.gmane.org>

Albert-Jan Roskam wrote:

> I created a small menu with Tkinter. It has two listboxes: a source and a
> destination box. The user can select files from the source box and 'move'
> them to the destination box. It now does what I want, except for one
> thing: when I resize it, the listboxes will not (*will* not, grrr)
> increase in size.
> 
> I followed these instructions:
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/root-resize.html
> 
> 
> I added background colors to the various frames to see what's happening. I
> pasted the code here because it is a bit much (sorry):
> http://pastebin.com/waeACc4B. Any idea what I am doing wrong in the
> function createListbox (line 80)? I am using sticky=NESW in the grid()
> calls.

You must explicitly tell the row/column to grab the extra space:

    def createListbox(self, row, column, name, contents):
        ...
        self.listboxframe.grid(row=row, column=column, sticky=self.sticky)
        self.listboxframe.columnconfigure(column, weight=1)
        self.listboxframe.rowconfigure(row, weight=1)
        ...

See http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/grid-config.html


From linux at barrowhillfarm.org.uk  Tue Jul  8 18:44:10 2014
From: linux at barrowhillfarm.org.uk (Bob Williams)
Date: Tue, 08 Jul 2014 17:44:10 +0100
Subject: [Tutor] subprocess.call not formatting date
Message-ID: <53BC1FDA.6010406@barrowhillfarm.org.uk>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm using Python 2.7.6 on an openSUSE linux system.

I'm trying to convert a shell (bash) script to a python script, and everything's worked OK except this. The following line in the shell script

btrfs subvolume snapshot /home/bob/A3/documents /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`

creates a folder of the form

/home/bob/A3/docsnaps/14-07-08_17-32

ie. the name is a formatted date string, which is what I want.

In my python script, this

subprocess.call('btrfs', 'subvolume', 'snapshot', '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`')

creates a folder

/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`

In other words, it does not format the date, but takes the stuff between the backticks (`) as a string.

I tried adding shell=True, but got the following error:

Traceback (most recent call last):
  File "/home/bob/bin/btrfs-backup.py", line 55, in <module>
    subprocess.call('btrfs', 'subvolume', 'snapshot', '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`', shell=True)
  File "/usr/lib64/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib64/python2.7/subprocess.py", line 658, in __init__
    raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

Any suggestions, please?
- -- 
Bob Williams
System:  Linux 3.11.10-17-desktop
Distro:  openSUSE 13.1 (x86_64) with KDE Development Platform: 4.13.2
Uptime:  06:00am up 2 days 9:43, 5 users, load average: 0.00, 0.02, 0.05
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlO8H9gACgkQ0Sr7eZJrmU7fdACgkBqVXT+Ozb+XqmEFwhPBdmeX
NcgAnjY6YrbXcmUTAvgLPblk4rOWFAdH
=vfIY
-----END PGP SIGNATURE-----

From __peter__ at web.de  Tue Jul  8 19:12:42 2014
From: __peter__ at web.de (Peter Otten)
Date: Tue, 08 Jul 2014 19:12:42 +0200
Subject: [Tutor] subprocess.call not formatting date
References: <53BC1FDA.6010406@barrowhillfarm.org.uk>
Message-ID: <lph8qc$ceg$1@ger.gmane.org>

Bob Williams wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I'm using Python 2.7.6 on an openSUSE linux system.
> 
> I'm trying to convert a shell (bash) script to a python script, and
> everything's worked OK except this. The following line in the shell script
> 
> btrfs subvolume snapshot /home/bob/A3/documents
> /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`
> 
> creates a folder of the form
> 
> /home/bob/A3/docsnaps/14-07-08_17-32
> 
> ie. the name is a formatted date string, which is what I want.
> 
> In my python script, this
> 
> subprocess.call('btrfs', 'subvolume', 'snapshot',
> '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`')
> 
> creates a folder
> 
> /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`
> 
> In other words, it does not format the date, but takes the stuff between
> the backticks (`) as a string.
> 
> I tried adding shell=True, but got the following error:
> 
> Traceback (most recent call last):
>   File "/home/bob/bin/btrfs-backup.py", line 55, in <module>
>     subprocess.call('btrfs', 'subvolume', 'snapshot',
>     '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date
>     +%y-%m-%d_%H-%M`', shell=True)
>   File "/usr/lib64/python2.7/subprocess.py", line 522, in call
>     return Popen(*popenargs, **kwargs).wait()
>   File "/usr/lib64/python2.7/subprocess.py", line 658, in __init__
>     raise TypeError("bufsize must be an integer")
> TypeError: bufsize must be an integer

That's because the second argument to call() is bufsize, and you are passing
it the string "subvolume". While I suppose that

# untested
subprocess.call("btrfs subvolume snapshot /home/bob/A3/documents /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`", shell=True)

would work I suggest that you calculate the folder name in Python instead:

# untested
name = datetime.datetime.now().strftime("%y-%m-%d_%H-%M")
destpath = os.path.join("/home/bob/A3/docsnaps", name)
subprocess.call(
    ["btrfs", "subvolume", "snapshot", "/home/bob/A3/documents", destpath])



From emile at fenx.com  Tue Jul  8 19:18:07 2014
From: emile at fenx.com (Emile van Sebille)
Date: Tue, 08 Jul 2014 10:18:07 -0700
Subject: [Tutor] subprocess.call not formatting date
In-Reply-To: <53BC1FDA.6010406@barrowhillfarm.org.uk>
References: <53BC1FDA.6010406@barrowhillfarm.org.uk>
Message-ID: <lph954$hf6$1@ger.gmane.org>

On 7/8/2014 9:44 AM, Bob Williams wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm using Python 2.7.6 on an openSUSE linux system.
>
> I'm trying to convert a shell (bash) script to a python script, and everything's worked OK except this. The following line in the shell script
>
> btrfs subvolume snapshot /home/bob/A3/documents /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`
>
> creates a folder of the form
>
> /home/bob/A3/docsnaps/14-07-08_17-32
>
> ie. the name is a formatted date string, which is what I want.
>
> In my python script, this
>
> subprocess.call('btrfs', 'subvolume', 'snapshot', '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`')
>
> creates a folder
>
> /home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`
>
> In other words, it does not format the date, but takes the stuff between the backticks (`) as a string.
>
> I tried adding shell=True, but got the following error:
>
> Traceback (most recent call last):
>    File "/home/bob/bin/btrfs-backup.py", line 55, in <module>
>      subprocess.call('btrfs', 'subvolume', 'snapshot', '/home/bob/A3/documents', '/home/bob/A3/docsnaps/`date +%y-%m-%d_%H-%M`', shell=True)
>    File "/usr/lib64/python2.7/subprocess.py", line 522, in call
>      return Popen(*popenargs, **kwargs).wait()
>    File "/usr/lib64/python2.7/subprocess.py", line 658, in __init__
>      raise TypeError("bufsize must be an integer")
> TypeError: bufsize must be an integer
>
> Any suggestions, please?

Pass in the formatted string using the python datetime module.

datetime.datetime.today().strftime("%y-%m-%d_%H-%M")

see https://docs.python.org/2/library/datetime.html for more details.

Emile




From linux at barrowhillfarm.org.uk  Tue Jul  8 20:23:14 2014
From: linux at barrowhillfarm.org.uk (Bob Williams)
Date: Tue, 08 Jul 2014 19:23:14 +0100
Subject: [Tutor] subprocess.call not formatting date
In-Reply-To: <lph8qc$ceg$1@ger.gmane.org>
References: <53BC1FDA.6010406@barrowhillfarm.org.uk>
 <lph8qc$ceg$1@ger.gmane.org>
Message-ID: <53BC3712.2030106@barrowhillfarm.org.uk>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/07/14 18:12, Peter Otten wrote:
> I suggest that you calculate the folder name in Python instead:
> 
> # untested name =
> datetime.datetime.now().strftime("%y-%m-%d_%H-%M") destpath =
> os.path.join("/home/bob/A3/docsnaps", name) subprocess.call( 
> ["btrfs", "subvolume", "snapshot", "/home/bob/A3/documents",
> destpath])

Thank you. That worked perfectly. Once it's pointed out it is obvious
to use the python solution, but my brain is becoming less agile as I
collect more birthdays!

Bob
- -- 
Bob Williams
System:  Linux 3.11.10-17-desktop
Distro:  openSUSE 13.1 (x86_64) with KDE Development Platform: 4.13.2
Uptime:  06:00am up 2 days 9:43, 5 users, load average: 0.00, 0.02, 0.05
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlO8Nw8ACgkQ0Sr7eZJrmU6HVwCaAkT+nqxn818s1Di8mgqc9U1a
qksAni7exn27xTGgDV2O6vSNtg8FbgMK
=9I7G
-----END PGP SIGNATURE-----

From alan.gauld at btinternet.com  Tue Jul  8 20:56:05 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 08 Jul 2014 19:56:05 +0100
Subject: [Tutor] Tkinter resizable menu??
In-Reply-To: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
References: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
Message-ID: <lphes6$bd7$1@ger.gmane.org>

On 08/07/14 16:46, Albert-Jan Roskam wrote:
> I pasted the code here because it is a bit much (sorry):

Too much for me, I gave up without spotting the problem.

One thing that did strike me though was that you spend quite
a lot of code setting up scrollbars etc on your list boxes.

The Tix module has a scrollable listbox widget which is
quite easy to use and does all that stuff for you.

Simply replace

import Tkinter as tk

with

import Tix as tk

and it should just work as is.
Then replace the list box and scrollers with the
ScrolledListBox widget.

Much less work.
Tix is not very well documented but the ScrolledListBox
(and ScrolledText) are two of the better examples.


Also all that messing around with lambdas etc outside the
widget creation would actually be easier to read if you
just used the lambda inside the command=argument and
referenced the actual method. Having two levels of
redirection simply makes the reader have to search
your code to find out what it really is...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From jf_byrnes at comcast.net  Tue Jul  8 22:45:42 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Tue, 08 Jul 2014 15:45:42 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python script?
Message-ID: <lphl9m$8uh$1@ger.gmane.org>

I would like to automate running virtualenv with a python script by:

opening gnome-terminal
cd to proper directory
run source /bin/activate

I found some examples of using os.system() to get gnome-terminal to open 
but I can't figure out how then cd to the proper directory in the new 
terminal.

My biggest frustration right now is that I can't find any documentation 
on how to use os.system().  Looking at the docs on the Python site I 
don't see system() under the os module.  Googling hasn't helped.

Thanks,  Jim


From dyoo at hashcollision.org  Tue Jul  8 23:02:46 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Tue, 8 Jul 2014 14:02:46 -0700
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lphl9m$8uh$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
Message-ID: <CAGZAPF70Vpy3vZp58sOvQ5LWCjk0ZOKgF-BJNFeRydV_RfVzSQ@mail.gmail.com>

You might look at:

    http://askubuntu.com/questions/351582/open-terminal-window-and-execute-python-script-on-startup
    http://superuser.com/questions/198015/open-gnome-terminal-programmatically-and-execute-commands-after-bashrc-was-execu

both which appears relevant to your question.

If I understand your question correctly, you're trying to open up a
new terminal with gnome-terminal, and within that new terminal,
execute some additional set of instructions in the context of that
terminal.  If so, then you'll probably have to open up the
gnome-terminal in such a way that it knows what to do next by itself,
without further interaction with your original Python program.  So
when you say:

    opening gnome-terminal
    cd to proper directory
    run source /bin/activate

then I see a secondary "terminal_script.py" in charge of doing:

    cd to proper directory
    run source /bin/activate

and your primary script will be doing the initial call to do

    gnome-terminal -e "python terminal_script.py"

to finish the rest of the computation you're planning.


As a side note, consider using the subprocess module instead of
os.system().  https://docs.python.org/2/library/subprocess.html#module-subprocess.

From paradox at pobox.com  Wed Jul  9 01:15:55 2014
From: paradox at pobox.com (Paradox)
Date: Wed, 09 Jul 2014 07:15:55 +0800
Subject: [Tutor] Next steps... :p:
In-Reply-To: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>
References: <CA+pvUGXux3bGH8cwYxCghAhecCGgRMv=973ca83nW23RK+qWYA@mail.gmail.com>
Message-ID: <53BC7BAB.5040500@pobox.com>

On 07/08/2014 11:51 AM, Ni Hung wrote:
 > What should I do next to advance my knowledge of python? Should I 
study/use libraries/modules?  Which ones?  Any other suggestions?
 >
 > Thanks and Regards
 > Nii

Oops, replied to sender and not to the list ...

Sounds like you are ready to start solving real problems.  Pick 
something that interests you and dig in.  If you don't have any pressing 
problems to solve then look for the myriad of problems sites to get some 
training problems.  Here are a few of my favorites:

1. pythonchallenge.com (good fun)
2. checkio.org (my current favorite)
3. projecteuler.net (good if you are interested in math oriented puzzles)
4. https://github.com/karan/Projects/ (long list of puzzles to solve)
5. https://github.com/gregmalcolm/python_koans/wiki - You are probably 
passed this but I like koans for some easy fun and to keep sharp when I 
have had an interruption in learning
6. 
http://www.dreamincode.net/forums/topic/78802-martyr2s-mega-project-ideas-list/ 
- there is a github repo for solutions for these as well

There are many such puzzle collections out there, these are just the 
ones with which I have experience.

thomas

From alan.gauld at btinternet.com  Wed Jul  9 01:39:53 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 09 Jul 2014 00:39:53 +0100
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lphl9m$8uh$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
Message-ID: <lphvg9$4r7$1@ger.gmane.org>

On 08/07/14 21:45, Jim Byrnes wrote:
> I would like to automate running virtualenv with a python script by:
>
> opening gnome-terminal
> cd to proper directory
> run source /bin/activate

Thats almost certainly the wrong approach.
Instead of trying to automate what the user does in the terminal replace 
the terminal with Python.

Run the cd command from within Python (os.chdir())
Run Activate from within Python (this is where os.system()
could be used, but subprocess.call() is considered better
practice.

> I found some examples of using os.system() to get gnome-terminal to open
> but I can't figure out how then cd to the proper directory in the new
> terminal.

You can't. os.system() just runs a command it has no way to interaxct5 
with the command, you do that manually. Its perfectly fine for 
displaying a directory listing (although os.listdir() would be better) 
or sending a file to a printer, or even opening a terminal/editor
for the user to interact with. But its no good for your program 
interacting with it. Thats what subprocess is for.


> My biggest frustration right now is that I can't find any documentation
> on how to use os.system().  Looking at the docs on the Python site I
> don't see system() under the os module.

You should, although they don;t have a lot to say...

----------------------
os.system(command)

Execute the command (a string) in a subshell. This is implemented by 
calling the Standard C function system(), and has the same limitations. 
Changes to sys.stdin, etc. are not reflected in the environment of the 
executed command. If command generates any output, it will be sent to 
the interpreter standard output stream.

On Unix, the return value is the exit status of the process encoded in 
the format specified for wait(). Note that POSIX does not specify the 
meaning of the return value of the C system() function, so the return 
value of the Python function is system-dependent.

On Windows, the return value is that returned by the system shell after 
running command. The shell is given by the Windows environment variable 
COMSPEC: it is usually cmd.exe, which returns the exit status of the 
command run; on systems using a non-native shell, consult your shell 
documentation.

The subprocess module provides more powerful facilities for spawning new 
processes and retrieving their results; using that module is preferable 
to using this function. See the Replacing Older Functions with the 
subprocess Module section in the subprocess documentation for some 
helpful recipes.

Availability: Unix, Windows.
-------------------------------

>  Googling hasn't helped.

When you know the module use the browser search tools on the page itself 
- that's how I found it. I searched for os.system and it
was the 3rd occurence.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From cs at zip.com.au  Wed Jul  9 02:25:58 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Wed, 9 Jul 2014 10:25:58 +1000
Subject: [Tutor] How can I open and use gnome-terminal from a Python
 script?
In-Reply-To: <lphl9m$8uh$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
Message-ID: <20140709002558.GA32958@cskk.homeip.net>

On 08Jul2014 15:45, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>I would like to automate running virtualenv with a python script by:
>
>opening gnome-terminal
>cd to proper directory
>run source /bin/activate
>
>I found some examples of using os.system() to get gnome-terminal to 
>open but I can't figure out how then cd to the proper directory in the 
>new terminal.

You basicly can't do that, in that specific order, easily via system(); it runs 
a shell command.  It also waits for it to complete; you don't say if that is 
required.

But like Alan, I think you're doing it in the wrong order. I would do the cd 
and source activate, then start the gnome-terminal.

You can do that as one shell command like this:

   cd /the/proper/directory; . /path/to/bin/activate; gnome-terminal

Such a string you can hand to os.system().

There are some obvious things to consider here:

   - proper quoting of the directory path and the path to activate; they may have almost anything in them and care is needed

   - do you intent to wait for the terminal to exit before proceeding?

Regarding the former item: for this reason it would be more robust and safer to 
do the cd (os.chdir) and activation in python. But please get the shell version 
working first to ensure it does what you want it to do.

>My biggest frustration right now is that I can't find any documentation on how 
to use os.system().  Looking at the docs on the Python site I don't see 
system() under the os module.  Googling hasn't helped.

os.system should be documented in the "os" module.

But it just takes a shell command, so aside for handling the fork/exec-of-"sh 
-c your_command"-wait, there is little to document.

Cheers,
Cameron Simpson <cs at zip.com.au>

From steve at pearwood.info  Wed Jul  9 03:42:04 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Wed, 9 Jul 2014 11:42:04 +1000
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lphl9m$8uh$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
Message-ID: <20140709014204.GM13014@ando>

On Tue, Jul 08, 2014 at 03:45:42PM -0500, Jim Byrnes wrote:
> I would like to automate running virtualenv with a python script by:
> 
> opening gnome-terminal
> cd to proper directory
> run source /bin/activate

Why not just run /bin/activate directly from Python?

os.chdir("the/proper/directory")
os.system("/bin/activate")

> I found some examples of using os.system() to get gnome-terminal to open 
> but I can't figure out how then cd to the proper directory in the new 
> terminal.
> 
> My biggest frustration right now is that I can't find any documentation 
> on how to use os.system().  Looking at the docs on the Python site I 
> don't see system() under the os module.  Googling hasn't helped.

https://docs.python.org/2/library/os.html#os.system

I found it by going to the os module, then using my browser's Find In 
This Page (not google!) function to look for "os.system", then clicking 
the very first link that came up.

Basically, if you can type a command at the shell prompt, you can run 
the same thing using os.system. There are a few complications due to the 
fact that each call to os.system operates in isolation from any other 
call to os.system e.g. this won't touch the file /tmp/foo:

os.system("cd /tmp")
os.system("touch foo")

but this will:

os.system("cd /tmp; touch foo")

but otherwise it is as simple as it gets.



-- 
Steven

From nanney.56 at gmail.com  Wed Jul  9 03:44:01 2014
From: nanney.56 at gmail.com (Robert Nanney)
Date: Tue, 8 Jul 2014 20:44:01 -0500
Subject: [Tutor] Unpacking lists
Message-ID: <CAEGCHXsHdHiaGozp=grnvcLiOQJx1C5fxcc0NzVO5fg1EeR22w@mail.gmail.com>

Hello All,

I have the following code.  The idea is to have one list that contains
all of the items from the different iterable types and maintain the
order of the items.

Python 2.7.6 |Anaconda 2.0.0 (x86_64)| (default, May 27 2014, 14:58:54)

#!/usr/bin/python
#list_test2.py

list1 = [1, 8, 15]
list2 = [2, 9, 16]
list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
list4 = [7, 14, 21]
one_list = zip(list1, list2, list3, list4)
print "Start: {}".format(one_list)
first_round = [one_list[x][y] for x in range(len(list3)) for y in range(4)]
print "First Round: {}".format(first_round)
second_round = []
for i in first_round:
    if not isinstance(i, list):
        second_round.append(i)
    else:
        for x in range(len(i)):
            second_round.append(i[x])
print "Second round: {}".format(second_round)

While this seems to do the trick, I feel there is probably a
better/more pythonic way to accomplish the same thing.

One thing to keep in mind is that the number of items in each list
will always be the same, ie... if list1, list2, list4 have 4 items
each, there will be 4 lists in list3.

Any advice would be greatly appreciated!

-Robert

From cs at zip.com.au  Wed Jul  9 07:14:14 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Wed, 9 Jul 2014 15:14:14 +1000
Subject: [Tutor] How can I open and use gnome-terminal from a Python
 script?
In-Reply-To: <20140709014204.GM13014@ando>
References: <20140709014204.GM13014@ando>
Message-ID: <20140709051414.GA59032@cskk.homeip.net>

On 09Jul2014 11:42, Steven D'Aprano <steve at pearwood.info> wrote:
>On Tue, Jul 08, 2014 at 03:45:42PM -0500, Jim Byrnes wrote:
>> I would like to automate running virtualenv with a python script by:
>>
>> opening gnome-terminal
>> cd to proper directory
>> run source /bin/activate
>
>Why not just run /bin/activate directly from Python?
>
>os.chdir("the/proper/directory")
>os.system("/bin/activate")

Because "activate" needs to be sourced by the shell. It hacks the environment.

Cheers,
Cameron Simpson <cs at zip.com.au>

If at first you don't succeed, your sky-diving days are over.
         - Paul Blumstein, paulb at harley.tti.com, DoD #36

From alan.gauld at btinternet.com  Wed Jul  9 07:58:26 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 09 Jul 2014 06:58:26 +0100
Subject: [Tutor] Unpacking lists
In-Reply-To: <CAEGCHXsHdHiaGozp=grnvcLiOQJx1C5fxcc0NzVO5fg1EeR22w@mail.gmail.com>
References: <CAEGCHXsHdHiaGozp=grnvcLiOQJx1C5fxcc0NzVO5fg1EeR22w@mail.gmail.com>
Message-ID: <lpilm2$msn$1@ger.gmane.org>

On 09/07/14 02:44, Robert Nanney wrote:

> #!/usr/bin/python
> #list_test2.py
>
> list1 = [1, 8, 15]
> list2 = [2, 9, 16]
> list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
> list4 = [7, 14, 21]
> one_list = zip(list1, list2, list3, list4)
> first_round = [one_list[x][y] for x in range(len(list3)) for y in range(4)]

My first thought is that you are using indexing too much.
The above would be clearer using:

first_round = [tup[x] for tup in one_list for x in range(4)]

> second_round = []
> for i in first_round:
>      if not isinstance(i, list):
>          second_round.append(i)
>      else:
>          for x in range(len(i)):
>              second_round.append(i[x])

and this loop could be
     for item in i:
         second_round.append(item)

But I think list addition would do the job more easily.
Something like (untested)

second_round += i


> While this seems to do the trick, I feel there is probably a
> better/more pythonic way to accomplish the same thing.

I agree but I don;t have time right now to figure it out!
But it seems there should be a more straightforward method.

I'm thinking something like

result = []
for L in (list1,list2,list3):
     if isinstance(L,list)
        result += L
     else: result.append(L)

mebbe...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Wed Jul  9 08:16:39 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 09 Jul 2014 07:16:39 +0100
Subject: [Tutor] Unpacking lists
In-Reply-To: <lpilm2$msn$1@ger.gmane.org>
References: <CAEGCHXsHdHiaGozp=grnvcLiOQJx1C5fxcc0NzVO5fg1EeR22w@mail.gmail.com>
 <lpilm2$msn$1@ger.gmane.org>
Message-ID: <lpimo7$5tr$1@ger.gmane.org>

On 09/07/14 06:58, Alan Gauld wrote:

>> list1 = [1, 8, 15]
>> list2 = [2, 9, 16]
>> list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
>> list4 = [7, 14, 21]
> I'm thinking something like
>
> result = []
> for L in (list1,list2,list3):
>      if isinstance(L,list)
>         result += L
>      else: result.append(L)
>
> mebbe...

Too early in the morning...
There needs to be another loop around that.

for L in (list1,list2,list3):
    for index in len(list1):  #???
       if isinstance(L[index],list)
          result += L[index]
       else: result.append(L[index])

double mebbe.
Anyway I'm off to work... :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From wprins at gmail.com  Wed Jul  9 11:27:14 2014
From: wprins at gmail.com (Walter Prins)
Date: Wed, 9 Jul 2014 10:27:14 +0100
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lphl9m$8uh$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
Message-ID: <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>

Hi Jim,

On 8 July 2014 21:45, Jim Byrnes <jf_byrnes at comcast.net> wrote:

> I would like to automate running virtualenv with a python script by:
>
> opening gnome-terminal
> cd to proper directory
> run source /bin/activate
>
> I found some examples of using os.system() to get gnome-terminal to open
> but I can't figure out how then cd to the proper directory in the new
> terminal.
>
> My biggest frustration right now is that I can't find any documentation on
> how to use os.system().  Looking at the docs on the Python site I don't see
> system() under the os module.  Googling hasn't helped.
>
>
Could you explain what you're trying to achieve?  Virtualenv is about
setting up an OS/Unix shell environment (For Windows there's a Powershell
variant of virtualenv...) so that a custom Python installation is used by
default instead of the system wide on (including possibly using a custom
Python executable.)  It therefore seems that trying to automate
"activating" a virtualenv with python (which presumably would use the
system wide python) is not adding much value? Hence my question: What are
you actually trying to achieve?

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/bb2d2dea/attachment.html>

From s.shall at virginmedia.com  Wed Jul  9 12:35:13 2014
From: s.shall at virginmedia.com (Sydney Shall)
Date: Wed, 09 Jul 2014 12:35:13 +0200
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <CAGZAPF5aXm5s7qA2fVcTD5RNkLOBrMj7m0AVqWCmKSKHnhv3Vg@mail.gmail.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
 <53B2EA27.8050900@virginmedia.com> <53B40AE4.1070404@virginmedia.com>
 <CAGZAPF5aXm5s7qA2fVcTD5RNkLOBrMj7m0AVqWCmKSKHnhv3Vg@mail.gmail.com>
Message-ID: <53BD1AE1.40703@virginmedia.com>

On 06/07/2014 23:06, Danny Yoo wrote:
>> My apologies to the tutors.
>> I have identified my error, which was predictably elementary.
>> With many thanks,
>
> By the way, can you say what your conceptual error was or give an
> example?  It might help the other folks here who are learning and who
> may be making a similar mistake.  (And I'm curious!)  But if you don't
> want to say, that's ok too.
>
>
> Good luck!
>
Thanks Danny,

My error was simply that I inadvertently used the same name for a method 
(function) in the derived class that I had already used in the parent class.
The result was then a very obscure error because the wrong calculation 
was performed and later on an array was empty.
Fortunately, thanks to you very generous tutors I have learned to read 
the error trace very carefully indeed.
Thanks a lot.
Sydney

-- 
Sydney Shall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/76d92316/attachment.html>

From jf_byrnes at comcast.net  Wed Jul  9 15:43:49 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Wed, 09 Jul 2014 08:43:49 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
Message-ID: <lpjgul$aqi$1@ger.gmane.org>

On 07/09/2014 04:27 AM, Walter Prins wrote:
> Hi Jim,
>
> On 8 July 2014 21:45, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>
>> I would like to automate running virtualenv with a python script by:
>>
>> opening gnome-terminal
>> cd to proper directory
>> run source /bin/activate
>>
>> I found some examples of using os.system() to get gnome-terminal to open
>> but I can't figure out how then cd to the proper directory in the new
>> terminal.
>>
>> My biggest frustration right now is that I can't find any documentation on
>> how to use os.system().  Looking at the docs on the Python site I don't see
>> system() under the os module.  Googling hasn't helped.
>>
>>
> Could you explain what you're trying to achieve?  Virtualenv is about
> setting up an OS/Unix shell environment (For Windows there's a Powershell
> variant of virtualenv...) so that a custom Python installation is used by
> default instead of the system wide on (including possibly using a custom
> Python executable.)  It therefore seems that trying to automate
> "activating" a virtualenv with python (which presumably would use the
> system wide python) is not adding much value? Hence my question: What are
> you actually trying to achieve?
>
> Walter
>

I forgot to mention I am using Linux (Ubuntu 12.04).

I am working my way through a book about breezypythongui which uses 
Python 3, hence virtualenv.  I found that each time I started to work 
with it I did the above 3 steps, I was just looking to automatic that 
repetitive task.

Regards,  Jim



From jf_byrnes at comcast.net  Wed Jul  9 16:00:16 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Wed, 09 Jul 2014 09:00:16 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lphvg9$4r7$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org> <lphvg9$4r7$1@ger.gmane.org>
Message-ID: <lpjhtg$ouj$1@ger.gmane.org>

On 07/08/2014 06:39 PM, Alan Gauld wrote:
> On 08/07/14 21:45, Jim Byrnes wrote:
>> I would like to automate running virtualenv with a python script by:
>>
>> opening gnome-terminal
>> cd to proper directory
>> run source /bin/activate
>
> Thats almost certainly the wrong approach.
> Instead of trying to automate what the user does in the terminal replace
> the terminal with Python.
>
> Run the cd command from within Python (os.chdir())
> Run Activate from within Python (this is where os.system()
> could be used, but subprocess.call() is considered better
> practice.
>
>> I found some examples of using os.system() to get gnome-terminal to open
>> but I can't figure out how then cd to the proper directory in the new
>> terminal.
>
> You can't. os.system() just runs a command it has no way to interaxct5
> with the command, you do that manually. Its perfectly fine for
> displaying a directory listing (although os.listdir() would be better)
> or sending a file to a printer, or even opening a terminal/editor
> for the user to interact with. But its no good for your program
> interacting with it. Thats what subprocess is for.

Alan and the others that offered advice, thanks. I see that I have taken 
the wrong approach.  My intent was to automate something I was doing 
manually time after time and learn a little more Python as well.

>
>> My biggest frustration right now is that I can't find any documentation
>> on how to use os.system().  Looking at the docs on the Python site I
>> don't see system() under the os module.
>
> You should, although they don;t have a lot to say...
>

<snip>

>
>>  Googling hasn't helped.
>
> When you know the module use the browser search tools on the page itself
> - that's how I found it. I searched for os.system and it
> was the 3rd occurence.
>

My mistake.  I went to the Docs page and clicked on modules and then os. 
For some reason as I was scrolling down the page I thought the  subject 
had changed and stopped reading.  Now I see I stopped reading to soon as 
it is much further down the page.

Thanks,  Jim


From steve10brink at comcast.net  Wed Jul  9 17:00:03 2014
From: steve10brink at comcast.net (steve10brink at comcast.net)
Date: Wed, 9 Jul 2014 15:00:03 +0000 (UTC)
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <963705785.322795.1404917444303.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
Message-ID: <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>

Greetings, 


I've been learning Python concepts for about 6 months now and was doing okay with most of these. However, I ran into a fairly simple program developed by Mark Pilgrim in his "Dive Into Python" text that puzzles me and am hoping some of you can explain how this works. He is creating the Fibonoci sequence by iterating over a function that has a generator in it (i.e. no return statement). The code is as follows: 
---- 

def fibonacci(max): #using a generator 
a, b = 0, 1 
while a < max: 
yield a 
a, b = b, a+b 


for n in fibonacci(1000): 
print n, 
------ 


The program works beautifully buy I can't figure out what we are actually iterating with. When the function is called it 'yields' the value a which is then updated to b, etc. But what is the value of 'n' as it iterates through the function? I can understand iterating through lists, strings, range(), etc. but how this iterates through a function is puzzling me. Obviously the answer, n, is the Fibonocci series but by what mechanism does this work? What is the iterable component of a function? 


BTW, this is one of the many things that fascinates me about Python. It's easy to learn but also has some unique (at least to me) ways of doing things. 


Thanks, 
Steve Tenbrink 
Los Alamos, NM 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/c473238a/attachment.html>

From raulcumplido at gmail.com  Wed Jul  9 17:18:32 2014
From: raulcumplido at gmail.com (=?UTF-8?Q?Ra=C3=BAl_Cumplido?=)
Date: Wed, 9 Jul 2014 16:18:32 +0100
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
References: <963705785.322795.1404917444303.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
 <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
Message-ID: <CAD1RbrrTGf=qfhbTeYdiA0wH2UmOFngi_OZtsCq1uOZYYd=skg@mail.gmail.com>

Hi,

Let's see what happens iteration by iteration. First iteration:

def fibonacci(max):  #using a generator
>
    a, b = 0, 1
>
 # The value of a is 0 and b is 1, easy :)

>     while a < max:
>
        yield a
>
# yield a (0) (yield is a keyword that is used like return but returns a
generator). This value will be sent to the for iteration on the first
iteration.

On the second iteration:

>         a, b = b, a+b
>
# a is 1 now and b is 1 (1+0)
And then yield a which now is 1

On the third iteration:

>         a, b = b, a+b
>
# a is 1 now and b is 2 (1+1)
And then yield a which now is 1

On the forth iteration:

>         a, b = b, a+b
>
# a is 2 now and b is 3 (2+1)
And then yield a which now is 2


> for n in fibonacci(1000):
>     print n,
> ------
>

n is the value for each iteration that the yield statement is returning.
You can read the response on this thread if you want to understand more
about yield, generators and iterators.

Thanks,
Ra?l
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/2661e5a8/attachment-0001.html>

From raulcumplido at gmail.com  Wed Jul  9 17:24:46 2014
From: raulcumplido at gmail.com (=?UTF-8?Q?Ra=C3=BAl_Cumplido?=)
Date: Wed, 9 Jul 2014 16:24:46 +0100
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <CAD1RbrrTGf=qfhbTeYdiA0wH2UmOFngi_OZtsCq1uOZYYd=skg@mail.gmail.com>
References: <963705785.322795.1404917444303.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
 <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
 <CAD1RbrrTGf=qfhbTeYdiA0wH2UmOFngi_OZtsCq1uOZYYd=skg@mail.gmail.com>
Message-ID: <CAD1Rbrou1hDfxkBeJcB97361uwyNYq8tW7REk=mhUaVjeNNk2g@mail.gmail.com>

Hi,

A little bit more on this :)

Python iterator protocol will call the next() method on the iterator on
each iteration and receive the values from your iterator until a
StopIteration Exception is raised. This is how the for clause knows to
iterate. In your example below you can see this with the next example:

>>> gen = fibonacci(3)
>>> gen.next()
0
>>> gen.next()
1
>>> gen.next()
1
>>> gen.next()
2
>>> gen.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration
>>>

Thanks,
Ra?l


On Wed, Jul 9, 2014 at 4:18 PM, Ra?l Cumplido <raulcumplido at gmail.com>
wrote:

> Hi,
>
> Let's see what happens iteration by iteration. First iteration:
>
> def fibonacci(max):  #using a generator
>>
>     a, b = 0, 1
>>
>  # The value of a is 0 and b is 1, easy :)
>
>>     while a < max:
>>
>         yield a
>>
> # yield a (0) (yield is a keyword that is used like return but returns a
> generator). This value will be sent to the for iteration on the first
> iteration.
>
> On the second iteration:
>
>>         a, b = b, a+b
>>
> # a is 1 now and b is 1 (1+0)
> And then yield a which now is 1
>
> On the third iteration:
>
>>         a, b = b, a+b
>>
> # a is 1 now and b is 2 (1+1)
> And then yield a which now is 1
>
> On the forth iteration:
>
>>         a, b = b, a+b
>>
> # a is 2 now and b is 3 (2+1)
> And then yield a which now is 2
>
>
>> for n in fibonacci(1000):
>>     print n,
>> ------
>>
>
> n is the value for each iteration that the yield statement is returning.
> You can read the response on this thread if you want to understand more
> about yield, generators and iterators.
>
> Thanks,
> Ra?l
>



-- 
Ra?l Cumplido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/ccbbee12/attachment.html>

From fomcl at yahoo.com  Wed Jul  9 17:54:41 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Wed, 9 Jul 2014 08:54:41 -0700
Subject: [Tutor] Tkinter resizable menu??
In-Reply-To: <lphes6$bd7$1@ger.gmane.org>
References: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
 <lphes6$bd7$1@ger.gmane.org>
Message-ID: <1404921281.80966.YahooMailNeo@web163803.mail.gq1.yahoo.com>

?
----- Original Message -----
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Cc: 
> Sent: Tuesday, July 8, 2014 8:56 PM
> Subject: Re: [Tutor] Tkinter resizable menu??
> 
> On 08/07/14 16:46, Albert-Jan Roskam wrote:
>>  I pasted the code here because it is a bit much (sorry):
> 
> Too much for me, I gave up without spotting the problem.

Hi Peter, Alan, 

Yes, that was too much code indeed. Peter's suggestion helped though --thanks! After I added the row/columnfigure commands it was resizable. What? a lot of work for a small menu!
?
> One thing that did strike me though was that you spend quite
> a lot of code setting up scrollbars etc on your list boxes.
> 
> The Tix module has a scrollable listbox widget which is
> quite easy to use and does all that stuff for you.
> 
> Simply replace
> 
> import Tkinter as tk
> 
> with
> 
> import Tix as tk


Ahh, I will certainly look into that. Today somebody recommanded Python Megawidgets to me (http://pmw.sourceforge.net/). Might be something similar. I gets much more problem-oriented without all the 'mandatory' stuff like scrollbars.

Thanks again!

Albert-Jan

From codemonkey at inbox.com  Wed Jul  9 18:00:02 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Wed, 9 Jul 2014 08:00:02 -0800
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
References: <963705785.322795.1404917444303.javamail.root@sz0082a.emeryville.ca.mail.comcast.net>
Message-ID: <962EBEFA45E.00000D9Ecodemonkey@inbox.com>


> 
> Greetings,
> 
> 
> I've been learning Python concepts for about 6 months now and was doing
> okay with most of these. However, I ran into a fairly simple program
> developed by Mark Pilgrim in his "Dive Into Python" text that puzzles me
> and am hoping some of you can explain how this works. He is creating the
> Fibonoci sequence by iterating over a function that has a generator in it
> (i.e. no return statement). The code is as follows:
> ----
> 
> def fibonacci(max): #using a generator
> a, b = 0, 1
> while a < max:
> yield a
> a, b = b, a+b
> 
> 
> for n in fibonacci(1000):
> print n,
> ------
> 
> 
> Thanks,
> Steve Tenbrink
> Los Alamos, NM

I am pretty new to Python myself, so I don't know all that much, but you can get a visualization of how the code works at the following website.  It is a highly useful tool.  just copy/paste and step through. 

http://www.pythontutor.com/visualize.html#mode=edit

Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



From alan.gauld at btinternet.com  Wed Jul  9 18:33:00 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 09 Jul 2014 17:33:00 +0100
Subject: [Tutor] Tkinter resizable menu??
In-Reply-To: <1404921281.80966.YahooMailNeo@web163803.mail.gq1.yahoo.com>
References: <1404834396.20506.YahooMailNeo@web163806.mail.gq1.yahoo.com>
 <lphes6$bd7$1@ger.gmane.org>
 <1404921281.80966.YahooMailNeo@web163803.mail.gq1.yahoo.com>
Message-ID: <lpjqrs$ku3$1@ger.gmane.org>

On 09/07/14 16:54, Albert-Jan Roskam wrote:

>> The Tix module has a scrollable listbox widget which is
>> quite easy to use and does all that stuff for you.
>>
> Ahh, I will certainly look into that. Today
 > somebody recommanded Python Megawidgets to me

The PMW are fine too but Tix comes as part of the standard library.
Documentation isn't great though - you often find better
examples on the Tcl/Tk Tix site.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From dyoo at hashcollision.org  Wed Jul  9 20:17:35 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 9 Jul 2014 11:17:35 -0700
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <53BD1AE1.40703@virginmedia.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
 <53B2EA27.8050900@virginmedia.com> <53B40AE4.1070404@virginmedia.com>
 <CAGZAPF5aXm5s7qA2fVcTD5RNkLOBrMj7m0AVqWCmKSKHnhv3Vg@mail.gmail.com>
 <53BD1AE1.40703@virginmedia.com>
Message-ID: <CAGZAPF4Ws3SVx+7x3W5pmtygiwNnR+8XTvWNdO=Z1DPMbQo8kw@mail.gmail.com>

> My error was simply that I inadvertently used the same name for a method
> (function) in the derived class that I had already used in the parent class.
> The result was then a very obscure error because the wrong calculation was
> performed and later on an array was empty.
> Fortunately, thanks to you very generous tutors I have learned to read the
> error trace very carefully indeed.


Ah, yes, that one.  It's happened to me too.

It's one of the reasons why inheritance makes me nervous sometimes.
It's a problem that's fairly language-independent.

(If you'd like to know the details, the example that I was involved in
is described in the comments on:
https://github.com/bootstrapworld/js-numbers/pull/5.  Essentially, we
subclassed some base class, and wrote a method called BigNumber.exp()
to do exponentiation.  Unfortunately, we didn't realize that our
superclass already had defined an exp() method.  It ended up showing
up as a very strange, obscure error.  Same class of problem.)


Side note, Python does have a hack called "name mangling" that can be
used to try to avoid this problem:

    https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references


Good luck!

From steve10brink at comcast.net  Wed Jul  9 20:59:16 2014
From: steve10brink at comcast.net (steve10brink at comcast.net)
Date: Wed, 9 Jul 2014 18:59:16 +0000 (UTC)
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <mailman.65653.1404929884.18129.tutor@python.org>
Message-ID: <355789990.324667.1404932356211.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>



----- Original Message -----

I guess my higher level question is: "what makes this function iterable?" and the answer appears to be the fact that it 
uses a generator instead of a return function. Is that correct? 


-Steve Tenbrink 

---------------------------------------------------------------------- 

Message: 1 
Date: Wed, 9 Jul 2014 16:24:46 +0100 
From: Ra?l Cumplido <raulcumplido at gmail.com> 
To: steve10brink at comcast.net 
Cc: tutor <tutor at python.org> 
Subject: Re: [Tutor] How does this work (iterating over a function)? 
Message-ID: 
<CAD1Rbrou1hDfxkBeJcB97361uwyNYq8tW7REk=mhUaVjeNNk2g at mail.gmail.com> 
Content-Type: text/plain; charset="utf-8" 

Hi, 

A little bit more on this :) 

Python iterator protocol will call the next() method on the iterator on 
each iteration and receive the values from your iterator until a 
StopIteration Exception is raised. This is how the for clause knows to 
iterate. In your example below you can see this with the next example: 

>>> gen = fibonacci(3) 
>>> gen.next() 
0 
>>> gen.next() 
1 
>>> gen.next() 
1 
>>> gen.next() 
2 
>>> gen.next() 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
StopIteration 
>>> 

Thanks, 
Ra?l 





-- 
Ra?l Cumplido 
-------------- next part -------------- 
An HTML attachment was scrubbed... 
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/ccbbee12/attachment-0001.html> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/2e1040c6/attachment.html>

From raulcumplido at gmail.com  Wed Jul  9 21:19:02 2014
From: raulcumplido at gmail.com (=?UTF-8?Q?Ra=C3=BAl_Cumplido?=)
Date: Wed, 9 Jul 2014 20:19:02 +0100
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <355789990.324667.1404932356211.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
References: <mailman.65653.1404929884.18129.tutor@python.org>
 <355789990.324667.1404932356211.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
Message-ID: <CAD1RbrqV2BJDXmsoP2m4j2DuzT1TCXuVKGq=vXyq6nkzBJUiLA@mail.gmail.com>

Yes, every generator is an iterator (but not viceversa) and you can iterate
over an iterator.

An iterator is one object that implements the Python iterator protocol.

Thanks,
Ra?l


On Wed, Jul 9, 2014 at 7:59 PM, <steve10brink at comcast.net> wrote:

>
>
> ------------------------------
>
> I guess my higher level question is: "what makes this function iterable?"
> and the answer appears to be the fact that it
> uses a generator instead of a return function.  Is that correct?
>
> -Steve Tenbrink
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Wed, 9 Jul 2014 16:24:46 +0100
> From: Ra?l Cumplido <raulcumplido at gmail.com>
> To: steve10brink at comcast.net
> Cc: tutor <tutor at python.org>
> Subject: Re: [Tutor] How does this work (iterating over a function)?
> Message-ID:
>         <CAD1Rbrou1hDfxkBeJcB97361uwyNYq8tW7REk=
> mhUaVjeNNk2g at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
>
> Hi,
>
> A little bit more on this :)
>
> Python iterator protocol will call the next() method on the iterator on
> each iteration and receive the values from your iterator until a
> StopIteration Exception is raised. This is how the for clause knows to
> iterate. In your example below you can see this with the next example:
>
> >>> gen = fibonacci(3)
> >>> gen.next()
> 0
> >>> gen.next()
> 1
> >>> gen.next()
> 1
> >>> gen.next()
> 2
> >>> gen.next()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> StopIteration
> >>>
>
> Thanks,
> Ra?l
>
>
>
>
>
> --
> Ra?l Cumplido
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20140709/ccbbee12/attachment-0001.html
> >
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Ra?l Cumplido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/954d6ced/attachment.html>

From dyoo at hashcollision.org  Wed Jul  9 21:44:20 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 9 Jul 2014 12:44:20 -0700
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <CAD1RbrqV2BJDXmsoP2m4j2DuzT1TCXuVKGq=vXyq6nkzBJUiLA@mail.gmail.com>
References: <mailman.65653.1404929884.18129.tutor@python.org>
 <355789990.324667.1404932356211.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
 <CAD1RbrqV2BJDXmsoP2m4j2DuzT1TCXuVKGq=vXyq6nkzBJUiLA@mail.gmail.com>
Message-ID: <CAGZAPF5a88d=A+UBPKbh=TXpgwyOvOwBkRtMygB2VhqFdKTx0w@mail.gmail.com>

By the way, it may be really instructive to read the article when
generators were officially introduced into Python 2.2:

    https://docs.python.org/3/whatsnew/2.2.html#pep-255-simple-generators

It's written for the perspective of someone who doesn't know what
generators are.  Because of that, it should be fairly approachable.

From dyoo at hashcollision.org  Wed Jul  9 22:03:20 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 9 Jul 2014 13:03:20 -0700
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <CAGZAPF5a88d=A+UBPKbh=TXpgwyOvOwBkRtMygB2VhqFdKTx0w@mail.gmail.com>
References: <mailman.65653.1404929884.18129.tutor@python.org>
 <355789990.324667.1404932356211.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
 <CAD1RbrqV2BJDXmsoP2m4j2DuzT1TCXuVKGq=vXyq6nkzBJUiLA@mail.gmail.com>
 <CAGZAPF5a88d=A+UBPKbh=TXpgwyOvOwBkRtMygB2VhqFdKTx0w@mail.gmail.com>
Message-ID: <CAGZAPF4XmPgX1jvmMGCmgPp9p+DtYmeWJ_we0nyXpRU_xoYOJA@mail.gmail.com>

It might also be useful to see what an equivalent version of that
fib() iterator looks like if we don't take advantage of generators
ourselves.  Here's an attempt at it:

###############################################
def fib1(max):
    a, b, = 0, 1
    while a < max:
        yield a
        a, b, = b, a+b


class fib2(object):
    def __init__(self, max):
        self.max = max
        self.a, self.b = 0, 1

    def __iter__(self):
        return self

    def next(self):
        if self.a >= self.max:
            raise StopIteration
        result = self.a
        self.a, self.b = self.b, self.a + self.b
        return result


## We should see the same output between this:
for n in fib1(10):
    print n,
print
## and this:
for n in fib2(10):
    print n,
###############################################

fib1 is the original iterator of this thread.  fib2 is an iterator
that manages its state by itself.  The difference is that when we're
writing a generator, we can depend on the resuming part to restore our
state when we want to pick up the next value.  In contrast, in the
version without generators, we have to manage all that state
ourselves.

For this example, it's not necessarily hard, but it's slightly tedious.

That's why generators are so closely tied to iterators: generators
make it really easy to write an iterator.  You can write an iterator
without using the generator feature, but it can be a hassle.

From wolfgang.maier at biologie.uni-freiburg.de  Wed Jul  9 12:21:04 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Wed, 09 Jul 2014 12:21:04 +0200
Subject: [Tutor] Unpacking lists
In-Reply-To: <lpimo7$5tr$1@ger.gmane.org>
References: <CAEGCHXsHdHiaGozp=grnvcLiOQJx1C5fxcc0NzVO5fg1EeR22w@mail.gmail.com>
 <lpilm2$msn$1@ger.gmane.org> <lpimo7$5tr$1@ger.gmane.org>
Message-ID: <53BD1790.2000207@biologie.uni-freiburg.de>

On 09.07.2014 08:16, Alan Gauld wrote:
> On 09/07/14 06:58, Alan Gauld wrote:
>
>>> list1 = [1, 8, 15]
>>> list2 = [2, 9, 16]
>>> list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
>>> list4 = [7, 14, 21]
>> I'm thinking something like
>>
>> result = []
>> for L in (list1,list2,list3):
>>      if isinstance(L,list)
>>         result += L
>>      else: result.append(L)
>>
>> mebbe...
>
> Too early in the morning...
> There needs to be another loop around that.
>
> for L in (list1,list2,list3):
>     for index in len(list1):  #???
>        if isinstance(L[index],list)
>           result += L[index]
>        else: result.append(L[index])
>
> double mebbe.
> Anyway I'm off to work... :-)
>

The working solution closest to Alan's attempt appears to be:

list1 = [1, 8, 15]
list2 = [2, 9, 16]
list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
list4 = [7, 14, 21]

final = []
for outer in zip(list1, list2, list3, list4):
     for inner in outer:
         if isinstance(inner, list):
             final.extend(inner)
         else:
             final.append(inner)
print (final)

but his general idea is right.

Best,
Wolfgang

From jdcast at stanford.edu  Wed Jul  9 20:26:47 2014
From: jdcast at stanford.edu (John Cast)
Date: Wed, 9 Jul 2014 11:26:47 -0700
Subject: [Tutor] How to Create Webpage with Python
Message-ID: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>

First, please forgive any ignorance in my post here as I am not good with
HTML and new to python.

I have a bunch of excel spreadsheets (all in the same format) that I am
writing a python script to go through and pick out some information and
post to a wiki page. I'm new to python and have gone through some basic
tutorials. I feel confident that I can figure out how to read an excel
spreadsheet in python. However, I am feeling a bit overwhelmed with
figuring out how to do the web stuff in python. The webpage doesn't exist
yet and I have envisioned that the wiki webpage is created once and then
simply update it every time the script is run. However, I don't know much
about how persistence works with webpages.

I have two main questions:

1) Considering the webpage doesn't exist yet, do I need to 'serve' or
'post' a webpage (as was brought up below)?

2) How do I create this wiki webpage? and does this happen in python every
time the script is run?

3) How do I send my data to this webpage?

I don't have to have full blown answers here, just a link or advice or
anything to help me with navigating all of the information out there on
Google.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/c1804be8/attachment.html>

From wprins at gmail.com  Wed Jul  9 23:16:01 2014
From: wprins at gmail.com (Walter Prins)
Date: Wed, 9 Jul 2014 22:16:01 +0100
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lpjgul$aqi$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
Message-ID: <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>

Hi Jim,

On 9 July 2014 14:43, Jim Byrnes <jf_byrnes at comcast.net> wrote:

> On 07/09/2014 04:27 AM, Walter Prins wrote:
>
>> I forgot to mention I am using Linux (Ubuntu 12.04).
>>
>
> I am working my way through a book about breezypythongui which uses Python
> 3, hence virtualenv.  I found that each time I started to work with it I
> did the above 3 steps, I was just looking to automatic that repetitive task.
>

In that case you should put these commands in your .bashrc file so it gets
set up as your user's default.  (The .bashrc file is somewhat like DOS's
"autoexec.bat" file, if you're familiar with this, except each user has
their own .bashrc.)  You can also create a shell script that does this for
you.  (You can install "virtualenv wrapper" which gives you some further
commands to make working with virtualenvs easier.)

Regards

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/6bd1e68b/attachment.html>

From wprins at gmail.com  Thu Jul 10 00:00:52 2014
From: wprins at gmail.com (Walter Prins)
Date: Wed, 9 Jul 2014 23:00:52 +0100
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
Message-ID: <CANLXbfA45ZOA8cRso3GNrSSvUU7UH_qnx-0sQa+c6HFNaiVHdg@mail.gmail.com>

Hi John,

Welcome you to the Python tutor mailing list.

On 9 July 2014 19:26, John Cast <jdcast at stanford.edu> wrote:
>
> First, please forgive any ignorance in my post here as I am not good with HTML and new to python.

Not a problem.  Although the list if formally about learning the
basics of Python, there's many people on here with both diverse and
deep knowledge so people often get lucky with what would be formally
off-topic questions.

> I have a bunch of excel spreadsheets (all in the same format) that I am writing a python script to go through and pick out some information and post to a wiki page. I'm new to python and have gone through some basic tutorials. I feel confident that I can figure out how to read an excel spreadsheet in python.

I imagine you're referring to using the xlrd module?

> However, I am feeling a bit overwhelmed with figuring out how to do the web stuff in python. The webpage doesn't exist yet and I have envisioned that the wiki webpage is created once and then simply update it every time the script is run. However, I don't know much about how persistence works with webpages.

OK...

> I have two main questions:
>
> 1) Considering the webpage doesn't exist yet, do I need to 'serve' or 'post' a webpage (as was brought up below)?

That depends. Actually both approaches are feasible but to make a
choice either way would depend really on what you're actually trying
to achieve and what constraints you operate under in terms of web
server/hosting.

> 2) How do I create this wiki webpage? and does this happen in python every time the script is run?
>
> 3) How do I send my data to this webpage?


Again, that depends.

You need to decide what approach would suit your context better:

1) Generating a static HTML website from your data
======================================

Pros:
- Hosts anywhere, not backend Python required
- Setup, Management and generation is relatively straightforward, and
web pages themselves can be written up in e.g. simple text formats
(Markdown etc)
- Light, fast
- Easy to version control

Cons:
- No DB backend so site is less interactive than it would otherwise be.

Example: Pelican web framework for Python.  See here:
http://pelican.readthedocs.org/en/3.4.0/ and here:
http://blog.getpelican.com/

2) Build a website with Python on the back-end
==================================

Pros:
- Much more flexible.
- You can pretty much do anything
- Setup and management is more involved/complex.

Cons
- Usually not quite as fast as a static site
- Requires hosting that can comply with your backend needs (Python +
whatever framework you want to use.)

Examples:
- Django web framework:  https://www.djangoproject.com/
- Web2py web framework: http://www.web2py.com/

There's of course a myriad of related and alternatives to what I've
mentioned above which may or may not be applicable to what you're
doing but without knowing more about your operational and other
requirements it's impossible to make further suggestions.  I just want
to address one other point -- you mention the term "wiki", note that
the items I've mentioned aren't wiki's in their own right, however if
you really do want wiki functionality then just to note that there are
Python powered CMS's and wiki's as well (some powered by the
framework's I've mentioned).

Hope that helps,

Walter

From alan.gauld at btinternet.com  Thu Jul 10 00:08:55 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 09 Jul 2014 23:08:55 +0100
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
Message-ID: <lpkeho$euv$1@ger.gmane.org>

On 09/07/14 19:26, John Cast wrote:

> I have a bunch of excel spreadsheets (all in the same format) that I am
> writing a python script to go through and pick out some information and
> post to a wiki page. I'm new to python and have gone through some basic
> tutorials. I feel confident that I can figure out how to read an excel
> spreadsheet in python.

Its trickier than you might think.
But there are a couple of third party modules you can download.
Google is your friend.

> figuring out how to do the web stuff in python.

Python has lots of web frameworks and to be honest there isn't
much to choose between them IMHO. They are all fairly easy to
use and offer the same kind of things.

> The webpage doesn't exist yet and I have envisioned that the
 > wiki webpage is created once and then simply
 > update it every time the script is run.

Thats OK. whats not clear is where you intend to host this 'wiki'?
Is it a traditional hosting company? If so you need to create
the new html file and copy it to the hosting site (maybe using
ftp - Python has an ftp module). But if you are hosting the site
on your own server then you can create the HTML file directly
on the host server.

> However, I don't know much about how persistence works with webpages.

I'm not sure what you mean by persistence?
You could do it in several ways but the easiest way is to just recreate 
the page each time from a template but substituting the latest data.
But another way is to have a dynamic web page that reads the data from a 
database either on the server or via JSON (requires some minimal 
JavaScripting)

> 1) Considering the webpage doesn't exist yet, do I need to 'serve' or
> 'post' a webpage (as was brought up below)?

where below?

You need a web server somewhere. Either you provide it yourself or
you hire space on a web providers estate.

> 2) How do I create this wiki webpage? and does this happen in python
> every time the script is run?

Lots of options. It depends on how you want it to run, how often it gets 
updated, which web framework you choose etc.

> 3) How do I send my data to this webpage?

See my comments above, but again it depends a lot on where
the web site lives...


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From breamoreboy at yahoo.co.uk  Thu Jul 10 00:16:00 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Wed, 09 Jul 2014 23:16:00 +0100
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
Message-ID: <lpkeut$ja5$1@ger.gmane.org>

On 09/07/2014 19:26, John Cast wrote:
> First, please forgive any ignorance in my post here as I am not good
> with HTML and new to python.
>
> I have a bunch of excel spreadsheets (all in the same format) that I am
> writing a python script to go through and pick out some information and
> post to a wiki page. I'm new to python and have gone through some basic
> tutorials. I feel confident that I can figure out how to read an excel
> spreadsheet in python. However, I am feeling a bit overwhelmed with
> figuring out how to do the web stuff in python. The webpage doesn't
> exist yet and I have envisioned that the wiki webpage is created once
> and then simply update it every time the script is run. However, I don't
> know much about how persistence works with webpages.
>
> I have two main questions:
>
> 1) Considering the webpage doesn't exist yet, do I need to 'serve' or
> 'post' a webpage (as was brought up below)?
>
> 2) How do I create this wiki webpage? and does this happen in python
> every time the script is run?
>
> 3) How do I send my data to this webpage?
>
> I don't have to have full blown answers here, just a link or advice or
> anything to help me with navigating all of the information out there on
> Google.
>
> Thanks
>

For the excel side see http://www.python-excel.org/

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From mnickey at gmail.com  Thu Jul 10 00:40:46 2014
From: mnickey at gmail.com (Mike Nickey)
Date: Wed, 9 Jul 2014 15:40:46 -0700
Subject: [Tutor] Off topic - Ruby similar list?
Message-ID: <CAEywD5D-iv67khoHiCgdEvuq-K6Hf9U1W7gUmuB-kOfXtfHQog@mail.gmail.com>

Just curious if there's a similar list like this one for Ruby-ists.
Anyone know of one or two?
TIA

-- 
~MEN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/426c1e86/attachment.html>

From dyoo at hashcollision.org  Thu Jul 10 00:52:24 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 9 Jul 2014 15:52:24 -0700
Subject: [Tutor] Off topic - Ruby similar list?
In-Reply-To: <CAEywD5D-iv67khoHiCgdEvuq-K6Hf9U1W7gUmuB-kOfXtfHQog@mail.gmail.com>
References: <CAEywD5D-iv67khoHiCgdEvuq-K6Hf9U1W7gUmuB-kOfXtfHQog@mail.gmail.com>
Message-ID: <CAGZAPF644=G3wD516ezgQtBL=Mc6XobCMY8WkARa26z=XPGtbw@mail.gmail.com>

On Wed, Jul 9, 2014 at 3:40 PM, Mike Nickey <mnickey at gmail.com> wrote:
> Just curious if there's a similar list like this one for Ruby-ists.
> Anyone know of one or two?


Hi Mike,

I believe the general ruby-talk mailing list is what you're looking for.  See:

    https://www.ruby-lang.org/en/community/mailing-lists/

From cs at zip.com.au  Thu Jul 10 00:40:37 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Thu, 10 Jul 2014 08:40:37 +1000
Subject: [Tutor] How can I open and use gnome-terminal from a Python
 script?
In-Reply-To: <lpjhtg$ouj$1@ger.gmane.org>
References: <lpjhtg$ouj$1@ger.gmane.org>
Message-ID: <20140709224037.GA43927@cskk.homeip.net>

On 09Jul2014 09:00, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>My mistake.  I went to the Docs page and clicked on modules and then os. For some reason as I was scrolling down the page I thought the subject had changed and stopped reading.  Now I see I stopped reading to soon as it is much further down the page.

When searching for doco on particular functions I find the Index is a good 
place. Go to the "S" section and find "system"; there should be a link directly 
to the relevant doc section.

Cheers,
Cameron Simpson <cs at zip.com.au>

In theory, there is no difference between theory and practice.
In practice, there is. - Yogi Berra

From cs at zip.com.au  Thu Jul 10 00:44:09 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Thu, 10 Jul 2014 08:44:09 +1000
Subject: [Tutor] How can I open and use gnome-terminal from a Python
 script?
In-Reply-To: <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
References: <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
Message-ID: <20140709224409.GA46336@cskk.homeip.net>

On 09Jul2014 22:16, Walter Prins <wprins at gmail.com> wrote:
>On 9 July 2014 14:43, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>> On 07/09/2014 04:27 AM, Walter Prins wrote:
>>> I forgot to mention I am using Linux (Ubuntu 12.04).
>>
>> I am working my way through a book about breezypythongui which uses Python
>> 3, hence virtualenv.  I found that each time I started to work with it I
>> did the above 3 steps, I was just looking to automatic that repetitive task.
>
>In that case you should put these commands in your .bashrc file so it gets
>set up as your user's default.  (The .bashrc file is somewhat like DOS's
>"autoexec.bat" file, if you're familiar with this, except each user has
>their own .bashrc.)

I am aginst this. It makes _every_ one of your interactive bash instances 
(assuming you're even using bash, though that is probable) use that virtualenv.

>You can also create a shell script that does this for
>you.  (You can install "virtualenv wrapper" which gives you some further
>commands to make working with virtualenvs easier.)

I think this is a better approach.

Even a tiny shell script that sources activate and then execs "$SHELL" (your 
shell, whatever one it is) will ease your pain. Eg:

   #!/bin/sh
   . /path/to/venv/bin/activate
   exec "${SHELL:-/bin/sh}"

Cheers,
Cameron Simpson <cs at zip.com.au>

Many are stubborn in pursuit of the path they have chosen, few in pursuit
of the goal. - Friedrich Nietzsche

From cs at zip.com.au  Thu Jul 10 02:38:00 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Thu, 10 Jul 2014 10:38:00 +1000
Subject: [Tutor] How does this work (iterating over a function)?
In-Reply-To: <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
References: <738796078.322834.1404918003848.JavaMail.root@sz0082a.emeryville.ca.mail.comcast.net>
Message-ID: <20140710003800.GA82804@cskk.homeip.net>

On 09Jul2014 15:00, steve10brink at comcast.net <steve10brink at comcast.net> wrote:
>I've been learning Python concepts for about 6 months now and was doing okay with most of these. However, I ran into a fairly simple program developed by Mark Pilgrim in his "Dive Into Python" text that puzzles me and am hoping some of you can explain how this works. He is creating the Fibonoci sequence by iterating over a function that has a generator in it (i.e. no return statement).
>The code is as follows:
>
>def fibonacci(max): #using a generator
>a, b = 0, 1
>while a < max:
>yield a
>a, b = b, a+b

Please post in plain text, not HTML. Something is eating your code indentation.

Returning to your question:

>for n in fibonacci(1000):
>print n,
>
>The program works beautifully buy I can't figure out what we are actually iterating with. When the function is called it 'yields' the value a which is then updated to b, etc. But what is the value of 'n' as it iterates through the function? I can understand iterating through lists, strings, range(), etc. but how this iterates through a function is puzzling me. Obviously the answer, n, is the Fibonocci series but by what mechanism does this work? What is the iterable component of a function?

Other have tried to explain, but let me try a different metaphor.

Pretend (or actually try) the fibonacci() function says: "print a" instead of "yield a".

You can see then that it will print the sequence directly.

When you write a generator function (a function with yield statements), what 
you get back when you call it is an iterator which iterates over the values the 
"yield"s produce.

It is a little like a pipeline: the "for" loop acts as though it is reading the 
values from the yields (or prints).

What happens is that when you call "fibonacci", it sets up the function in 
memory and _does not run it_.

When the "for" loop iterates, the function runs until it hits a "uyield" 
statement. And stalls. The "for" loop gets the yielded value and does whatever.  
Next time the for loop iterates the "fibonacci" function runs again, briefly, 
until the next "yield".

I hope this helps you visualise the process.

Cheers,
Cameron Simpson <cs at zip.com.au>

From jdcast at stanford.edu  Thu Jul 10 03:30:05 2014
From: jdcast at stanford.edu (John Cast)
Date: Wed, 9 Jul 2014 18:30:05 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <lpkeut$ja5$1@ger.gmane.org>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
Message-ID: <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>

Thanks everyone for the tremendous and speedy support!

Here's a bit more information that I think would be useful:

I will be hosting this (for the foreseeable future at least) on my desktop.
There is another python script already written that generates the excel
spreadsheets (I did not write this).  That script will be ran on a fairly
frequent basis so the webpage will constantly have its information updated.

I'm in unfamiliar territory with the web stuff, but it sounds so far like I
will generate an HTML doc every time I run my script and then somehow turn
that HTML doc into a static site?  (My terminology is weak here I'm sure)
I use the term wiki very loosely.  I'm basically just wanting to write my
excel information (possibly with some formatting) to one page (or maybe one
page per excel sheet...not really sure...more worried about getting the
basics for right now) that others can then navigate to.  Interaction with
this page, is at the moment, unnecessary.

So this is what I have gathered from all of your input so far:

Excel - I didn't have a module in mind just yet, but it looks like xlrd is
my best bet

Web - Currently it looks like maybe static HTML page(s) generated every
time my script is run is the right way to go?
          It sounds like I need a server on my desktop?
          I need to create a site and host/serve this somehow using my
server?
          I don't need a webframework to do this?
          Need some mechanism to get these HTML page(s) to my site?


I welcome any further input anyone is willing to give!

Thanks


On Wed, Jul 9, 2014 at 3:16 PM, Mark Lawrence <breamoreboy at yahoo.co.uk>
wrote:

> On 09/07/2014 19:26, John Cast wrote:
>
>> First, please forgive any ignorance in my post here as I am not good
>> with HTML and new to python.
>>
>> I have a bunch of excel spreadsheets (all in the same format) that I am
>> writing a python script to go through and pick out some information and
>> post to a wiki page. I'm new to python and have gone through some basic
>> tutorials. I feel confident that I can figure out how to read an excel
>> spreadsheet in python. However, I am feeling a bit overwhelmed with
>> figuring out how to do the web stuff in python. The webpage doesn't
>> exist yet and I have envisioned that the wiki webpage is created once
>> and then simply update it every time the script is run. However, I don't
>> know much about how persistence works with webpages.
>>
>> I have two main questions:
>>
>> 1) Considering the webpage doesn't exist yet, do I need to 'serve' or
>> 'post' a webpage (as was brought up below)?
>>
>> 2) How do I create this wiki webpage? and does this happen in python
>> every time the script is run?
>>
>> 3) How do I send my data to this webpage?
>>
>> I don't have to have full blown answers here, just a link or advice or
>> anything to help me with navigating all of the information out there on
>> Google.
>>
>> Thanks
>>
>>
> For the excel side see http://www.python-excel.org/
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask what
> you can do for our language.
>
> Mark Lawrence
>
> ---
> This email is free from viruses and malware because avast! Antivirus
> protection is active.
> http://www.avast.com
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140709/010c2767/attachment-0001.html>

From mandardhadve55 at gmail.com  Thu Jul 10 06:17:44 2014
From: mandardhadve55 at gmail.com (Mandar Dhadve)
Date: Thu, 10 Jul 2014 09:47:44 +0530
Subject: [Tutor] plz find error
Message-ID: <CAD4aLDqxXZe7w+s1gTX5X71vio5nw8Zs0k8KWmLkpixnocmgEg@mail.gmail.com>

#!/usr/bin/env python

import socket,sys
from impacket import ImpactDecoder, ImpactPacket

src = sys.argv[1]
dst = sys.argv[2]

#Create a new IP packet and set its source and destination addresses

ip = ImpactPacket.IP()
ip.set_ip_src(src)
ip.set_ip_dst(dst)

#Create a new ICMP packet

icmp = ImpactPacket.ICMP()
icmp.set_icmp_type(icmp.ICMP_ECHO)

#inlude a small payload inside the ICMP packet
#and have the ip packet contain the ICMP packet
icmp.contains(ImpactPacket.Data("a"*100))
ip.contains(icmp)

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

#give the ICMP packet some ID
icmp.set_icmp_id(1)
#calculate checksum
icmp.set_icmp_cksum(0)
icmp.auto_checksum = 0
s.sendto(ip.get_packet(), (dst, 0))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140710/d6757a62/attachment.html>

From cs at zip.com.au  Thu Jul 10 09:23:27 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Thu, 10 Jul 2014 17:23:27 +1000
Subject: [Tutor] plz find error
In-Reply-To: <CAD4aLDqxXZe7w+s1gTX5X71vio5nw8Zs0k8KWmLkpixnocmgEg@mail.gmail.com>
References: <CAD4aLDqxXZe7w+s1gTX5X71vio5nw8Zs0k8KWmLkpixnocmgEg@mail.gmail.com>
Message-ID: <20140710072327.GA28360@cskk.homeip.net>

On 10Jul2014 09:47, Mandar Dhadve <mandardhadve55 at gmail.com> wrote:
>#!/usr/bin/env python
[... short program to send ICMP packets, purpose undescribed ...]

Hi Mandar,

Please describe the purpose and background of this program, and describe in 
what way it fails. Include a transcript of a failed run if possible.

Just supplying some code without any accompanying text isn't very helpful to 
the people who may help you.

Thanks,
Cameron Simpson <cs at zip.com.au>

... It beeped and said "Countdown initiated." Is that bad?

From breamoreboy at yahoo.co.uk  Thu Jul 10 10:15:59 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Thu, 10 Jul 2014 09:15:59 +0100
Subject: [Tutor] plz find error
In-Reply-To: <20140710072327.GA28360@cskk.homeip.net>
References: <CAD4aLDqxXZe7w+s1gTX5X71vio5nw8Zs0k8KWmLkpixnocmgEg@mail.gmail.com>
 <20140710072327.GA28360@cskk.homeip.net>
Message-ID: <lpli41$uo8$1@ger.gmane.org>

On 10/07/2014 08:23, Cameron Simpson wrote:
> On 10Jul2014 09:47, Mandar Dhadve <mandardhadve55 at gmail.com> wrote:
>> #!/usr/bin/env python
> [... short program to send ICMP packets, purpose undescribed ...]
>
> Hi Mandar,
>
> Please describe the purpose and background of this program, and describe
> in what way it fails. Include a transcript of a failed run if possible.
>
> Just supplying some code without any accompanying text isn't very
> helpful to the people who may help you.
>

For the OP and anybody else who may be interested http://sscce.org/

> Thanks,
> Cameron Simpson <cs at zip.com.au>
>
> ... It beeped and said "Countdown initiated." Is that bad?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From wprins at gmail.com  Thu Jul 10 10:39:37 2014
From: wprins at gmail.com (Walter Prins)
Date: Thu, 10 Jul 2014 09:39:37 +0100
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
Message-ID: <CANLXbfBCA61EYae1tbY+s9ZugqJnWs5Q70jXpB_6rPqZQd4H7A@mail.gmail.com>

Hi,

On 10 July 2014 02:30, John Cast <jdcast at stanford.edu> wrote:
> Web - Currently it looks like maybe static HTML page(s) generated every time
> my script is run is the right way to go?

It would be one way to proceed, yes, perhaps the most appropriate way
for you for now.

>           It sounds like I need a server on my desktop?

Note that Python includes in the Python standard library a simple HTTP
web server (module SimpleHTTPServer, in Python 3x http.server) which
can be used by itself and is often used (sometimes with
embellishments) by many/most of the Python web frameworks to run web
servers for development/small scale use.

Concretely: you run a command that start a simple Python based HTTP
server that then serves up the generated or development site from your
local machine for review/development purposes.   In the most basic
case you open a command prompt, change directory to your HTML site
contents, then run the command: python -m SimpleHTTPServer

Proper production deployment will depend on the nature of the site.

For a static site (meaning it is in essence just HTML pages), you
would push the site to some suitable webserver you've installed
somewhere (Apache, Nginx, IIS etc.)

For a dynamic site using a web framework you'd need a web server
configured to run your Python based site, meaning you'd need for
example Apache + mod_wsgi with Python and your chosen web framework
installed, in addition to any Database requirements/dependencies (for
example MySQL or PostgreSQL).

>           I need to create a site and host/serve this somehow using my
> server?

Assuming you're going be generating static HTML pages, yes.

>           I don't need a webframework to do this?

No, but you need something to help you generate the HTML pages.
Unless you just want to generate them yourself from absolute scratch,
which of course you can also do.

>           Need some mechanism to get these HTML page(s) to my site?

For a static site, deploying it means copying the site contents (HTML
files and attendant resources) to the correct folder by whatever means
is most convenient, from which the production web server will the
serve it to the intended audience.  An FTP client would be one way,
assuming the web server also has FTP access.  Another would be to make
the web server's root folder into a version control repository (e.g.
git, mercurial or such.) Serving directly from a version control
repository (e.g. say git) would mean you can in essence simply "push"
changes to the live website once you'e happy with your changes.
Regardless of how you deploy it, using version control is recommended
as it will allow you to properly manage your site over time, for
example reverting to a previous version in case of problems.

Walter

From s.shall at virginmedia.com  Thu Jul 10 12:27:54 2014
From: s.shall at virginmedia.com (Sydney Shall)
Date: Thu, 10 Jul 2014 12:27:54 +0200
Subject: [Tutor] A beginner having problems with inheritance
In-Reply-To: <CAGZAPF4Ws3SVx+7x3W5pmtygiwNnR+8XTvWNdO=Z1DPMbQo8kw@mail.gmail.com>
References: <CABmD0bHiCZYfi-3LmzZu371sN+0wT-T_0oc1B++qjkZJOxBSPQ@mail.gmail.com>
 <20140612123105.GD10355@ando>
 <CAHvkzykQ5u2et3Hif4rPudCbOUemi-Nx5gsDs+ZJpcvV_Y6fpg@mail.gmail.com>
 <53B2EA27.8050900@virginmedia.com> <53B40AE4.1070404@virginmedia.com>
 <CAGZAPF5aXm5s7qA2fVcTD5RNkLOBrMj7m0AVqWCmKSKHnhv3Vg@mail.gmail.com>
 <53BD1AE1.40703@virginmedia.com>
 <CAGZAPF4Ws3SVx+7x3W5pmtygiwNnR+8XTvWNdO=Z1DPMbQo8kw@mail.gmail.com>
Message-ID: <53BE6AAA.5050605@virginmedia.com>

On 09/07/2014 20:17, Danny Yoo wrote:
>> My error was simply that I inadvertently used the same name for a method
>> (function) in the derived class that I had already used in the parent class.
>> The result was then a very obscure error because the wrong calculation was
>> performed and later on an array was empty.
>> Fortunately, thanks to you very generous tutors I have learned to read the
>> error trace very carefully indeed.
>
> Ah, yes, that one.  It's happened to me too.
>
> It's one of the reasons why inheritance makes me nervous sometimes.
> It's a problem that's fairly language-independent.
>
> (If you'd like to know the details, the example that I was involved in
> is described in the comments on:
> https://github.com/bootstrapworld/js-numbers/pull/5.  Essentially, we
> subclassed some base class, and wrote a method called BigNumber.exp()
> to do exponentiation.  Unfortunately, we didn't realize that our
> superclass already had defined an exp() method.  It ended up showing
> up as a very strange, obscure error.  Same class of problem.)
>
>
> Side note, Python does have a hack called "name mangling" that can be
> used to try to avoid this problem:
>
>      https://docs.python.org/2/tutorial/classes.html#private-variables-and-class-local-references
>
>
> Good luck!
>
Thanks for the reply.
I had read the second reference that you gave some time ago, but of 
course I had forgotten about it.
I shall try and make use of it now.
Thanks for the help.

-- 
Sydney Shall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140710/311461ae/attachment.html>

From wolfgang.maier at biologie.uni-freiburg.de  Thu Jul 10 09:24:05 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Thu, 10 Jul 2014 09:24:05 +0200
Subject: [Tutor] plz find error
In-Reply-To: <CAD4aLDqxXZe7w+s1gTX5X71vio5nw8Zs0k8KWmLkpixnocmgEg@mail.gmail.com>
References: <CAD4aLDqxXZe7w+s1gTX5X71vio5nw8Zs0k8KWmLkpixnocmgEg@mail.gmail.com>
Message-ID: <53BE3F95.7000804@biologie.uni-freiburg.de>

plz provide info :(

State the problem you are trying to solve and your program's expected 
output.
Include any error messages you are getting - the full
text not a summary.
It's also helpful if you state the Python and OS version you are using.



From kwpolska at gmail.com  Thu Jul 10 14:28:26 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Thu, 10 Jul 2014 14:28:26 +0200
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
Message-ID: <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>

On Thu, Jul 10, 2014 at 3:30 AM, John Cast <jdcast at stanford.edu> wrote:
> I'm in unfamiliar territory with the web stuff, but it sounds so far like I
> will generate an HTML doc every time I run my script and then somehow turn
> that HTML doc into a static site?  (My terminology is weak here I'm sure)

If you go with the static website route, you will have to:

(a) generate a reStructuredText/Markdown/HTML file that your static
site generator (like Pelican, or Nikola* <http://getnikola.com/>) will
turn into a nice, pretty website for you, or
(b) just generate one HTML file, skipping the ?static site generator? part.

> Web - Currently it looks like maybe static HTML page(s) generated every time
> my script is run is the right way to go?

Yes ? it?s generally easier and nicer to do this, unless you were to
run your script very, VERY often.

>           It sounds like I need a server on my desktop?
>           I need to create a site and host/serve this somehow using my
> server?

Hosting websites off a desktop can be troublesome.  Your computer must
stay on all the time (or at least at the times when the website should
be accessible), you have to get a static IP, or use a dynamic DNS
service, and that?s assuming your ISP won?t hate you for hosting a
website.  It might be better to use an actual server instead.

>           I don't need a webframework to do this?

If you?re staying with static webpages, then yes.

* disclaimer: I?m quite involved with Nikola?s development; however,
even with that aside, I believe Nikola is much more human-friendly
than Pelican.  To each their own, though.

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From jf_byrnes at comcast.net  Thu Jul 10 16:15:00 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Thu, 10 Jul 2014 09:15:00 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <20140709224037.GA43927@cskk.homeip.net>
References: <lpjhtg$ouj$1@ger.gmane.org>
 <20140709224037.GA43927@cskk.homeip.net>
Message-ID: <lpm754$ign$1@ger.gmane.org>

On 07/09/2014 05:40 PM, Cameron Simpson wrote:
> On 09Jul2014 09:00, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>> My mistake.  I went to the Docs page and clicked on modules and then
>> os. For some reason as I was scrolling down the page I thought the
>> subject had changed and stopped reading.  Now I see I stopped reading
>> to soon as it is much further down the page.
>
> When searching for doco on particular functions I find the Index is a
> good place. Go to the "S" section and find "system"; there should be a
> link directly to the relevant doc section.
>
> Cheers,
> Cameron Simpson <cs at zip.com.au>
>

There was, thanks for the tip.

Regards,  Jim



From jf_byrnes at comcast.net  Thu Jul 10 16:23:04 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Thu, 10 Jul 2014 09:23:04 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
 <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
Message-ID: <lpm7k9$ojq$1@ger.gmane.org>

On 07/09/2014 04:16 PM, Walter Prins wrote:
> Hi Jim,
>
> On 9 July 2014 14:43, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>
>> On 07/09/2014 04:27 AM, Walter Prins wrote:
>>
>>> I forgot to mention I am using Linux (Ubuntu 12.04).
>>>
>>
>> I am working my way through a book about breezypythongui which uses Python
>> 3, hence virtualenv.  I found that each time I started to work with it I
>> did the above 3 steps, I was just looking to automatic that repetitive task.
>>
>
> In that case you should put these commands in your .bashrc file so it gets
> set up as your user's default.  (The .bashrc file is somewhat like DOS's
> "autoexec.bat" file, if you're familiar with this, except each user has
> their own .bashrc.)  You can also create a shell script that does this for
> you.  (You can install "virtualenv wrapper" which gives you some further
> commands to make working with virtualenvs easier.)
>
> Regards
>
> Walter
>

I realize I could have used a shell script but since I was working with 
Python I thought I might learn some more Python by trying to use it.  As 
it turns out, I did learn quite a bit through this discussion.

Thanks for the pointer to virtualenv wrapper.

Regards,  Jim



From breamoreboy at yahoo.co.uk  Thu Jul 10 18:43:31 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Thu, 10 Jul 2014 17:43:31 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
Message-ID: <lpmfrm$6tj$1@ger.gmane.org>

Just came across this and thought it might be handy for newbies, lurkers 
and the like http://lignos.org/py_antipatterns/

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From akleider at sonic.net  Thu Jul 10 18:40:07 2014
From: akleider at sonic.net (Alex Kleider)
Date: Thu, 10 Jul 2014 09:40:07 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
Message-ID: <ce973d35eaed62ec314b893fddcde413@sonic.net>

On 2014-07-10 05:28, Chris ?Kwpolska? Warrick wrote:
> On Thu, Jul 10, 2014 at 3:30 AM, John Cast <jdcast at stanford.edu> wrote:

>>           It sounds like I need a server on my desktop?
>>           I need to create a site and host/serve this somehow using my
>> server?
> 
> Hosting websites off a desktop can be troublesome.  Your computer must
> stay on all the time (or at least at the times when the website should
> be accessible), you have to get a static IP, or use a dynamic DNS
> service, and that?s assuming your ISP won?t hate you for hosting a
> website.  It might be better to use an actual server instead.

If all you want is to check how your 'site' looks perhaps it'd be much 
simpler to simply point your browser to your parent html file rather 
than set up a server machine to serve it:
file:///home/yourusername/yoursubdirectory/index.html
It'll look exactly the same as it would if you were running it on a 
server.
(or am I missing something?)

From kwpolska at gmail.com  Thu Jul 10 19:24:20 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Thu, 10 Jul 2014 19:24:20 +0200
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <ce973d35eaed62ec314b893fddcde413@sonic.net>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
Message-ID: <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>

On Thu, Jul 10, 2014 at 6:40 PM, Alex Kleider <akleider at sonic.net> wrote:
> If all you want is to check how your 'site' looks perhaps it'd be much
> simpler to simply point your browser to your parent html file rather than
> set up a server machine to serve it:
> file:///home/yourusername/yoursubdirectory/index.html
> It'll look exactly the same as it would if you were running it on a server.
> (or am I missing something?)

JavaScript may not work.  The same might also happen with links and
resources using the // scheme (//example.com/ instead of
http://example.com/)

For local testing, use

    python -m SimpleHTTPServer

or, if you?re on Python 3,

    python3 -m http.server

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From alan.gauld at btinternet.com  Thu Jul 10 18:59:47 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 10 Jul 2014 17:59:47 +0100
Subject: [Tutor] Gmane archive/web site
Message-ID: <53BEC683.9000003@btinternet.com>

I just tried accessing gmane and the web site(*) seems to be down.
The news server is working OK but the web site is not responding.
(*)
www.gmane.org

Is it a problem at my end? or are others experiencing the same?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

From fomcl at yahoo.com  Thu Jul 10 20:06:57 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Thu, 10 Jul 2014 11:06:57 -0700
Subject: [Tutor] Anti-Patterns in Python Programming
Message-ID: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>




>Just came across this and thought it might be handy for newbies, lurkers and the like http://lignos.org/py_antipatterns/
>

This one is also nice:
https://docs.python.org/3.1/howto/doanddont.html

From breamoreboy at yahoo.co.uk  Thu Jul 10 20:49:14 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Thu, 10 Jul 2014 19:49:14 +0100
Subject: [Tutor] Gmane archive/web site
In-Reply-To: <53BEC683.9000003@btinternet.com>
References: <53BEC683.9000003@btinternet.com>
Message-ID: <lpmn79$6cj$1@ger.gmane.org>

On 10/07/2014 17:59, Alan Gauld wrote:
> I just tried accessing gmane and the web site(*) seems to be down.
> The news server is working OK but the web site is not responding.
> (*)
> www.gmane.org
>
> Is it a problem at my end? or are others experiencing the same?
>

http://www.downforeveryoneorjustme.com/www.gmane.org says it's down.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From jf_byrnes at comcast.net  Thu Jul 10 20:50:14 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Thu, 10 Jul 2014 13:50:14 -0500
Subject: [Tutor] Gmane archive/web site
In-Reply-To: <53BEC683.9000003@btinternet.com>
References: <53BEC683.9000003@btinternet.com>
Message-ID: <lpmn95$5bp$1@ger.gmane.org>

On 07/10/2014 11:59 AM, Alan Gauld wrote:
> I just tried accessing gmane and the web site(*) seems to be down.
> The news server is working OK but the web site is not responding.
> (*)
> www.gmane.org
>
> Is it a problem at my end? or are others experiencing the same?
>

I just tried it and it timed out without connecting.

Regards,  Jim


From breamoreboy at yahoo.co.uk  Thu Jul 10 21:06:42 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Thu, 10 Jul 2014 20:06:42 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
Message-ID: <lpmo81$ja6$1@ger.gmane.org>

On 10/07/2014 19:06, Albert-Jan Roskam wrote:
>
>> Just came across this and thought it might be handy for newbies, lurkers and the like http://lignos.org/py_antipatterns/
>>
>
> This one is also nice:
> https://docs.python.org/3.1/howto/doanddont.html
>

Links of the format https://docs.python.org/3/howto/doanddont.html are 
always up to date, the one you give is by definition 3.1 specific and so 
will never change until such time as it presumably disappears completely.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From codemonkey at inbox.com  Fri Jul 11 00:35:42 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Thu, 10 Jul 2014 14:35:42 -0800
Subject: [Tutor] sometimes I feel like my head is going to explode
Message-ID: <A635CC91996.00000673codemonkey@inbox.com>

The more I learn, the more I realize that there is so much more to learn, and the more difficult some of the stuff to learn seems to be.  I'm not sure that I would have set out on this journey to learn Python if I had known how massive the task was going to be. I AM enjoying it, but my gosh, when am I ever going to feel like I have a handle on this stuff?

That is all.  

Deb in WA, USA

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



From dyoo at hashcollision.org  Fri Jul 11 00:43:16 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 10 Jul 2014 15:43:16 -0700
Subject: [Tutor] sometimes I feel like my head is going to explode
In-Reply-To: <A635CC91996.00000673codemonkey@inbox.com>
References: <A635CC91996.00000673codemonkey@inbox.com>
Message-ID: <CAGZAPF540jnKAE=KEVqS=B=oouhcF4pgEuarzipcY0zOfMv7zQ@mail.gmail.com>

On Thu, Jul 10, 2014 at 3:35 PM, Deb Wyatt <codemonkey at inbox.com> wrote:
> The more I learn, the more I realize that there is so much more to learn, and the more difficult some of the stuff to learn seems to be.  I'm not sure that I would have set out on this journey to learn Python if I had known how massive the task was going to be. I AM enjoying it, but my gosh, when am I ever going to feel like I have a handle on this stuff?


If it helps: I'm still learning, and I've been at it for a while.  So
have many of the others here.

Take it one step at a time.  Try cementing knowledge by really
building things.  Talk to others.

As Piet Hein says:

    Err
    and err
    and err again
    but less
    and less
    and less.

As Peter Norvig says: http://norvig.com/21-days.html

Most of the fundamental knowledge you're picking up should probably
not be too tied to Python.  In the best case, the skills should
transfer to many of the other in-vogue programming languages out there
today.

From sacharook at gmail.com  Fri Jul 11 00:47:48 2014
From: sacharook at gmail.com (Sacha Rook)
Date: Thu, 10 Jul 2014 23:47:48 +0100
Subject: [Tutor] sometimes I feel like my head is going to explode
In-Reply-To: <A635CC91996.00000673codemonkey@inbox.com>
References: <A635CC91996.00000673codemonkey@inbox.com>
Message-ID: <127401cf9c90$fae0bd90$f0a238b0$@gmail.com>

At some point in time you will get to a place where you know enough, never
everything. That's what makes it fun....

-----Original Message-----
From: Tutor [mailto:tutor-bounces+sacharook=gmail.com at python.org] On Behalf
Of Deb Wyatt
Sent: 10 July 2014 23:36
To: tutor at python.org
Subject: [Tutor] sometimes I feel like my head is going to explode

The more I learn, the more I realize that there is so much more to learn,
and the more difficult some of the stuff to learn seems to be.  I'm not sure
that I would have set out on this journey to learn Python if I had known how
massive the task was going to be. I AM enjoying it, but my gosh, when am I
ever going to feel like I have a handle on this stuff?

That is all.  

Deb in WA, USA

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your
desktop!
Check it out at http://www.inbox.com/marineaquarium


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


From dyoo at hashcollision.org  Fri Jul 11 00:50:07 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 10 Jul 2014 15:50:07 -0700
Subject: [Tutor] sometimes I feel like my head is going to explode
In-Reply-To: <CAGZAPF540jnKAE=KEVqS=B=oouhcF4pgEuarzipcY0zOfMv7zQ@mail.gmail.com>
References: <A635CC91996.00000673codemonkey@inbox.com>
 <CAGZAPF540jnKAE=KEVqS=B=oouhcF4pgEuarzipcY0zOfMv7zQ@mail.gmail.com>
Message-ID: <CAGZAPF7D+gMm2kNBvqRTfDeA_9b5Jwy9kS=QQYkWBex5wBe9pw@mail.gmail.com>

By the way, there was a nice talk from Camille Fournier that might be
relevant to you:

    https://www.youtube.com/watch?v=sc8sc-ELMhA

Unfortunately, last time I checked, her presentation cuts off near the
end.  But the bangbangcon folks did a lot of great work on recording
their conference, including writing transcripts for all the talks, so
you can read the rest of her talk here:

https://github.com/hausdorff/bangbangcon.github.io/blob/gh-pages/2014-transcripts/camille-fournier-how-to-stay-in-love-with-programming.txt


There's a line in the talk that made me giggle.  You'll know the line
when you get to it.  It has to do with love.

From breamoreboy at yahoo.co.uk  Fri Jul 11 01:53:12 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 11 Jul 2014 00:53:12 +0100
Subject: [Tutor] sometimes I feel like my head is going to explode
In-Reply-To: <A635CC91996.00000673codemonkey@inbox.com>
References: <A635CC91996.00000673codemonkey@inbox.com>
Message-ID: <lpn913$n4b$1@ger.gmane.org>

On 10/07/2014 23:35, Deb Wyatt wrote:
> The more I learn, the more I realize that there is so much more to learn, and the more difficult some of the stuff to learn seems to be.  I'm not sure that I would have set out on this journey to learn Python if I had known how massive the task was going to be. I AM enjoying it, but my gosh, when am I ever going to feel like I have a handle on this stuff?
>
> That is all.
>
> Deb in WA, USA
>

THINK BIG start small.  Little steps.  Divide and conquer.  I'd guess 
that you've heard at least one of those if not all of them.

Personally I don't believe that you can call yourself a professional 
programmer until you've inadvertantly written an infinite number of 
infinite loops :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From cs at zip.com.au  Fri Jul 11 03:18:33 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Fri, 11 Jul 2014 11:18:33 +1000
Subject: [Tutor] sometimes I feel like my head is going to explode
In-Reply-To: <A635CC91996.00000673codemonkey@inbox.com>
References: <A635CC91996.00000673codemonkey@inbox.com>
Message-ID: <20140711011833.GA36097@cskk.homeip.net>

On 10Jul2014 14:35, Deb Wyatt <codemonkey at inbox.com> wrote:
>The more I learn, the more I realize that there is so much more to learn, and the more difficult some of the stuff to learn seems to be.  I'm not sure that I would have set out on this journey to learn Python if I had known how massive the task was going to be. I AM enjoying it, but my gosh, when am I ever going to feel like I have a handle on this stuff?

After about a year? Your mileage may vary.

Seriously, you'll never know everything.

When you're comfortable writiing arbitrary small things as needed, and 
progressively bigger things (often by getting good at stitching your smaller 
things together). You'll always need to consult doco for specifics and for 
anything new.  Don't worry too much about that.

Cheers,
Cameron Simpson <cs at zip.com.au>

Serious error.
All shortcuts have disappeared.
Screen. Mind. Both are blank.
- Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html

From davea at davea.name  Fri Jul 11 05:01:23 2014
From: davea at davea.name (Dave Angel)
Date: Thu, 10 Jul 2014 23:01:23 -0400 (EDT)
Subject: [Tutor] sometimes I feel like my head is going to explode
References: <A635CC91996.00000673codemonkey@inbox.com>
 <lpn913$n4b$1@ger.gmane.org>
Message-ID: <lpnjts$b52$1@ger.gmane.org>

Mark Lawrence <breamoreboy at yahoo.co.uk> Wrote in message:
> On 
> THINK BIG start small.  Little steps.  Divide and conquer.  I'd guess 
> that you've heard at least one of those if not all of them.
> 
> Personally I don't believe that you can call yourself a professional 
> programmer until you've inadvertantly written an infinite number of 
> infinite loops :)
> 
>

I wrote code whose purpose was to generate other code whose
 purpose was to generate code that in turn was a library. The code
 that I wrote using that library had a purpose of modifying code
 being compiled by a customer of this system.  And this approach
 was the quickest way I could find to solve the original problem. 
 And I was issued a patent on the end result. 

Incidentally the generated code was used without manual editing,
 but was properly indented and commented,  to make debugging
 possible. 


-- 
DaveA


From jdcast at stanford.edu  Fri Jul 11 04:07:15 2014
From: jdcast at stanford.edu (John Cast)
Date: Thu, 10 Jul 2014 19:07:15 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
Message-ID: <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>

Thanks everyone again for the great support.

Right now I have a very basic server running using the http module (I'm
using python 3).  My next step is to generating the HTML pages so that the
formatting of the excel docs stays pretty much the same except that it gets
shown on the web.

For future reference (assuming everything else goes well) how do I procure
a more permanent server (i.e. one that doesn't run on my machine so that I
can turn it off and still be able to visit my pages)?  I'm hearing Apache
and so forth being thrown around (I've read up a little on it) but it seems
those would still run on my local computer.
What am I missing?

I'll keep everyone posted on how the excel parsing turns out.

Thanks again


On Thu, Jul 10, 2014 at 10:24 AM, Chris ?Kwpolska? Warrick <
kwpolska at gmail.com> wrote:

> On Thu, Jul 10, 2014 at 6:40 PM, Alex Kleider <akleider at sonic.net> wrote:
> > If all you want is to check how your 'site' looks perhaps it'd be much
> > simpler to simply point your browser to your parent html file rather than
> > set up a server machine to serve it:
> > file:///home/yourusername/yoursubdirectory/index.html
> > It'll look exactly the same as it would if you were running it on a
> server.
> > (or am I missing something?)
>
> JavaScript may not work.  The same might also happen with links and
> resources using the // scheme (//example.com/ instead of
> http://example.com/)
>
> For local testing, use
>
>     python -m SimpleHTTPServer
>
> or, if you?re on Python 3,
>
>     python3 -m http.server
>
> --
> Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
> PGP: 5EAAEA16
> stop html mail | always bottom-post | only UTF-8 makes sense
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140710/58a51000/attachment-0001.html>

From dyoo at hashcollision.org  Fri Jul 11 06:21:12 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 10 Jul 2014 21:21:12 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
Message-ID: <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>

> For future reference (assuming everything else goes well) how do I
procure a more permanent server (i.e. one that doesn't run on my machine so
that I can turn it off and still be able to visit my pages)?  I'm hearing
Apache and so forth being thrown around (I've read up a little on it) but
it seems those would still run on my local computer.

If you are still associated with your university, you might be able to host
your web site with them.

Otherwise, there are "hosting services" that maintain servers for you:
often you just upload the web site to such a service in exchange for some
subscription fee.  There's a wide spectrum of what a hosting service will
provide you.

The ones I use for my personal and professional use are webfaction.com and
appengine.google.com.  I'm sure others can give more suggestions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140710/4686e808/attachment.html>

From alan.gauld at btinternet.com  Fri Jul 11 07:47:14 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 11 Jul 2014 06:47:14 +0100
Subject: [Tutor] sometimes I feel like my head is going to explode
In-Reply-To: <A635CC91996.00000673codemonkey@inbox.com>
References: <A635CC91996.00000673codemonkey@inbox.com>
Message-ID: <lpntp2$b77$1@ger.gmane.org>

On 10/07/14 23:35, Deb Wyatt wrote:
> The more I learn, the more I realize that there is so much more to learn,

Just get used to the idea that there is no end.
Computer programming is such a young subject - less than
70 years old in practice - that it is still growing rapidly.
By the time you learn all there is to learn, there will be
as much again new stuff!

I've been programming since 1974 and yet there is so much new
and exciting developments happening right now that I think
there is more to learn than when I started.

But that's what makes it fun!

And don't let the fact you don't know it all prevent you
from using the knowledge you do have. Apply what you have,
learn what you can, and make a note of interesting things
for the future.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From kwpolska at gmail.com  Fri Jul 11 09:46:45 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Fri, 11 Jul 2014 09:46:45 +0200
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
Message-ID: <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>

On Fri, Jul 11, 2014 at 4:07 AM, John Cast <jdcast at stanford.edu> wrote:
> For future reference (assuming everything else goes well) how do I procure a
> more permanent server (i.e. one that doesn't run on my machine so that I can
> turn it off and still be able to visit my pages)?  I'm hearing Apache and so
> forth being thrown around (I've read up a little on it) but it seems those
> would still run on my local computer.
> What am I missing?

Apache is a HTTP daemon, as in a piece of software that serves content
over HTTP.  It?s one of many HTTP daemons (web servers) on the market,
and perhaps the most popular one (other popular ones are nginx and
IIS)

But if you want to host persistently, you need to get an actual
server, a piece of hardware, that runs a HTTP daemon.  There are
basically three types of servers: shared (many people host their
websites on the same machine), VPS (virtual private server), and
dedicated (a machine only for you).  Shared servers are the cheapest,
and the best idea for small/static websites.  You can even find free
shared hosting services, like GitHub Pages
<https://pages.github.com/>, or ultra-cheap ones (like
<http://NearlyFreeSpeech.net/>).

On Fri, Jul 11, 2014 at 6:21 AM, Danny Yoo <dyoo at hashcollision.org> wrote:
> The ones I use for my personal and professional use are webfaction.com and
> appengine.google.com.  I'm sure others can give more suggestions.

Both are services used for hosting webapps, not static websites.

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From davea at davea.name  Fri Jul 11 11:13:23 2014
From: davea at davea.name (Dave Angel)
Date: Fri, 11 Jul 2014 05:13:23 -0400 (EDT)
Subject: [Tutor] How to Create Webpage with Python
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
Message-ID: <lpo9nb$k68$1@ger.gmane.org>

John Cast <jdcast at stanford.edu> Wrote in message:
>
> 
 will be hosting this (for the foreseeable future at least) on my desktop.
There is another python script already written that generates the
 excel spreadsheets (I did not write this).  That script will be
 ran on a fairly frequent basis so the webpage will constantly
 have its information updated.  

Please don't post here in html. It can cause a number of problems.
  Tell your mail program to use text.

You don't say who your customers are. If you're doing this for
 your job, call your IT department. They probably have a hosting
 arrangement so their customers can find them. Adding on can be
 trivial,  or simple, or very hard. But it's bound to be easier
 and/or cheaper than starting from scratch.

Your email address implies some connection to a college.  If this
 is for them,  then that's your company.  But even if not,  they
 may be willing to host it for you.

Assuming this is private,  or for a company too new to have needed
 a web or email presence, you have to do more for yourself.  So
 what's your scope? If all your customers are connected to the
 same router (like a typical home) then you can do it all with a
 simple local server,  some machine you promise to leave on all
 the time. They may have to fake the website domain,  using your
 local ip address,  but even that can be finessed,  editing the
 host file on each customer's machine. 

If your customers are spread across multiple routers,  or across
 the city or world,  you need to glue together some access from
 the world,  past your ISP and router,  and into your machine. 
 How best to do that depends on your ISP,  its services and
 policies.  Easiest is to upgrade your service to give you a fixed
 ip address.

If your ISP can't or won't cooperate, or if your machine's uptime
 is unsatisfactory,  there are web hosting services that ARE able
 to host your pages,  connect those pages to a domain you
 purchase, and maintain the machine for you. For low traffic
 sites, you should be able to do it for under S10 a month,  or
 even free. I'm currently hosting 5 domains at 1and1.com, 
 including the davea.name one that gives my email address.  $10
 per month and it's overkill. 


-- 
DaveA


From breamoreboy at yahoo.co.uk  Fri Jul 11 15:26:26 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 11 Jul 2014 14:26:26 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lpmo81$ja6$1@ger.gmane.org>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org>
Message-ID: <lpoolm$bg0$1@ger.gmane.org>

On 10/07/2014 20:06, Mark Lawrence wrote:
> On 10/07/2014 19:06, Albert-Jan Roskam wrote:
>>
>>> Just came across this and thought it might be handy for newbies,
>>> lurkers and the like http://lignos.org/py_antipatterns/
>>>
>>
>> This one is also nice:
>> https://docs.python.org/3.1/howto/doanddont.html
>>
>
> Links of the format https://docs.python.org/3/howto/doanddont.html are
> always up to date, the one you give is by definition 3.1 specific and so
> will never change until such time as it presumably disappears completely.
>

What timing http://bugs.python.org/issue21956 :(

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From fomcl at yahoo.com  Fri Jul 11 16:39:29 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Fri, 11 Jul 2014 07:39:29 -0700
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lpoolm$bg0$1@ger.gmane.org>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
Message-ID: <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>



----- Original Message -----

> From: Mark Lawrence <breamoreboy at yahoo.co.uk>
> To: tutor at python.org
> Cc: 
> Sent: Friday, July 11, 2014 3:26 PM
> Subject: Re: [Tutor] Anti-Patterns in Python Programming
> 
> On 10/07/2014 20:06, Mark Lawrence wrote:
>>  On 10/07/2014 19:06, Albert-Jan Roskam wrote:
>>> 
>>>>  Just came across this and thought it might be handy for newbies,
>>>>  lurkers and the like http://lignos.org/py_antipatterns/
>>>> 
>>> 
>>>  This one is also nice:
>>>  https://docs.python.org/3.1/howto/doanddont.html
>>> 
>> 
>>  Links of the format https://docs.python.org/3/howto/doanddont.html are
>>  always up to date, the one you give is by definition 3.1 specific and so
>>  will never change until such time as it presumably disappears completely.
>> 
> 
> What timing http://bugs.python.org/issue21956 :(

:-) But what is 'bad advice' in this document? Does it imply that all document versions should be deleted/pulverized? (including, for instance, this one: https://docs.python.org/2.7/howto/doanddont.html)

From steve at pearwood.info  Fri Jul 11 17:07:15 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 12 Jul 2014 01:07:15 +1000
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lpoolm$bg0$1@ger.gmane.org>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
Message-ID: <20140711150714.GB5705@ando>

On Fri, Jul 11, 2014 at 02:26:26PM +0100, Mark Lawrence wrote:

> >>This one is also nice:
> >>https://docs.python.org/3.1/howto/doanddont.html

> What timing http://bugs.python.org/issue21956 :(

I reject that bug report. The "Do And Don't" article is not perfect, but 
it is broadly correct. Any suggestion that it is "flat-out wrong", as 
suggested by that bug report, is nonsense.




-- 
Steven

From steve at pearwood.info  Fri Jul 11 17:13:34 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 12 Jul 2014 01:13:34 +1000
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
Message-ID: <20140711151334.GC5705@ando>

On Fri, Jul 11, 2014 at 07:39:29AM -0700, Albert-Jan Roskam wrote:

> > What timing http://bugs.python.org/issue21956 :(
> 
> :-) But what is 'bad advice' in this document? Does it imply that all 
> document versions should be deleted/pulverized? (including, for 
> instance, this one: https://docs.python.org/2.7/howto/doanddont.html)


See my comment on the bug tracker. The advice is good. Some of the 
advice may be a little unclear, especially to the [sneer] Twitter 
generation which is incapable of understand anything that takes more 
than 140 characters to say, but it's still good.


-- 
Steven

From breamoreboy at yahoo.co.uk  Fri Jul 11 17:51:09 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 11 Jul 2014 16:51:09 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
Message-ID: <lpp151$1fh$1@ger.gmane.org>

On 11/07/2014 15:39, Albert-Jan Roskam wrote:
>
>
> ----- Original Message -----
>
>> From: Mark Lawrence <breamoreboy at yahoo.co.uk>
>> To: tutor at python.org
>> Cc:
>> Sent: Friday, July 11, 2014 3:26 PM
>> Subject: Re: [Tutor] Anti-Patterns in Python Programming
>>
>> On 10/07/2014 20:06, Mark Lawrence wrote:
>>>   On 10/07/2014 19:06, Albert-Jan Roskam wrote:
>>>>
>>>>>   Just came across this and thought it might be handy for newbies,
>>>>>   lurkers and the like http://lignos.org/py_antipatterns/
>>>>>
>>>>
>>>>   This one is also nice:
>>>>   https://docs.python.org/3.1/howto/doanddont.html
>>>>
>>>
>>>   Links of the format https://docs.python.org/3/howto/doanddont.html are
>>>   always up to date, the one you give is by definition 3.1 specific and so
>>>   will never change until such time as it presumably disappears completely.
>>>
>>
>> What timing http://bugs.python.org/issue21956 :(
>
> :-) But what is 'bad advice' in this document? Does it imply that all document versions should be deleted/pulverized? (including, for instance, this one: https://docs.python.org/2.7/howto/doanddont.html)
>

See http://bugs.python.org/issue7391 which was closed and then 
re-opened, and remains open.  Judging from comments there and on the 
email that is linked I believe that the pages will all be updated and 
not permanently deleted.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From akleider at sonic.net  Fri Jul 11 18:57:29 2014
From: akleider at sonic.net (Alex Kleider)
Date: Fri, 11 Jul 2014 09:57:29 -0700
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <20140711151334.GC5705@ando>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
 <20140711151334.GC5705@ando>
Message-ID: <3944d6a3ea7c76d85861c1d9b6b05b77@sonic.net>

On 2014-07-11 08:13, Steven D'Aprano wrote:
> On Fri, Jul 11, 2014 at 07:39:29AM -0700, Albert-Jan Roskam wrote:
> 
>> > What timing http://bugs.python.org/issue21956 :(
>> 
>> :-) But what is 'bad advice' in this document? Does it imply that all
>> document versions should be deleted/pulverized? (including, for
>> instance, this one: https://docs.python.org/2.7/howto/doanddont.html)
> 
> 
> See my comment on the bug tracker. The advice is good. Some of the
> advice may be a little unclear, especially to the [sneer] Twitter
> generation which is incapable of understand anything that takes more
> than 140 characters to say, but it's still good.


If the part between a "with" key word and the ":" that follows it is not 
an expression (and therefore can not be protected from 'end of line' by 
enclosure in parentheses,) what is it?


From danieshari at gmail.com  Fri Jul 11 07:50:12 2014
From: danieshari at gmail.com (Danielle Salaz)
Date: Thu, 10 Jul 2014 22:50:12 -0700
Subject: [Tutor]  how do I set variables in Python 3.4
Message-ID: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>

I'm a noob to Python and cannot figure out how to complete one of my assignments. 

I am supposed to use operand1=2 and operand2=7 
To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either on the " or operand1. Please help

Sent from my iPhone

From breamoreboy at yahoo.co.uk  Fri Jul 11 19:16:18 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 11 Jul 2014 18:16:18 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <20140711150714.GB5705@ando>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <20140711150714.GB5705@ando>
Message-ID: <lpp657$c6v$1@ger.gmane.org>

On 11/07/2014 16:07, Steven D'Aprano wrote:
> On Fri, Jul 11, 2014 at 02:26:26PM +0100, Mark Lawrence wrote:
>
>>>> This one is also nice:
>>>> https://docs.python.org/3.1/howto/doanddont.html
>
>> What timing http://bugs.python.org/issue21956 :(
>
> I reject that bug report. The "Do And Don't" article is not perfect, but
> it is broadly correct. Any suggestion that it is "flat-out wrong", as
> suggested by that bug report, is nonsense.
>

Lies, damn lies, and Twitter. :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From mondal.avishekri at yahoo.com.sg  Fri Jul 11 13:27:18 2014
From: mondal.avishekri at yahoo.com.sg (Avishek Mondal)
Date: Fri, 11 Jul 2014 19:27:18 +0800
Subject: [Tutor] TypeError: 'int' object is not iterable
Message-ID: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>

Hi,

I wrote a simple program, as follows-
def finddivisor(n1, n2):
? ? divisor = ()
? ??
? ? for i in range(1, min(n1+n2)+1):
? ? ? ? if n1%i == 0 and n2%i==0:
? ? ? ? ? ? divisor = divisor + (i, )
? ? return divisor

n1 = eval(input('Enter first number: '))
n2 = eval(input('Enter second number: '))


divisors= finddivisor(n1,n2)
print (divisors)

However, when I run it, the message

Traceback (most recent call last):
? File "C:/Python33/Trials/tuple trial.py", line 21, in <module>
? ? divisors= finddivisor(n1,n2)
? File "C:/Python33/Trials/tuple trial.py", line 12, in finddivisor
? ? for i in range(1, min(n1+n2)+1):
TypeError: 'int' object is not iterable

shows up.?Could you please tell me where I went wrong? Does it mean that if i in an integer, it will not be iterated? But isn't the code for i in range(1, n) a very frequently used line?

Thank you for your help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140711/dbc89a29/attachment.html>

From breamoreboy at yahoo.co.uk  Fri Jul 11 21:32:01 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 11 Jul 2014 20:32:01 +0100
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
Message-ID: <lppe39$rok$1@ger.gmane.org>

On 11/07/2014 06:50, Danielle Salaz wrote:
> I'm a noob to Python and cannot figure out how to complete one of my assignments.
>
> I am supposed to use operand1=2 and operand2=7
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either on the " or operand1. Please help
>

Please show us your code and the complete traceback.  Please use cut and 
paste, don't try typing it in by hand as this inevitably leads to mistakes.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From dyoo at hashcollision.org  Fri Jul 11 21:42:49 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 11 Jul 2014 12:42:49 -0700
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
Message-ID: <CAGZAPF6ZpeLXPk_Pn8CXYafH7YckLfwzy0OcexRdszCN5xQNkw@mail.gmail.com>

> I am supposed to use operand1=2 and operand2=7
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either on the " or operand1. Please help


Unfortunately, you've paraphrased the error message enough that we can
not reproduce the problem.  Since you're emailing on your phone, you
may want to reply when you're in front of your compute and are in a
position to do some copy-and-pasting.

Please copy and paste exactly what your entire program looks like.
Please copy and paste the exact contents of the error message and the
surrounding lines.  Also, please say what you expected your program to
do.



For example, let's pretend that I'm seeing a problem in my own
program.  Here's how I'd ask for help:

---------------------------------------------------------------------------------------
I'm seeing the following error in my program:

>>> percent(1, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in percent
ZeroDivisionError: integer division or modulo by zero

Here is my program:

#######################
def percent(part, whole):
   return part / whole
#######################

I expected to see infinity here, but I'm seeing this error instead.
Can you help explain what I can do to get this value?
---------------------------------------------------------------------------------------

That is, show the error message, show the program content, and most
importantly, try to say what you expected to see.

It may be obvious to you what should happen, but sometimes it isn't
obvious!  Here, in this example, I'm pretending to be a crazy person
who believes in infinity.  :P  And that information is useful, because
there actually is a way of getting such a value:
http://stackoverflow.com/questions/7781260/how-can-i-represent-an-infinite-number-in-python.
If I left that part out, the answers I get from other people might be
entirely different or miss this possibility altogether.



Good luck to you.

From wrw at mac.com  Fri Jul 11 21:38:02 2014
From: wrw at mac.com (William Ray Wing)
Date: Fri, 11 Jul 2014 15:38:02 -0400
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
Message-ID: <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>

On Jul 11, 2014, at 1:50 AM, Danielle Salaz <danieshari at gmail.com> wrote:

> I'm a noob to Python and cannot figure out how to complete one of my assignments. 
> 

Welcome to Python - I?d hope you?ve been monitoring this Tutor list for at least a few days -

> I am supposed to use operand1=2 and operand2=7 
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either on the " or operand1. Please help
> 

If you have been, you would see that we need to know which version of Python, what operating system, and then see a complete copy and paste of the traceback and the code you were executing.

In this case, that would be particularly relevant, because it would appear that you have typo?d your iPhone e-mail since there is no " character anyplace in any of the three assignment statements you have given us. Worse, on an iPhone keypad, the ? character isn?t close to anything else you might logically have used.

-Bill



> Sent from my iPhone
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


From audreyr at gmail.com  Fri Jul 11 22:04:59 2014
From: audreyr at gmail.com (Audrey M Roy)
Date: Fri, 11 Jul 2014 13:04:59 -0700
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <20140711151334.GC5705@ando>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
 <20140711151334.GC5705@ando>
Message-ID: <CAM0KdEWmarJdtCm1Rxso9GdR=afbaoc3c+gPWDwKXEg3XsHTVQ@mail.gmail.com>

Steven, any chance you could clarify how to interpret that section? I'm
assuming it refers to not importing objects that share state across modules?

Not being passive-aggressive here, just genuinely seek clarification and
want to learn to be a smarter Python user. I'm on this list to learn stuff
and actually got that link from Mark's original post. :)

Audrey


On Fri, Jul 11, 2014 at 8:13 AM, Steven D'Aprano <steve at pearwood.info>
wrote:

> On Fri, Jul 11, 2014 at 07:39:29AM -0700, Albert-Jan Roskam wrote:
>
> > > What timing http://bugs.python.org/issue21956 :(
> >
> > :-) But what is 'bad advice' in this document? Does it imply that all
> > document versions should be deleted/pulverized? (including, for
> > instance, this one: https://docs.python.org/2.7/howto/doanddont.html)
>
>
> See my comment on the bug tracker. The advice is good. Some of the
> advice may be a little unclear, especially to the [sneer] Twitter
> generation which is incapable of understand anything that takes more
> than 140 characters to say, but it's still good.
>
>
> --
> Steven
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140711/81f47042/attachment-0001.html>

From breamoreboy at yahoo.co.uk  Fri Jul 11 22:21:26 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Fri, 11 Jul 2014 21:21:26 +0100
Subject: [Tutor] TypeError: 'int' object is not iterable
In-Reply-To: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
References: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
Message-ID: <lppgvu$tse$1@ger.gmane.org>

On 11/07/2014 12:27, Avishek Mondal wrote:
> Hi,
>
> I wrote a simple program, as follows-
> def finddivisor(n1, n2):
>      divisor = ()

What's wrong with divisor = [] # a list

>      for i in range(1, min(n1+n2)+1):
>          if n1%i == 0 and n2%i==0:
>      divisor = divisor + (i, )

Then divisor.append(i)

>      return divisor
>
> n1 = eval(input('Enter first number: '))
> n2 = eval(input('Enter second number: '))

Please don't use the code above.

n1 = int(input('Enter first number: '))

>
>
> divisors= finddivisor(n1,n2)
> print (divisors)
>
> However, when I run it, the message
>
> Traceback (most recent call last):
>    File "C:/Python33/Trials/tuple trial.py", line 21, in <module>
>      divisors= finddivisor(n1,n2)
>    File "C:/Python33/Trials/tuple trial.py", line 12, in finddivisor
>      for i in range(1, min(n1+n2)+1):
> TypeError: 'int' object is not iterable
>
> shows up. Could you please tell me where I went wrong? Does it mean that
> if i in an integer, it will not be iterated? But isn't the code for i in
> range(1, n) a very frequently used line?

It is indeed, but not when you've mistyped it :)  Take a close look at 
your call to min()

>
> Thank you for your help!
>

Not at all.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From dyoo at hashcollision.org  Fri Jul 11 22:36:51 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 11 Jul 2014 13:36:51 -0700
Subject: [Tutor] TypeError: 'int' object is not iterable
In-Reply-To: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
References: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
Message-ID: <CAGZAPF4+=tsLsqQcYLk-usN2FePEKvbcba4uOAiVgcR12iis2Q@mail.gmail.com>

Hi Avishek:

Look at the subexpression within the line that Python says it thinks
the error is close to:

    min(n1 + n2)

That looks strange.  Take a look at that subexpression again.

From __peter__ at web.de  Fri Jul 11 22:48:17 2014
From: __peter__ at web.de (Peter Otten)
Date: Fri, 11 Jul 2014 22:48:17 +0200
Subject: [Tutor] TypeError: 'int' object is not iterable
References: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
Message-ID: <lppiih$f58$1@ger.gmane.org>

Avishek Mondal wrote:

> Hi,
> 
> I wrote a simple program, as follows-
> def finddivisor(n1, n2):
> divisor = ()
> 
> for i in range(1, min(n1+n2)+1):
> if n1%i == 0 and n2%i==0:
> divisor = divisor + (i, )
> return divisor
> 
> n1 = eval(input('Enter first number: '))
> n2 = eval(input('Enter second number: '))
> 
> 
> divisors= finddivisor(n1,n2)
> print (divisors)
> 
> However, when I run it, the message
> 
> Traceback (most recent call last):
> File "C:/Python33/Trials/tuple trial.py", line 21, in <module>
> divisors= finddivisor(n1,n2)
> File "C:/Python33/Trials/tuple trial.py", line 12, in finddivisor
> for i in range(1, min(n1+n2)+1):
> TypeError: 'int' object is not iterable
> 
> shows up. Could you please tell me where I went wrong? Does it mean that
> if i in an integer, it will not be iterated? But isn't the code for i in
> range(1, n) a very frequently used line?
> 
> Thank you for your help!

Hint: the problem is not with range(), it's min() with a single argument:

>>> min(2,1)
1
>>> min(2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable



From alan.gauld at btinternet.com  Fri Jul 11 22:50:24 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 11 Jul 2014 21:50:24 +0100
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
Message-ID: <lppimh$ig2$1@ger.gmane.org>

On 11/07/14 06:50, Danielle Salaz wrote:
> I'm a noob to Python and cannot figure out how to complete one of my assignments.
>
> I am supposed to use operand1=2 and operand2=7
> To complete: result= operand1+operand2 etc, but

We need more detail.

How are you entering your code? Is it using a tool like
IDLE or an operating system console version of python?

Are you typing at the interactive python prompt,
usually looking like
 >>>

 > I keep getting invalid syntax either on the " or operand1.

Please post the exact code you entered and the
full error message, do not summarize.

There is no " in the little bit code you posted.
And operand1 appears twice.
We need to see exactly what you are doing - what you
typed, and what Python told you was wrong.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Fri Jul 11 23:01:55 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 11 Jul 2014 22:01:55 +0100
Subject: [Tutor] TypeError: 'int' object is not iterable
In-Reply-To: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
References: <1405078038.56372.YahooMailNeo@web190803.mail.sg3.yahoo.com>
Message-ID: <lppjc3$qo1$1@ger.gmane.org>

On 11/07/14 12:27, Avishek Mondal wrote:

>      for i in range(1, min(n1+n2)+1):
> TypeError: 'int' object is not iterable
>
> shows up. Could you please tell me where I went wrong? Does it mean that
> if i in an integer, it will not be iterated? But isn't the code for i in
> range(1, n) a very frequently used line?

Break it down. Try evaluyating

 >>> min( 6+7)

You get the same ertror because Python sees that as:

 >>> min(13)

And min expects a series of numbers not a single int.

Maybe you meant to use

     for i in range(1, min(n1, n2)+1):

??

Finally, don't do this:

n1 = eval(input('Enter first number: '))

Its very bad practice and a security nightmare.
A user could type any Python expression and it would be evaluated.
This could potentially result in your hard drive being formatted
or similar evils ...

To try it out (safely!) do this:

 >>> value = eval(input("Type a number "))

Then at the prompt type

exit()

And hit enter and see what happens.

Use a conversion function to convert to whatever
type you want. In your case probably int()


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From codemonkey at inbox.com  Sat Jul 12 00:20:07 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Fri, 11 Jul 2014 14:20:07 -0800
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lpoolm$bg0$1@ger.gmane.org>
References: <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org>
Message-ID: <B2A599481FB.00000309codemonkey@inbox.com>


>>>> lurkers and the like http://lignos.org/py_antipatterns/
>>>> 
>> Links of the format https://docs.python.org/3/howto/doanddont.html are
>> always up to date, the one you give is by definition 3.1 specific and so
>> will never change until such time as it presumably disappears
>> completely.
>> 
> 
> What timing http://bugs.python.org/issue21956 :(
> 
> --
I see you all are trying to explode my head some more.  The first article noted is what exploded it yesterday lol.
Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



From jf_byrnes at comcast.net  Sat Jul 12 03:29:57 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Fri, 11 Jul 2014 20:29:57 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lpm7k9$ojq$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
 <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
 <lpm7k9$ojq$1@ger.gmane.org>
Message-ID: <lpq32l$3r4$1@ger.gmane.org>

On 07/10/2014 09:23 AM, Jim Byrnes wrote:
> On 07/09/2014 04:16 PM, Walter Prins wrote:
>> Hi Jim,
>>
>> On 9 July 2014 14:43, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>>
>>> On 07/09/2014 04:27 AM, Walter Prins wrote:
>>>
>>>> I forgot to mention I am using Linux (Ubuntu 12.04).
>>>>
>>>
>>> I am working my way through a book about breezypythongui which uses
>>> Python
>>> 3, hence virtualenv.  I found that each time I started to work with it I
>>> did the above 3 steps, I was just looking to automatic that
>>> repetitive task.
>>>
>>
>> In that case you should put these commands in your .bashrc file so it
>> gets
>> set up as your user's default.  (The .bashrc file is somewhat like DOS's
>> "autoexec.bat" file, if you're familiar with this, except each user has
>> their own .bashrc.)  You can also create a shell script that does this
>> for
>> you.  (You can install "virtualenv wrapper" which gives you some further
>> commands to make working with virtualenvs easier.)
>>
>> Regards
>>
>> Walter
>>
>
> I realize I could have used a shell script but since I was working with
> Python I thought I might learn some more Python by trying to use it.  As
> it turns out, I did learn quite a bit through this discussion.
>
> Thanks for the pointer to virtualenv wrapper.
>
> Regards,  Jim
>

I've worked on this a little more. If I create a file like:

#!/usr/bin/python
import os, subprocess
subprocess.Popen(args=["gnome-terminal",
     "--working-directory=/home/jfb/Documents/Prog/Python/breezygui"])

and execute it, it will take me to the correct directory.  Once there if 
I type in 'source bin/activate' I will get a virtualenv. However I can't 
figure out how to do it from my script.

I have tried adding "--command=source bin/active" to args=
but then I get this error:

There was an error creating the child process for this terminal
Failed to execute child process "source" (No such file or directory)

To check if I could even use "--command=", I added "--command=python" 
and I got a  python session.

Could some one tell me what I need to do to issue the command to setup 
virtualenv?

Thanks,  Jim



From steve at pearwood.info  Sat Jul 12 04:06:06 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 12 Jul 2014 12:06:06 +1000
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <b50f7aa80b15b3058d128c2284b7acac@sonic.net>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
 <20140711151334.GC5705@ando> <b50f7aa80b15b3058d128c2284b7acac@sonic.net>
Message-ID: <20140712020606.GD5705@ando>

On Fri, Jul 11, 2014 at 09:56:36AM -0700, Alex Kleider wrote:

> If the part between a "with" key word and the ":" that follows it is not 
> an expression (and therefore can not be protected from 'end of line' by 
> enclosure in parentheses,) what is it?

A bug in the parser.

And one which is now fixed. This is using Python 3.3:

py> with (open(
...             '/tmp/foo', 'w')) as f:
...     f.write("Hello")
...
5
py> 


Works fine, no \ line continuation needed.

The point about rules like "don't use \ line continuation" is not that 
that you should never ever ever under any circumstances break them. I've 
done every single one of the "Don't" rules, deliberately, not out of 
ignorance, except the "from module import *" inside a function. (I have 
done it at module level.) The point of such rules are to guide you 
towards better practice, away from poor practice, and to make you think 
good and hard before breaking the rules.



-- 
Steven

From steve at pearwood.info  Sat Jul 12 04:43:11 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 12 Jul 2014 12:43:11 +1000
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <CAM0KdEWmarJdtCm1Rxso9GdR=afbaoc3c+gPWDwKXEg3XsHTVQ@mail.gmail.com>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
 <20140711151334.GC5705@ando>
 <CAM0KdEWmarJdtCm1Rxso9GdR=afbaoc3c+gPWDwKXEg3XsHTVQ@mail.gmail.com>
Message-ID: <20140712024311.GE5705@ando>

On Fri, Jul 11, 2014 at 01:04:59PM -0700, Audrey M Roy wrote:
> Steven, any chance you could clarify how to interpret that section? I'm
> assuming it refers to not importing objects that share state across modules?

Importing objects that share state across modules was not the problem 
I was talking about. Let's have two imaginary modules, spam and eggs:

# spam.py
x = 23


# eggs.py
from spam import x


This is perfectly clean: the eggs module reaches into the spam module, 
grabs the current value of x (23), and sticks that value into itself. 
What it's doing may be more clear if we re-write eggs.py in a slightly 
longer way:

import spam
x = spam.x
del spam

So now it is clear that any link between eggs.x and spam.x is lost, gone 
for good. They are now completely independent variables which happen to 
share the same value.

This is perfectly fine if x is being used as a constant. Since neither 
spam nor eggs are changing x, there's no problem.

It's also perfectly fine if spam.x and eggs.x are *supposed* to be 
independent. If you're intending for eggs to just get it's *initial* 
value from spam, and then treat it as a separate value from then on, 
then there's no problem.

But note that if x is *mutable*, like a list, then eggs.x is NOT a 
copy. It is just a different reference to the same object, which means 
that changes to eggs.x will effect spam.x and visa versa, since they are 
the same mutable object. So that's another possible issue to be 
concerned about.

The problem I meant occurs when you don't intend for the link to be 
lost. The spam module sometimes re-assigns x, giving it a different 
value. In other words, spam.x is used as a variable, not a constant. 
(This is itself a bit of a worry, global state is often harmful and best 
avoided, but sometimes there are reasons for it.) The spam module can 
re-assign x later on:

# inside spam, some function calls this:
global x
x = 42


rebinding spam.x, but eggs.x is oblivious.


The common pattern, where you import a function or a class or a 
constant, and it never gets mutated or rebound, is perfectly fine. But 
there are odd gotchas to "from ... import" that may be surprising. 
That's why I think one needs to be cautious about doing "from ... 
import". You need to think about it: are you sharing an object, where 
modifications to the object will be seen across multiple modules? Is it 
intended as a variable or a constant? If you don't think about it, one 
day you'll be bitten.


-- 
Steven

From cs at zip.com.au  Sat Jul 12 05:50:20 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Sat, 12 Jul 2014 13:50:20 +1000
Subject: [Tutor] How can I open and use gnome-terminal from a Python
 script?
In-Reply-To: <lpq32l$3r4$1@ger.gmane.org>
References: <lpq32l$3r4$1@ger.gmane.org>
Message-ID: <20140712035020.GA8333@cskk.homeip.net>

On 11Jul2014 20:29, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>I've worked on this a little more. If I create a file like:
>
>#!/usr/bin/python
>import os, subprocess
>subprocess.Popen(args=["gnome-terminal",
>    "--working-directory=/home/jfb/Documents/Prog/Python/breezygui"])
>
>and execute it, it will take me to the correct directory.  Once there 
>if I type in 'source bin/activate' I will get a virtualenv. However I 
>can't figure out how to do it from my script.
>
>I have tried adding "--command=source bin/active" to args=
>but then I get this error:
>
>There was an error creating the child process for this terminal
>Failed to execute child process "source" (No such file or directory)
>
>To check if I could even use "--command=", I added "--command=python" 
>and I got a  python session.
>
>Could some one tell me what I need to do to issue the command to setup 
>virtualenv?

Your problem is that "source" is a shell builtin because it must affect the 
shell internals, and although gnome-terminal's --command option takes a string 
it does not seem to be a shell string, passed to "sh". Instead, it seems 
gnome-terminal takes it upon itself to take a string and break it up into words 
and expected the first word to be an executable program i.e. "source" in your 
case.

Suggestions below, but first a tiny rant on the side: gnome-terminal's command 
specification option is rubbish, a long standing gripe of mine with 
gnome-terminal. Most decent terminal emulators take a -e option and follow 
command strings (just like you're passing to subprocess.Popen). Some are less 
helpful (eg OSX Terminal) and accept only a shell command; in Terminal's case 
it seems to be literally typed at the terminal :-( gnome-terminal seems to do 
neither.

Returning to your task:

Virtualenv is a directory to hold python modules etc and some "activate" 
scripts to set up the environment so that this is used by commands.

People are generally pointed at the "bin/activate" shell file to source to set 
things up, but that doesn't need to happen _inside_ the terminal. You can do it 
outside and then run the terminal.

An example shell command might look like this:

   cd /home/jfb/Documents/Prog/Python/breezygui
   . ./bin/activate
   gnome-terminal

or

   cd /home/jfb/Documents/Prog/Python/breezygui; . ./bin/activate; exec gnome-terminal

which avoids the difficulties with gnome-terminal's command line options.

So you could adapt your Popen invocation to look like this:

   subprocess.Popen(args=["sh", "-c", "cd /home/jfb/Documents/Prog/Python/breezygui; . ./bin/activate; gnome-terminal"])

That is only one line, in case some mail program breaks it up.

If you were using another terminal emulator it might be worth putting more work 
into getting stuff done after starting the emulator rather than before, but IMO 
gnome-terminal makes it too painful to bother.

Cheers,
Cameron Simpson <cs at zip.com.au>

Windows crashes:
===============
Cath   "Do the blue screens count?"
Jimbo  "According to the microsoft conference, they are not crashes, they are
         corrections"
John   "This was surely a joke as, at the time, the stock market crash during
         the week in question was being referred to as a 'correction' and not
         a crash"
Scott  "Yes, Windows is a joke"

From codemonkey at inbox.com  Sat Jul 12 06:50:54 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Fri, 11 Jul 2014 20:50:54 -0800
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <000301cf9d6c$b499f090$1dcdd1b0$@gmail.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org>
Message-ID: <B60F16351E0.00000511codemonkey@inbox.com>



terns in Python Programming
> 
> Hi Deb and others,
> Most are for people coming from different languages like C/C++, Java and
> so
> on (I myself am coming from C++ world, and can speak both C++ and
> Python).
> Unless if you're working on specific things, don't worry about some of
> the
> concepts until later (e.g. if you're working on variables, you might want
> to
> note down recommendation on lists, like loops and testing if a list is
> empty).
> As for learning new things, start with small steps first. In my opinion,
> it
> is better to have objectives on what you wish to learn, and if you want
> to
> speak Python fluently, learn the concepts until you can speak it in your
> sleep (you know what I mean). Also I recommend writing some things you
> truly
> wish to learn in Python so the tutors can recommend things you might want
> to
> go over before you learn your dream concept.
> Just in case I'm repeating a question that was asked here (as I'm new
> here),
> is python your first ever programming language?
> BTW, as a side note, for those who'd like to practice their skills, I
> highly
> recommend Code Eval (www.codeeval.com).
> Cheers,
> Joseph

Thank you for answering.  I used to be a Clipper/dBase programmer years 
ago. I got sick, couldn't work, and technology passed me by.  I've 
always been kind of ticked off that my career was short circuited 
because of illness, so I decided to see if I could get a handle on OOP. 
The more I learn about Python, the more I loved it. 

So much has been invented since my dos programming days and it is 
overwhelming, but I'm having the time of my life learning all this 
stuff. My head explodes quite often :).
  
Deb in WA, USA

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



From smrodriguez88 at gmail.com  Fri Jul 11 23:16:05 2014
From: smrodriguez88 at gmail.com (Steve Rodriguez)
Date: Fri, 11 Jul 2014 15:16:05 -0600
Subject: [Tutor] While loop issue, variable not equal to var or var
Message-ID: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>

Hey guys n gals,

New to python, having some problems with while loops, I would like to make
a program quick once q or Q is typed, but thus far I can only get the first
variable to be recognized. My code looks like:

    message = raw_input("-> ")
    while message != 'q':
        s.send(message)
        data = s.recv(2048)
        print str(data)
        message = raw_input("-> ")
    s.close()
    print("Shutting Down")

I've tried:

while message != 'q' or 'Q':
while message != 'q' or message != 'Q':
while message != ('q' or 'Q'):

Any ideas would be much appreciated! Thanks! :D

Regards,
Steve Rodriguez
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140711/25ea29de/attachment-0001.html>

From joseph.lee22590 at gmail.com  Sat Jul 12 03:00:41 2014
From: joseph.lee22590 at gmail.com (Joseph Lee)
Date: Fri, 11 Jul 2014 18:00:41 -0700
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <B2A599481FB.00000309codemonkey@inbox.com>
References: <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <B2A599481FB.00000309codemonkey@inbox.com>
Message-ID: <000301cf9d6c$b499f090$1dcdd1b0$@gmail.com>

Hi Deb and others,
Most are for people coming from different languages like C/C++, Java and so
on (I myself am coming from C++ world, and can speak both C++ and Python).
Unless if you're working on specific things, don't worry about some of the
concepts until later (e.g. if you're working on variables, you might want to
note down recommendation on lists, like loops and testing if a list is
empty).
As for learning new things, start with small steps first. In my opinion, it
is better to have objectives on what you wish to learn, and if you want to
speak Python fluently, learn the concepts until you can speak it in your
sleep (you know what I mean). Also I recommend writing some things you truly
wish to learn in Python so the tutors can recommend things you might want to
go over before you learn your dream concept.
Just in case I'm repeating a question that was asked here (as I'm new here),
is python your first ever programming language?
BTW, as a side note, for those who'd like to practice their skills, I highly
recommend Code Eval (www.codeeval.com).
Cheers,
Joseph

-----Original Message-----
From: Tutor [mailto:tutor-bounces+joseph.lee22590=gmail.com at python.org] On
Behalf Of Deb Wyatt
Sent: Friday, July 11, 2014 3:20 PM
To: tutor at python.org
Subject: Re: [Tutor] Anti-Patterns in Python Programming


>>>> lurkers and the like http://lignos.org/py_antipatterns/
>>>> 
>> Links of the format https://docs.python.org/3/howto/doanddont.html 
>> are always up to date, the one you give is by definition 3.1 specific 
>> and so will never change until such time as it presumably disappears 
>> completely.
>> 
> 
> What timing http://bugs.python.org/issue21956 :(
> 
> --
I see you all are trying to explode my head some more.  The first article
noted is what exploded it yesterday lol.
Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and
family!
Visit http://www.inbox.com/photosharing to find out more!


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


From joseph.lee22590 at gmail.com  Sat Jul 12 07:13:52 2014
From: joseph.lee22590 at gmail.com (Joseph Lee)
Date: Fri, 11 Jul 2014 22:13:52 -0700
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <B60F16351E0.00000511codemonkey@inbox.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <B60F16351E0.00000511codemonkey@inbox.com>
Message-ID: <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>

Hi Deb and others,
Answers are below.

-----Original Message-----
From: Deb Wyatt [mailto:codemonkey at inbox.com] 
Sent: Friday, July 11, 2014 9:51 PM
To: Joseph Lee; tutor at python.org
Subject: RE: [Tutor] Anti-Patterns in Python Programming




Thank you for answering.  I used to be a Clipper/dBase programmer years ago.
I got sick, couldn't work, and technology passed me by.  I've always been
kind of ticked off that my career was short circuited because of illness, so
I decided to see if I could get a handle on OOP. 
The more I learn about Python, the more I loved it.

JL: Ah, OOP (Object-oriented Programming), a very treasured territory in
some circles. Python does have facilities for OOP, namely classes, objects
(in fact, objects are first-class citizens in Python world), inheritance and
polymorphism (actually, those who've dealt with sequences may have noticed
that Python can iterate through them no matter which type it is, an example
of polymorphism). From reading the list archives, if I understand your
background, it appears that there are certain things that you might want to
get acquainted coming from a language like Basic, such as syntax
differences, indentation (I usually use tabs for four spaces for my code)
and transplanting what you know from 80's and 90's to 2010's. I'm sure there
are books and sites which talks about Python from another language's point
of view (I know there is a book out there called "C++ for Java
programmers").

Message:
So much has been invented since my dos programming days and it is
overwhelming, but I'm having the time of my life learning all this stuff. My
head explodes quite often :).

JL: Yes, there were more inventions since then, including Linux (which I use
as a virtual machine), GUI frameworks such as WXPython and QT and so on (web
programming included). But the concepts that were invented way back still
apply here, including console input and output, memory access (no, not
directly at first), network programming and string manipulation (Python is
good as an instant noodle-type of meal - that is, verifying your idea
quickly via interpreter, as it checks your input for you and displays what
it thinks it's doing). Please let us know if you'd like explanations (if
searching on Google fails, the next best place to ask would be here and
other lists you're in).
BTW, Python is a fun language with lots of fuel to last you a long time (I
mean it).
P.S. I know at least one programmer onboard who comes from COBOL, so he
might have something to say about transitioning to a new language.
Cheers,
Joseph
University of California, Riverside 
Translator and code contributor, NVDA (NonVisual Desktop Access)

  

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your
desktop!
Check it out at http://www.inbox.com/marineaquarium



From __peter__ at web.de  Sat Jul 12 09:10:25 2014
From: __peter__ at web.de (Peter Otten)
Date: Sat, 12 Jul 2014 09:10:25 +0200
Subject: [Tutor] While loop issue, variable not equal to var or var
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
Message-ID: <lpqn1i$bbe$1@ger.gmane.org>

Steve Rodriguez wrote:

> Hey guys n gals,
> 
> New to python, having some problems with while loops, I would like to make
> a program quick once q or Q is typed, but thus far I can only get the
> first variable to be recognized. My code looks like:
> 
>     message = raw_input("-> ")
>     while message != 'q':
>         s.send(message)
>         data = s.recv(2048)
>         print str(data)
>         message = raw_input("-> ")
>     s.close()
>     print("Shutting Down")
> 
> I've tried:
> 
> while message != 'q' or 'Q':

This evaluates 

(message != "q") or "Q"

and "Q" is always True in a boolean context:

>>> bool("Q")
True

> while message != 'q' or message != 'Q':

This is true when at least one of the subexpressions

message != "q"
message != "Q"

is True. When the value of message is "q" it must be unequal to "Q" and vice 
versa, so there is always at least one true subexpression.

> while message != ('q' or 'Q'):

When you try the right side in the interactive interpreter you get

>>> "q" or "Q"
'q'

so this is the same as just 

message != "q" 

> Any ideas would be much appreciated! Thanks! :D

while message.lower() != "q":
while message not in ("q", "Q"):
while message != "q" and message != "Q":

There's another one that chains boolean expressions

while "q" != message != "Q":

that I don't recommend here but that is very readable for checking number 
intervals:

if 0 <= some_number < 1:
   print some_number, "is in the half-open interval [0,1)"


You also may consider an infinite loop:

while True:
    message = raw_input("-> ")
    if message in ("q", "Q"):
        break
    s.send(message)
    ...

This avoids the duplicate raw_input().

PS: You sometimes see

message in "qQ"

but this is buggy as it is true when the message is either
"q", "Q", or "qQ".


From __peter__ at web.de  Sat Jul 12 09:21:24 2014
From: __peter__ at web.de (Peter Otten)
Date: Sat, 12 Jul 2014 09:21:24 +0200
Subject: [Tutor] While loop issue, variable not equal to var or var
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqn1i$bbe$1@ger.gmane.org>
Message-ID: <lpqnmf$hen$1@ger.gmane.org>

Peter Otten wrote:

> PS: You sometimes see
> 
> message in "qQ"
> 
> but this is buggy as it is true when the message is either
> "q", "Q", or "qQ".

Oops, I forgot "".


From alan.gauld at btinternet.com  Sat Jul 12 10:02:42 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 09:02:42 +0100
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lpq32l$3r4$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
 <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
 <lpm7k9$ojq$1@ger.gmane.org> <lpq32l$3r4$1@ger.gmane.org>
Message-ID: <lpqq32$9r8$1@ger.gmane.org>

On 12/07/14 02:29, Jim Byrnes wrote:

> I've worked on this a little more. If I create a file like:
>
> #!/usr/bin/python
> import os, subprocess
> subprocess.Popen(args=["gnome-terminal",
>      "--working-directory=/home/jfb/Documents/Prog/Python/breezygui"])
>
> and execute it, it will take me to the correct directory.  Once there if
> I type in 'source bin/activate' I will get a virtualenv. However I can't
> figure out how to do it from my script.

What I can't figure out is why you are trying to do this using 
gnome-terminal? (You may have explained and I've missed it, in which 
case I apologize) Why do you feel you need to start a terminal?

You normally execute the commands you want directly from within
Python not by driving a terminal emulator. Terminals are just
windows for humans. They run a shell that reads and executes
commands. They format the output to fit the window. So when
you use a terminal you are just adding 2 extra layers of
complexity.

You can change directory and run activate from within Python
without the terminal. You could even start a bash session if
you need to let the user (eg. you) type some commands. But you
shouldn't need to start a terminal and then try to force it
to execute commands. That just seems crazy to me. Or am I
missing something?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Sat Jul 12 10:27:57 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 09:27:57 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <B60F16351E0.00000511codemonkey@inbox.com>
 <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
Message-ID: <lpqrid$os6$1@ger.gmane.org>

On 12/07/14 05:50, Deb Wyatt wrote:

> So much has been invented since my dos programming days and it is
> overwhelming,

Actually very little has been *invented* since your DOS days.
Almost everything we do today was already around back then.

eg.
- The mouse is from the 60s
- Touch-screens are from the 60's
- OOP is from the 60's
- Networking is from the 60's(just!)
- The GUI is from the 70s
- Virtual machines are from the 70's (or maybe even 60s?)
- Unix (of which Linux and MacOS are implementations) is from the 70s
- C++ is from the 80s
- SQL is from the 80's
- Even Python is from 1991, around the same time Windows 3 appeared.

The difference is that the computer power needed to run it has
become cheap enough that ordinary people can use it.

It is a sad fact that very little real progress has been made
in computing over the last 40 years or so. The advent of the
web actually slowed down progress by about 10 years, although
it greatly increased accessibility and popularity. But for
many years the web didn't add anything new to computing/networking
it just made it easier to use. Now with HTML5 etc things are
slowly advancing again.

None of which helps Deb of course!
But I need a rant every now and then :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Sat Jul 12 10:33:20 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 09:33:20 +0100
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
Message-ID: <lpqrsg$rbg$1@ger.gmane.org>

On 11/07/14 22:16, Steve Rodriguez wrote:
> Hey guys n gals,
>
> New to python, having some problems with while loops, I would like to
> make a program quick once q or Q is typed, but thus far I can only get
> the first variable to be recognized.

 > My code looks like:
 >
 >      message = raw_input("-> ")
 >      while message != 'q':

Peter has given a comprehensive reply.

There are two other options he didn't mention.

1) Use 'and' instead of 'or':

while message != 'q' and message != 'Q':

2) Better (IMHO) is to convert message to lower case (or upper if
you prefer) and only do one comparison:

while message.lower() != 'q':


HTH,

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From steve at pearwood.info  Sat Jul 12 11:28:54 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 12 Jul 2014 19:28:54 +1000
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <lpqrsg$rbg$1@ger.gmane.org>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org>
Message-ID: <20140712092854.GH5705@ando>

On Sat, Jul 12, 2014 at 09:33:20AM +0100, Alan Gauld wrote:

> 2) Better (IMHO) is to convert message to lower case (or upper if
> you prefer) and only do one comparison:
> 
> while message.lower() != 'q':

I second this advice, but with a slight modification.

If you're using Python 3.3 or higher, it is better to use 
message.casefold rather than lower. For English, there's no real 
difference:

py> "Hello World!".casefold()
'hello world!'


but it can make a difference for non-English languages:

py> "Gro?e".lower()  # German for "great" or "large"
'gro?e'
py> "Gro?e".casefold()
'grosse'




-- 
Steven

From alan.gauld at btinternet.com  Sat Jul 12 12:27:17 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 11:27:17 +0100
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <20140712092854.GH5705@ando>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
Message-ID: <lpr2i5$vut$1@ger.gmane.org>

On 12/07/14 10:28, Steven D'Aprano wrote:

> If you're using Python 3.3 or higher, it is better to use
> message.casefold rather than lower. For English, there's no real
> difference:
>...
> but it can make a difference for non-English languages:
>
> py> "Gro?e".lower()  # German for "great" or "large"
> 'gro?e'
> py> "Gro?e".casefold()
> 'grosse'

You learn something new etc...

But I'm trying to figure out what difference this makes in
practice?

If you were targeting a German audience wouldn't you just test
against the German alphabet? After all you still have to expect 'grosse' 
which isn't English, so if you know to expect grosse
why not just test against gro?e instead?

I think I'm missing something.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From steve at pearwood.info  Sat Jul 12 14:19:50 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 12 Jul 2014 22:19:50 +1000
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <lpr2i5$vut$1@ger.gmane.org>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
 <lpr2i5$vut$1@ger.gmane.org>
Message-ID: <20140712121950.GI5705@ando>

On Sat, Jul 12, 2014 at 11:27:17AM +0100, Alan Gauld wrote:
> On 12/07/14 10:28, Steven D'Aprano wrote:
> 
> >If you're using Python 3.3 or higher, it is better to use
> >message.casefold rather than lower. For English, there's no real
> >difference:
> >...
> >but it can make a difference for non-English languages:
> >
> >py> "Gro?e".lower()  # German for "great" or "large"
> >'gro?e'
> >py> "Gro?e".casefold()
> >'grosse'
> 
> You learn something new etc...
> 
> But I'm trying to figure out what difference this makes in
> practice?
> 
> If you were targeting a German audience wouldn't you just test
> against the German alphabet? After all you still have to expect 'grosse' 
> which isn't English, so if you know to expect grosse
> why not just test against gro?e instead?

Because the person might have typed any of:

grosse
GROSSE
gROSSE
gro?e
Gro?e
GRO?E
GRO?E

etc., and you want to accept them all, just like in English you'd want 
to accept any of GREAT great gREAT Great gReAt etc. Hence you want to 
fold everything to a single, known, canonical version. Case-fold will do 
that, while lowercasing won't.

(The last example includes a character which might not be visible to 
many people, since it is quite unusual and not supported by many fonts 
yet. If it looks like a box or empty space for you, it is supposed 
to be capital sharp-s, matching the small sharp-s ?.)


Oh, here's another example of the difference, this one from Greek:

py> '???'.lower()  # three versions of sigma
'???'
py> '???'.upper()
'???'
py> '???'.casefold()
'???'


I suspect that there probably aren't a large number of languages where 
casefold and lower do something different, since most languages don't 
have distinguish between upper and lower case at all. But there's no 
harm in using it, since at worst it returns the same as lower().


-- 
Steven

From davea at davea.name  Sat Jul 12 14:20:21 2014
From: davea at davea.name (Dave Angel)
Date: Sat, 12 Jul 2014 07:20:21 -0500 (CDT)
Subject: [Tutor] While loop issue, variable not equal to var or var
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
Message-ID: <lpr96f$3ss$1@ger.gmane.org>

Steven D'Aprano <steve at pearwood.info> Wrote in message:
> On Sat, Jul 12, 2014 at 09:33:20AM +0100, Alan Gauld wrote:
> 
>> 2) Better (IMHO) is to convert message to lower case (or upper if
>> you prefer) and only do one comparison:
>> 
>> while message.lower() != 'q':
> 
> I second this advice, but with a slight modification.
> 
> If you're using Python 3.3 or higher, it is better to use 
> message.casefold rather than lower. For English, there's no real 
> difference:
> 
> py> "Hello World!".casefold()
> 'hello world!'
> 
> 
> but it can make a difference for non-English languages:
> 
> py> "Gro?e".lower()  # German for "great" or "large"
> 'gro?e'
> py> "Gro?e".casefold()
> 'grosse'
> 

I don't remember my high school German enough to remember if the  ?

character is an example,  but in various languages there are
 characters that exist only in uppercase,  and whose lowercase
 equivalent is multiple letters. Or vice versa. And characters
 that have multiple valid spellings in uppercase,  but only one in
 lowercase. 

If the latter is true for German,  perhaps GROSSE and GRO?E are
 valid uppercase,  but only grosse for lowercase.
 

-- 
DaveA


From jf_byrnes at comcast.net  Sat Jul 12 17:22:19 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Sat, 12 Jul 2014 10:22:19 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <20140712035020.GA8333@cskk.homeip.net>
References: <lpq32l$3r4$1@ger.gmane.org>
 <20140712035020.GA8333@cskk.homeip.net>
Message-ID: <lprjrc$lm9$1@ger.gmane.org>

On 07/11/2014 10:50 PM, Cameron Simpson wrote:
> On 11Jul2014 20:29, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>> I've worked on this a little more. If I create a file like:
>>
>> #!/usr/bin/python
>> import os, subprocess
>> subprocess.Popen(args=["gnome-terminal",
>>    "--working-directory=/home/jfb/Documents/Prog/Python/breezygui"])
>>
>> and execute it, it will take me to the correct directory.  Once there
>> if I type in 'source bin/activate' I will get a virtualenv. However I
>> can't figure out how to do it from my script.
>>
>> I have tried adding "--command=source bin/active" to args=
>> but then I get this error:
>>
>> There was an error creating the child process for this terminal
>> Failed to execute child process "source" (No such file or directory)
>>
>> To check if I could even use "--command=", I added "--command=python"
>> and I got a  python session.
>>
>> Could some one tell me what I need to do to issue the command to setup
>> virtualenv?
>
> Your problem is that "source" is a shell builtin because it must affect
> the shell internals, and although gnome-terminal's --command option
> takes a string it does not seem to be a shell string, passed to "sh".
> Instead, it seems gnome-terminal takes it upon itself to take a string
> and break it up into words and expected the first word to be an
> executable program i.e. "source" in your case.
>
> Suggestions below, but first a tiny rant on the side: gnome-terminal's
> command specification option is rubbish, a long standing gripe of mine
> with gnome-terminal. Most decent terminal emulators take a -e option and
> follow command strings (just like you're passing to subprocess.Popen).
> Some are less helpful (eg OSX Terminal) and accept only a shell command;
> in Terminal's case it seems to be literally typed at the terminal :-(
> gnome-terminal seems to do neither.
>
> Returning to your task:
>
> Virtualenv is a directory to hold python modules etc and some "activate"
> scripts to set up the environment so that this is used by commands.
>
> People are generally pointed at the "bin/activate" shell file to source
> to set things up, but that doesn't need to happen _inside_ the terminal.
> You can do it outside and then run the terminal.
>
> An example shell command might look like this:
>
>    cd /home/jfb/Documents/Prog/Python/breezygui
>    . ./bin/activate
>    gnome-terminal
>
> or
>
>    cd /home/jfb/Documents/Prog/Python/breezygui; . ./bin/activate; exec
> gnome-terminal
>
> which avoids the difficulties with gnome-terminal's command line options.
>
> So you could adapt your Popen invocation to look like this:
>
>    subprocess.Popen(args=["sh", "-c", "cd
> /home/jfb/Documents/Prog/Python/breezygui; . ./bin/activate;
> gnome-terminal"])
>
> That is only one line, in case some mail program breaks it up.

Thank you, that worked.  At first I thought it was not working because 
when I did it manually I ended up with a prompt that looked like:

(breezygui)jfb at jims1204:~/Documents/Prog/Python/breezygui$

The script result did not have the (breezygui) at the front.  Luckily I 
decided to test it and when I type python I got python3.

Thanks,  Jim




From jf_byrnes at comcast.net  Sat Jul 12 17:34:49 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Sat, 12 Jul 2014 10:34:49 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lpqq32$9r8$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
 <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
 <lpm7k9$ojq$1@ger.gmane.org> <lpq32l$3r4$1@ger.gmane.org>
 <lpqq32$9r8$1@ger.gmane.org>
Message-ID: <lprkip$u5h$1@ger.gmane.org>

On 07/12/2014 03:02 AM, Alan Gauld wrote:
> On 12/07/14 02:29, Jim Byrnes wrote:
>
>> I've worked on this a little more. If I create a file like:
>>
>> #!/usr/bin/python
>> import os, subprocess
>> subprocess.Popen(args=["gnome-terminal",
>>      "--working-directory=/home/jfb/Documents/Prog/Python/breezygui"])
>>
>> and execute it, it will take me to the correct directory.  Once there if
>> I type in 'source bin/activate' I will get a virtualenv. However I can't
>> figure out how to do it from my script.
>
> What I can't figure out is why you are trying to do this using
> gnome-terminal? (You may have explained and I've missed it, in which
> case I apologize) Why do you feel you need to start a terminal?
>
> You normally execute the commands you want directly from within
> Python not by driving a terminal emulator. Terminals are just
> windows for humans. They run a shell that reads and executes
> commands. They format the output to fit the window. So when
> you use a terminal you are just adding 2 extra layers of
> complexity.
>
> You can change directory and run activate from within Python
> without the terminal. You could even start a bash session if
> you need to let the user (eg. you) type some commands. But you
> shouldn't need to start a terminal and then try to force it
> to execute commands. That just seems crazy to me. Or am I
> missing something?
>

I guess because I don't have the depth of knowledge to know any better. 
I wanted to automate a tedious process using Python.  I was working with 
a Python3 version of breezypythongui on a Python2.7 system. So I would 
open a terminal, cd to the correct directory and run source 
bin/activate, which would leave me with an open window.  Then I could 
work with Python3 and see error messages. I just focused on doing the 
same thing, but using a script.

Regards,  Jim

Regards,  Jim


From codemonkey at inbox.com  Sat Jul 12 18:43:30 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 12 Jul 2014 08:43:30 -0800
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lpqrid$os6$1@ger.gmane.org>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
Message-ID: <BC47E1331BA.0000083Ecodemonkey@inbox.com>


>> So much has been invented since my dos programming days and it is
>> overwhelming,
> 
> Actually very little has been *invented* since your DOS days.
> Almost everything we do today was already around back then.
>
I knew someone was going to say that.  Maybe it's the jargon 
that has been invented? 

Some questions I have at the moment:

1.  What is functional programming?
2.  What is procedural programming?
3.  What are data patterns?
4.  What are regular expression?

I worked for a private company for a while where I was the only 
programmer, then I worked for the Commonwealth of Kentucky, 
and then University of Washington, where I created and 
maintained database applications. I never heard of any of those 
things prior to the past few months since I started dipping my 
toes back in (more like total immersion, jeeze).  So maybe all 
this stuff has been around but I sure never heard of it.  

Almost every time I post a question on here, I get my hand 
slapped by someone, and the favorite thing for you all to say to 
newbies is "read the tutorial."  The tutorial is over our heads 
in a lot of cases because of the jargon, at least at first.  And 
so many times things are explained with C++ as an example.  

My favorite useless thing I have run across on the internet is 
the answer to what does hashable mean?  From stack overflow:

"An object is hashable if it has a hash value which never changes 
during its lifetime (it needs a __hash__() method), and can be 
compared to other objects (it needs an __eq__() or __cmp__() 
method). Hashable objects which compare equal must have the same 
hash value."

what is a hash value?  What's a _hash_() method (or any of those 
other methods)?  

You all take this understanding for granted, but it's not common 
knowledge for the rest of the world. I bet if I talked knitting 
and fiber jargon you all wouldn't understand much of what I was 
talking about lol.

Sorry this is so long, but if this list is to be useful for people 
the information needs to be understandable by the lay person
and maybe you all don't realize how much you take for granted.

Deb in WA, USA

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



From breamoreboy at yahoo.co.uk  Sat Jul 12 19:01:41 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sat, 12 Jul 2014 18:01:41 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <BC47E1331BA.0000083Ecodemonkey@inbox.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <BC47E1331BA.0000083Ecodemonkey@inbox.com>
Message-ID: <lprplf$lsm$1@ger.gmane.org>

On 12/07/2014 17:43, Deb Wyatt wrote:
>
>>> So much has been invented since my dos programming days and it is
>>> overwhelming,
>>
>> Actually very little has been *invented* since your DOS days.
>> Almost everything we do today was already around back then.
>>
> I knew someone was going to say that.  Maybe it's the jargon
> that has been invented?
>
> Some questions I have at the moment:
>
> 1.  What is functional programming?
> 2.  What is procedural programming?
> 3.  What are data patterns?
> 4.  What are regular expression?
>
> I worked for a private company for a while where I was the only
> programmer, then I worked for the Commonwealth of Kentucky,
> and then University of Washington, where I created and
> maintained database applications. I never heard of any of those
> things prior to the past few months since I started dipping my
> toes back in (more like total immersion, jeeze).  So maybe all
> this stuff has been around but I sure never heard of it.
>
> Almost every time I post a question on here, I get my hand
> slapped by someone, and the favorite thing for you all to say to
> newbies is "read the tutorial."  The tutorial is over our heads
> in a lot of cases because of the jargon, at least at first.  And
> so many times things are explained with C++ as an example.
>
> My favorite useless thing I have run across on the internet is
> the answer to what does hashable mean?  From stack overflow:
>
> "An object is hashable if it has a hash value which never changes
> during its lifetime (it needs a __hash__() method), and can be
> compared to other objects (it needs an __eq__() or __cmp__()
> method). Hashable objects which compare equal must have the same
> hash value."
>
> what is a hash value?  What's a _hash_() method (or any of those
> other methods)?
>
> You all take this understanding for granted, but it's not common
> knowledge for the rest of the world. I bet if I talked knitting
> and fiber jargon you all wouldn't understand much of what I was
> talking about lol.
>
> Sorry this is so long, but if this list is to be useful for people
> the information needs to be understandable by the lay person
> and maybe you all don't realize how much you take for granted.
>
> Deb in WA, USA
>

Start at wikipedia.  For Python specific terms see 
https://docs.python.org/3/glossary.html

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From amonroe at columbus.rr.com  Sat Jul 12 19:05:10 2014
From: amonroe at columbus.rr.com (R. Alan Monroe)
Date: Sat, 12 Jul 2014 13:05:10 -0400
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <BC47E1331BA.0000083Ecodemonkey@inbox.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <BC47E1331BA.0000083Ecodemonkey@inbox.com>
Message-ID: <1192752246.20140712130510@columbus.rr.com>

> what is a hash value?

Some clever person back in the 1950s realized that computers were
better at numbers than names. So they came up with some gimmicks to
convert names to numbers. It was probably something fancier than "a=1,
b=2, etc. Now let's add up all the letters of the person's name to
make a unique number for that person", but that at least gives you an
idea of what's going on.

Instead of hunting through a list of names for John Doe to find his
phone number, just convert John Doe to 2453 or whatever, then jump
directly to the 2453rd slot in an array, and stow/find his phone
number there.

You can probably immediately see a drawback. Two people's names might
add up to the same number. There are two fixes. Come up with a better
names-to-numbers gimmick, or come up with a gimmick like mini-lists at
each number.

Alan


From steve at pearwood.info  Sat Jul 12 20:14:26 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 13 Jul 2014 04:14:26 +1000
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <BC47E1331BA.0000083Ecodemonkey@inbox.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <BC47E1331BA.0000083Ecodemonkey@inbox.com>
Message-ID: <20140712181426.GK5705@ando>

Hi Deb,

My answers are interleaved with your questions.



On Sat, Jul 12, 2014 at 08:43:30AM -0800, Deb Wyatt wrote:

> Some questions I have at the moment:
> 
> 1.  What is functional programming?
> 2.  What is procedural programming?
> 3.  What are data patterns?
> 4.  What are regular expression?

Good questions!

Here are some *very* simplified answers, but enough to give you a 
flavour of the answer.


1. Functional programming is based on the ideas that programming should 
(as much as possible) be like mathematics. Everything should be written 
as functions which avoid keeping state and don't have side-effects.

"State" refers to keeping values in a variable of some sort. The most 
obvious example is a global variable. Consider this simplified example:

    def say_hello():
        print "Hello, %s" % name

    name = "Steve"
    say_hello()  # prints "Hello, Steve"
    name = "Deb"
    say_hello()  # prints "Hello, Deb"


Functional programming avoids the global variable and prefers to write 
the say_hello function like this:

    def say_hello(name):
        print "Hello, %s" % name

    say_hello("Steve")  # prints "Hello, Steve"
    say_hello("Deb")  # prints "Hello, Deb"


"Side-effects" refers to functions having any effect other than 
returning a result. Now obviously having *absolutely* no side-effects at 
all would be pointless, since we normally want to print the result (a 
side-effect!), save it in a file, turn on some machinery, or whatever 
the actual purpose of the program happens to be. But *internal* 
side-effects are considered to be a bad idea. Here's the kind of thing I 
mean:

    data = [4, 2, 1, 0, 5, 3]
    data.sort()  # has a side-effect
    print data == [4, 2, 1, 0, 5, 3]  # prints False, data has changed

The sort method has had a side-effect. Instead of returning a new list 
with the sorted values, it changes the existing list. A more functional 
way of writing this would be:

    data = [4, 2, 1, 0, 5, 3]
    sorted(data)  # returns a new list
    print data == [4, 2, 1, 0, 5, 3]  # prints True


It's hard to do justice to the reasons why functional programming makes 
the choices it does in just a few words, especially at 3:30am local 
time, but at least you should now have an idea of what F.P. is.



2.  What is procedural programming?

If you cast your mind back to the 1970s and 80s when people used to 
write BASIC code like this:

10 REM I can't remember BASIC commands, so I'm going to make them up
20 X = 0
30 IF X < 10
40 PRINT X
45 X = X + 1
50 ELSE
60 GOTO 30

you might remember that this style of programming was often 
characterised as "spaghetti code", because trying to follow the program 
flow through all the GOTOs was like trying to follow a strand of 
tangled up spaghetti. 

Procedural programming is the opposite of this. Instead of having one 
giant undifferentiated lump of code where you have to try to follow it 
from the first line to the last as one giant strand of spaghetti, and 
where everything belongs to a single shared environment, the code is 
divided up into small parcels of independent code, called "procedures", 
"functions" or "sub-routines".

Unlike a chunk of BASIC code, where you could jump into the middle of it 
with a GOTO, the important thing about a procedure is that it has only a 
single entry-point: you can only start the procedure from the beginning, 
and work its way to the end, where it then automatically returns to the 
code that called it.

The other important thing about procedures is that they can have local 
variables. Consider these two procedures:

    # not Python code, just some pseudo-code I made up
    procedure do_this:
        set x = 1
        print x

   procedure do_that:
       set x = 2
       do_this()
       print x


If you called do_that(), it would print "1 2", *not* "1 1". The reason 
is that the x inside "do_this" is local to that procedure, so it doesn't 
change the x inside "do_that". What happens inside a procedure is 
isolated from the insides of other procedures.


3.  What are data patterns?

I have no idea :-)


4.  What are regular expression?

Regular expressions are a kind of mini-programming language used for 
matching patterns in text. In the regular expression, certain special 
characters have special meanings. For example:

    A      just means the letter "A"
    A*     means "any number of the letter A (including zero)", 
           e.g. A, AA, AAA, ...
    A+     means "at least one letter A" (like A* but excludes zero)
    .      means "any character at all"
    .*     means "any number of any character"
    B?     means "zero or one of the letter B"
    A|B    means "A or B"


and so on. By using regular expressions, you can search text for 
alternatives, without having to list out every single possible 
substring. A concrete example: suppose I wanted to extract out a number 
from a string. I could say:

    search for 0
    search for 1
    search for 2
    ...
    search for 1234567
    search for 1234568
    search for 1234569
    search for 1234570
    ...

but it would get pretty tedious after a while, right? Here's how I can 
do it simply with a regular expression:

py> import re
py> pattern = r'\d+'  # one or more digits
py> mo = re.search(pattern, "The number today is 924736, okay?")
py> mo.group()
'924736'



> I worked for a private company for a while where I was the only 
> programmer, then I worked for the Commonwealth of Kentucky, and then 
> University of Washington, where I created and maintained database 
> applications. I never heard of any of those things prior to the past 
> few months since I started dipping my toes back in (more like total 
> immersion, jeeze).  So maybe all this stuff has been around but I sure 
> never heard of it.

What language or languages did you program with?


> Almost every time I post a question on here, I get my hand slapped by 
> someone, and the favorite thing for you all to say to newbies is "read 
> the tutorial." 

Ouch! Well, you certainly shouldn't be getting slapped for asking 
questions. Sorry about that.

Yes, reading the tutorial is important, and we've had plenty of people 
here who don't make even the *tiniest* effort to learn on their own. But 
if you make the effort, we should do the same.


> The tutorial is over our heads in a lot of cases 
> because of the jargon, at least at first.  And so many times things 
> are explained with C++ as an example.
> 
> My favorite useless thing I have run across on the internet is 
> the answer to what does hashable mean?  From stack overflow:
> 
> "An object is hashable if it has a hash value which never changes 
> during its lifetime (it needs a __hash__() method), and can be 
> compared to other objects (it needs an __eq__() or __cmp__() 
> method). Hashable objects which compare equal must have the same 
> hash value."
> 
> what is a hash value?  What's a _hash_() method (or any of those 
> other methods)?  

You know hash browns? You take a potato, and grate it, mix it up, 
and then cook it. In programming, "hashing" does the same thing: take 
some data, slice it, dice it, grate it, mix it all together, and turn it 
into a single number. An example:

py> hash("Hello!")
-1940210404
py> hash("hello!")
853481916


Notice that changing just one letter *completely* changes the hash value 
that we get out. The hash function takes the string, separates it into 
all the individual pieces ("H", "e", ...), mixes them up, and combines 
them into a single value, a number. If you change just one of those 
pieces, by the time it's all mixed together and combined again you get 
something very different.

Why on earth would anyone need such a thing? Well, that's complicated, 
but the short answer is, hashes are used for dictionaries.

What's __hash__? Like all Double leading and trailing UNDERscore 
("dunder") names, __hash__ is used by Python. When you write your own 
classes, if you ever do (it's not compulsory), if you need to control 
how Python calculates the hash of your objects, you write a __hash__ 
method to do so. But normally you wouldn't worry about it. In 15 years 
of Python programming, I don't think I have even once written my own 
__hash__ method.


> You all take this understanding for granted, but it's not common 
> knowledge for the rest of the world. I bet if I talked knitting 
> and fiber jargon you all wouldn't understand much of what I was 
> talking about lol.

:-)




-- 
Steven

From alan.gauld at btinternet.com  Sat Jul 12 20:21:59 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 19:21:59 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <BC47E1331BA.0000083Ecodemonkey@inbox.com>
References: <b2a599481fb.00000309codemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <BC47E1331BA.0000083Ecodemonkey@inbox.com>
Message-ID: <lpruc7$8ud$1@ger.gmane.org>

On 12/07/14 17:43, Deb Wyatt wrote:
>
>>> So much has been invented since my dos programming days and it is
>>> overwhelming,
>>
>> Actually very little has been *invented* since your DOS days.
>> Almost everything we do today was already around back then.
>>
> I knew someone was going to say that.

:-)


> Maybe it's the jargon that has been invented?

In some cases yes, but mostly it was there all
along just hideen in obscurity. For example all the GUI stuff we take 
for granted really came together at Xerox Park in the 1970's but didn't 
become well known till Steve Jobs paid a visit and promptly built the 
Apple Mac (after initially flopping with the Lisa!) around 1984.

> Some questions I have at the moment:
>
> 1.  What is functional programming?
> 2.  What is procedural programming?
> 3.  What are data patterns?
> 4.  What are regular expression?

As Mark has said I always go to Wikipedia for these kinds of answers.
It is a great resource for all things technical. I'll try to give
the newbies answers too though...

 > 1.  What is functional programming?
 > 2.  What is procedural programming?

These are both programming paradigms.

Most programmers learn procedural programming first - also known as 
imperative programming. This is where you tell the computer how to solve 
the problem using the familiar sequences, conditionals and loops. You 
then package these constructs into procedures (or functions).
You have data floating around loose and your procedures operate
on that data changing its state(values) as it goes along.
This means that in a procedural program two calls to the same
function can return different results even if they have the
same inputs:

 >>> state = True
 >>> def f(n):
...   global state
...   state = not state
...   if state and (n % 2):  # n is odd
...      return n ** 2
...   else: return n
...
 >>> f(3)
3
 >>> f(3)
9

Functional programming is more like pure math. It is built on functions 
that return values and the values should not depend on external state.
They always return the same result for the same input. Functional 
programming also attempts (with mixed results) to produce programs that 
look more like problem specifications than solution descriptions. So the 
functions often operate on data sets rather than individuial items 
(avoiding loops) and tend to use recursion a lot.
( I have a topic on FP in my tutor that explains more and uses
Python to illustrate...)

There are also Object Oriented Programming and Logic Programming paradigms.

 > 3.  What are data patterns?

This is a bit more open ended since there are several possible answers 
depending on context. At one level it can refer to data modelling 
patterns that crop up again and again. For example instead of modelling 
assigned to each, model it as a person and a role. All the people go in 
Person, all the jobs in role. Then you assign one or more roles to each 
person. When a person gets promoted you don't have to move the data 
between tables you just change the relationships slightly. That is one 
common data pattern in the world of modelling. But it depends on the 
context where you came across the term

 > 4.  What are regular expression?

A form of text pattern. They are like wildcards for filenames but more 
powerful. They are used for finding substrings in text. I have another 
topic in my tutorial on regular expressions...
Nowadays most languages support regular expression searches, including 
most SQL dialects on databases.

> You all take this understanding for granted, but it's not common
> knowledge for the rest of the world.

I sympathise.
One of the primary aims of my tutorial is to take a complete beginner to 
the point where they can understand these more technical tutorials. A 
lot of time has gone into explaining general computing terminology as 
well as showing how to use it. As far as possible every jargon term is 
explained when first introduced.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From joseph.lee22590 at gmail.com  Sat Jul 12 09:15:22 2014
From: joseph.lee22590 at gmail.com (Joseph Lee)
Date: Sat, 12 Jul 2014 00:15:22 -0700
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
Message-ID: <001d01cf9da1$0c72cf60$25586e20$@gmail.com>

Hi Steve,

In your conditionals:

?

while message != 'q' or 'Q'/message != ?q? or message != ?Q?:
?

Python will only match the first variable. A better approach (which might be a good solution) would be capturing the exit commands in a list like this:

JL?s code:

while message not in [?q?, ?Q?]:

               # blah, blah, your code?

# code end

Effectively, we?re testing if the command is a member of our exit commands list, and if it is, we?ll fall off the loop. Try this solution and see if it works for you.

Cheers,

Joseph

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140712/4a556847/attachment.html>

From smrodriguez88 at gmail.com  Sat Jul 12 09:29:08 2014
From: smrodriguez88 at gmail.com (Steve Rodriguez)
Date: Sat, 12 Jul 2014 01:29:08 -0600
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <lpqnmf$hen$1@ger.gmane.org>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqn1i$bbe$1@ger.gmane.org> <lpqnmf$hen$1@ger.gmane.org>
Message-ID: <CAELekOG1cPjJXcLFyQBDj9=OtdrJ_dxtytyjUhB=a2Mu3NNX4g@mail.gmail.com>

Thank you guys! Works perfectly! :D

Regards,
Steve Rodriguez


On Sat, Jul 12, 2014 at 1:21 AM, Peter Otten <__peter__ at web.de> wrote:

> Peter Otten wrote:
>
> > PS: You sometimes see
> >
> > message in "qQ"
> >
> > but this is buggy as it is true when the message is either
> > "q", "Q", or "qQ".
>
> Oops, I forgot "".
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140712/1faec32e/attachment.html>

From wolfgang.maier at biologie.uni-freiburg.de  Sat Jul 12 14:39:12 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Sat, 12 Jul 2014 14:39:12 +0200
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <20140712121950.GI5705@ando>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
 <lpr2i5$vut$1@ger.gmane.org> <20140712121950.GI5705@ando>
Message-ID: <53C12C70.301@biologie.uni-freiburg.de>

On 12.07.2014 14:19, Steven D'Aprano wrote:
> On Sat, Jul 12, 2014 at 11:27:17AM +0100, Alan Gauld wrote:
>> On 12/07/14 10:28, Steven D'Aprano wrote:
>>
>>> If you're using Python 3.3 or higher, it is better to use
>>> message.casefold rather than lower. For English, there's no real
>>> difference:
>>> ...
>>> but it can make a difference for non-English languages:
>>>
>>> py> "Gro?e".lower()  # German for "great" or "large"
>>> 'gro?e'
>>> py> "Gro?e".casefold()
>>> 'grosse'
>>
>> You learn something new etc...
>>
>> But I'm trying to figure out what difference this makes in
>> practice?
>>
>> If you were targeting a German audience wouldn't you just test
>> against the German alphabet? After all you still have to expect 'grosse'
>> which isn't English, so if you know to expect grosse
>> why not just test against gro?e instead?
>
> Because the person might have typed any of:
>
> grosse
> GROSSE
> gROSSE
> gro?e
> Gro?e
> GRO?E
> GRO?E
>
> etc., and you want to accept them all, just like in English you'd want
> to accept any of GREAT great gREAT Great gReAt etc. Hence you want to
> fold everything to a single, known, canonical version. Case-fold will do
> that, while lowercasing won't.
>
> (The last example includes a character which might not be visible to
> many people, since it is quite unusual and not supported by many fonts
> yet. If it looks like a box or empty space for you, it is supposed
> to be capital sharp-s, matching the small sharp-s ?.)
>

Very interesting advice. Wasn't aware at all of this feature of casefold.
As a native German speaker, I have to say that your last two examples 
involving the capital ? are pretty contrived: although the capital ? is 
part of unicode, it is not an official part of the German alphabet and 
nobody is using it (in fact, I had to look it up in Wikipedia now to 
learn what that letter is).
An even better example than the rest of yours would be Ku? (German for 
the noun kiss), which only people above 30 (like me) still spell this 
way, but younger people spell Kuss since the official rules have changed 
over the last 10 years.
In this particular case, you should definitely be prepared to handle 
"Kuss" and "Ku?" as legal input.


From wolfgang.maier at biologie.uni-freiburg.de  Sat Jul 12 14:43:56 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Sat, 12 Jul 2014 14:43:56 +0200
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <lpr96f$3ss$1@ger.gmane.org>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
 <lpr96f$3ss$1@ger.gmane.org>
Message-ID: <53C12D8C.4060904@biologie.uni-freiburg.de>

On 12.07.2014 14:20, Dave Angel wrote:
>
> I don't remember my high school German enough to remember if the  ?
>
> character is an example,  but in various languages there are
>   characters that exist only in uppercase,  and whose lowercase
>   equivalent is multiple letters. Or vice versa. And characters
>   that have multiple valid spellings in uppercase,  but only one in
>   lowercase.
>
> If the latter is true for German,  perhaps GROSSE and GRO?E are
>   valid uppercase,  but only grosse for lowercase.
>

No, that's not the case.
Only gro?e is valid lowercase, but many people got so used to computers 
not dealing with ? correctly that they'd type grosse automatically.
Conversely, since there is no official capital form of ? (see my reply 
to Steven), GROSSE is standard uppercase although you might encounter 
GRO?E occasionally.


From alan.gauld at btinternet.com  Sat Jul 12 20:32:03 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 19:32:03 +0100
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <20140712121950.GI5705@ando>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
 <lpr2i5$vut$1@ger.gmane.org> <20140712121950.GI5705@ando>
Message-ID: <lpruv4$f6p$1@ger.gmane.org>

On 12/07/14 13:19, Steven D'Aprano wrote:

> Because the person might have typed any of:
>
> grosse
> gro?e

> etc., and you want to accept them all, just like in English

The bit I was missing was that a German user might use the ss version 
instead the ? so testing for either of them alone is insufficient.
lower() or casefold() would deal with the mixed case variations, but 
lower() would not fix the ss v ? issues.

Thanks,

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From alan.gauld at btinternet.com  Sat Jul 12 20:36:39 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 19:36:39 +0100
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lprkip$u5h$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
 <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
 <lpm7k9$ojq$1@ger.gmane.org> <lpq32l$3r4$1@ger.gmane.org>
 <lpqq32$9r8$1@ger.gmane.org> <lprkip$u5h$1@ger.gmane.org>
Message-ID: <lprv7n$hrb$1@ger.gmane.org>

On 12/07/14 16:34, Jim Byrnes wrote:

> I guess because I don't have the depth of knowledge to know any better.
> I wanted to automate a tedious process using Python.  I was working with
> a Python3 version of breezypythongui on a Python2.7 system. So I would
> open a terminal, cd to the correct directory and run source
> bin/activate, which would leave me with an open window.

OK, Now imagine you were doing this in (bash) shell - I think you
are familiar with shell scripts? You wouldn't try to make the shell
script open a second terminal and then try to inject commands
into that terminal? You would just run the cd and source commands in the 
shell script within the terminal session you were already
using, right?

Python is just another scripting tool. You use it the same way. You run 
the script from a terminal so you don't need to open another one, just 
use the one you are in.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From jf_byrnes at comcast.net  Sat Jul 12 21:16:38 2014
From: jf_byrnes at comcast.net (Jim Byrnes)
Date: Sat, 12 Jul 2014 14:16:38 -0500
Subject: [Tutor] How can I open and use gnome-terminal from a Python
	script?
In-Reply-To: <lprv7n$hrb$1@ger.gmane.org>
References: <lphl9m$8uh$1@ger.gmane.org>
 <CANLXbfDyyfp5Wn1Swq1qKiUaHxAFp3wBhsNrVq6FsFHs+KBV6Q@mail.gmail.com>
 <lpjgul$aqi$1@ger.gmane.org>
 <CANLXbfB_Pr1kjiktpyyMrYcnmL-Fty=9TN9uzszLCnWRFNPHEA@mail.gmail.com>
 <lpm7k9$ojq$1@ger.gmane.org> <lpq32l$3r4$1@ger.gmane.org>
 <lpqq32$9r8$1@ger.gmane.org> <lprkip$u5h$1@ger.gmane.org>
 <lprv7n$hrb$1@ger.gmane.org>
Message-ID: <lps1im$aj6$1@ger.gmane.org>

On 07/12/2014 01:36 PM, Alan Gauld wrote:
> On 12/07/14 16:34, Jim Byrnes wrote:
>
>> I guess because I don't have the depth of knowledge to know any better.
>> I wanted to automate a tedious process using Python.  I was working with
>> a Python3 version of breezypythongui on a Python2.7 system. So I would
>> open a terminal, cd to the correct directory and run source
>> bin/activate, which would leave me with an open window.
>
> OK, Now imagine you were doing this in (bash) shell - I think you
> are familiar with shell scripts? You wouldn't try to make the shell
> script open a second terminal and then try to inject commands
> into that terminal? You would just run the cd and source commands in the
> shell script within the terminal session you were already
> using, right?
>
> Python is just another scripting tool. You use it the same way. You run
> the script from a terminal so you don't need to open another one, just
> use the one you are in.
>

You're right.  I guess I caused some confusion by stopping short of 
stating my ultimate goal. I wanted a 2 click solution. Open a launcher 
and then click to run the script.  That's why I wanted to open the 
terminal from the script.  When I try to do something I am not sure of I 
usually start simple and once I have something working try to build on 
that. Sorry I didn't state it more clearly sooner, I guess I was too 
caught up in trying to get it to work.

Regards,  Jim


From codemonkey at inbox.com  Sat Jul 12 21:24:08 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 12 Jul 2014 11:24:08 -0800
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <20140712181426.GK5705@ando>
References: <bc47e1331ba.0000083ecodemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <b2a599481fb.00000309codemonkey@inbox.com>
Message-ID: <BDAEEBB5BF1.0000095Ecodemonkey@inbox.com>



Wow.  Just wow! Thank you for all that information.  That was really helpful.  Thank you very much!!

> What language or languages did you program with?
CA Clipper was the main language I used in my former programming life (dBase compiler). A very simple, basic database manipulation language, but quite useful.
Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



From alan.gauld at btinternet.com  Sat Jul 12 22:57:37 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 12 Jul 2014 21:57:37 +0100
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <BDAEEBB5BF1.0000095Ecodemonkey@inbox.com>
References: <bc47e1331ba.0000083ecodemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <b2a599481fb.00000309codemonkey@inbox.com>
 <BDAEEBB5BF1.0000095Ecodemonkey@inbox.com>
Message-ID: <lps7g1$91s$1@ger.gmane.org>

On 12/07/14 20:24, Deb Wyatt wrote:

> CA Clipper was the main language

If I recall correctly it was one of several variants on DBase?
There were also Foxpro and others all sharing similar syntax.

I once got a free copy of DBase4 (back in the days when we
paid for compilers!) but it is still in its shrink wrap - I
suspect its on 3inch floppies which I can no longer read!...

If that's your background you might find the Dabo project
interesting. Its built by some FoxPro guys who wanted similar
features using Python. It has a GUI builder and some nice
tools to build databases and forms.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From codemonkey at inbox.com  Sat Jul 12 23:24:50 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 12 Jul 2014 13:24:50 -0800
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lps7g1$91s$1@ger.gmane.org>
References: <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <bc47e1331ba.0000083ecodemonkey@inbox.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com> <lpmo81$ja6$1@ger.gmane.org>
 <b2a599481fb.00000309codemonkey@inbox.com>
 <bdaeebb5bf1.0000095ecodemonkey@inbox.com>
Message-ID: <BEBCAFA47A7.00000013codemonkey@inbox.com>


> -----Original Message-----
> From: alan.gauld at btinternet.com
> Sent: Sat, 12 Jul 2014 21:57:37 +0100
> To: tutor at python.org
> Subject: Re: [Tutor] Anti-Patterns in Python Programming
> 
> On 12/07/14 20:24, Deb Wyatt wrote:
> 
>> CA Clipper was the main language
> 
> If I recall correctly it was one of several variants on DBase?
> There were also Foxpro and others all sharing similar syntax.
> 
> I once got a free copy of DBase4 (back in the days when we
> paid for compilers!) but it is still in its shrink wrap - I
> suspect its on 3inch floppies which I can no longer read!...

more likely 5.25 floppies lol.
> 
> If that's your background you might find the Dabo project
> interesting. Its built by some FoxPro guys who wanted similar
> features using Python. It has a GUI builder and some nice
> tools to build databases and forms.
>
Thanks for that info, I will take a look.  So much fun stuff to play with...

Deb in WA, USA

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth



From dyoo at hashcollision.org  Sun Jul 13 01:11:06 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sat, 12 Jul 2014 16:11:06 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
Message-ID: <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>

> On Fri, Jul 11, 2014 at 6:21 AM, Danny Yoo <dyoo at hashcollision.org> wrote:
>> The ones I use for my personal and professional use are webfaction.com and
>> appengine.google.com.  I'm sure others can give more suggestions.
>
> Both are services used for hosting webapps, not static websites.

Hi Chris,


It's true that hosting providers that provide access to the web server
allow for dynamic web applications.  That being said, the same
technology can be used for static web sites.  It would not preclude
the serving of static content.  For the technical details on serving
static files on App Engine, for example, see:
https://developers.google.com/appengine/docs/python/gettingstartedpython27/staticfiles

I think the point you're making is that John can probably stick to
something simple and free, which makes sense.  But App Engine's free
quotes are such that John might just be able to use it, depending on
his requirements.


I just want to make sure to address this point: just because an HTTP
request handler is a function of the type:

    handler: request -> response

that it doesn't mean the response can't be a simple, constant value.
I can point at:

#################################
def random_number():
    """Returns a random number."""
    return 4
#################################

and still claim that random_number() is technically a function.  :P

(Reference: http://xkcd.com/221/)

From dyoo at hashcollision.org  Sun Jul 13 01:32:12 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sat, 12 Jul 2014 16:32:12 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
Message-ID: <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>

Hi Chris,

Yikes.  I need to say that as, for disclosure: I work at Google.  I do
not work on the App Engine team, but I need to acknowledge my
potential conflict-of-interest, and I apologize for not stating this
in my reply.

From dyoo at hashcollision.org  Sun Jul 13 02:01:43 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sat, 12 Jul 2014 17:01:43 -0700
Subject: [Tutor] Image Upload FalconFramework
In-Reply-To: <53B381D0.8050707@gmail.com>
References: <53B381D0.8050707@gmail.com>
Message-ID: <CAGZAPF4QZJpHPGfr6OPjhS-sDWz+EXRMt6wOqOWuE1dZ0udG-Q@mail.gmail.com>

On Tue, Jul 1, 2014 at 8:51 PM, Peter Romfeld
<peter.romfeld.hk at gmail.com> wrote:
> Hi,
>
> I try to make a simple image upload function, in django i just used:
>
> for feature phones:
> file = request.body
>
> rest:
> file = request.FILES['image'].read()
>
> with falcon i tried but not working
> req.stream.read()
>
> Their Freenode Channel is quite empty and it seems unused, so i hope i
> could find someone here.


Hi Peter,

Apologies; it looks like none of us here on tutor at python have been
able to give you good help on this one.

It sounds like you're trying to use the Falcon framework?
(http://falconframework.org/)  Unfortunately, I don't have any
experience with this framework.

Reading...  It appears Falcon Framework is an implementation of the
Web Server Gateway Interface (WSGI) specificiation?  If so, you might
better luck by searching for the term "wsgi file upload".

I see an example in:
https://github.com/thejimmyg/wsgi-file-upload/blob/master/upload.py
that might apply.

From codemonkey at inbox.com  Sun Jul 13 03:24:36 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Sat, 12 Jul 2014 17:24:36 -0800
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <lpruc7$8ud$1@ger.gmane.org>
References: <bc47e1331ba.0000083ecodemonkey@inbox.com>
 <1405015617.4078.bpmail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <001001cf9d90$12fd37f0$38f7a7d0$@gmail.com>
 <b60f16351e0.00000511codemonkey@inbox.com>
 <b2a599481fb.00000309codemonkey@inbox.com>
Message-ID: <C0D499B851C.00000150codemonkey@inbox.com>


> -----Original Message-----
> From: alan.gauld at btinternet.com
> Sent: Sat, 12 Jul 2014 19:21:59 +0100
> To: tutor at python.org
> Subject: Re: [Tutor] Anti-Patterns in Python Programming
> 
> On 12/07/14 17:43, Deb Wyatt wrote:
>> 
>>>> So much has been invented since my dos programming days and it is
>>>> overwhelming,
>>> 
>>> Actually very little has been *invented* since your DOS days.
>>> Almost everything we do today was already around back then.
>>> 
>> I knew someone was going to say that.
> 
> :-)
> 
> 
>> Maybe it's the jargon that has been invented?
> 
> In some cases yes, but mostly it was there all
> along just hideen in obscurity. For example all the GUI stuff we take
> for granted really came together at Xerox Park in the 1970's but didn't
> become well known till Steve Jobs paid a visit and promptly built the
> Apple Mac (after initially flopping with the Lisa!) around 1984.
> 
>> Some questions I have at the moment:
>> 
>> 1.  What is functional programming?
>> 2.  What is procedural programming?
>> 3.  What are data patterns?
>> 4.  What are regular expression?
> 
> As Mark has said I always go to Wikipedia for these kinds of answers.
> It is a great resource for all things technical. I'll try to give
> the newbies answers too though...
> 
>  > 1.  What is functional programming?
>  > 2.  What is procedural programming?
> 
> These are both programming paradigms.
> 
> Most programmers learn procedural programming first - also known as
> imperative programming. This is where you tell the computer how to solve
> the problem using the familiar sequences, conditionals and loops. You
> then package these constructs into procedures (or functions).
> You have data floating around loose and your procedures operate
> on that data changing its state(values) as it goes along.
> This means that in a procedural program two calls to the same
> function can return different results even if they have the
> same inputs:
> 
>  >>> state = True
>  >>> def f(n):
> ...   global state
> ...   state = not state
> ...   if state and (n % 2):  # n is odd
> ...      return n ** 2
> ...   else: return n
> ...
>  >>> f(3)
> 3
>  >>> f(3)
> 9
> 
> Functional programming is more like pure math. It is built on functions
> that return values and the values should not depend on external state.
> They always return the same result for the same input. Functional
> programming also attempts (with mixed results) to produce programs that
> look more like problem specifications than solution descriptions. So the
> functions often operate on data sets rather than individuial items
> (avoiding loops) and tend to use recursion a lot.
> ( I have a topic on FP in my tutor that explains more and uses
> Python to illustrate...)
> 
> There are also Object Oriented Programming and Logic Programming
> paradigms.
> 
>  > 3.  What are data patterns?
> 
> This is a bit more open ended since there are several possible answers
> depending on context. At one level it can refer to data modelling
> patterns that crop up again and again. For example instead of modelling
> assigned to each, model it as a person and a role. All the people go in
> Person, all the jobs in role. Then you assign one or more roles to each
> person. When a person gets promoted you don't have to move the data
> between tables you just change the relationships slightly. That is one
> common data pattern in the world of modelling. But it depends on the
> context where you came across the term
> 
>  > 4.  What are regular expression?
> 
> A form of text pattern. They are like wildcards for filenames but more
> powerful. They are used for finding substrings in text. I have another
> topic in my tutorial on regular expressions...
> Nowadays most languages support regular expression searches, including
> most SQL dialects on databases.
> 
>> You all take this understanding for granted, but it's not common
>> knowledge for the rest of the world.
> 
> I sympathise.
> One of the primary aims of my tutorial is to take a complete beginner to
> the point where they can understand these more technical tutorials. A
> lot of time has gone into explaining general computing terminology as
> well as showing how to use it. As far as possible every jargon term is
> explained when first introduced.
>
Thank you very much for your answers.  I'll start going through your tutorial.  I can't wait to hear more about the book you mentioned you were working on a week or two ago.

Deb in WA, USA

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



From steve at pearwood.info  Sun Jul 13 07:07:13 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 13 Jul 2014 15:07:13 +1000
Subject: [Tutor] While loop issue, variable not equal to var or var
In-Reply-To: <53C12C70.301@biologie.uni-freiburg.de>
References: <CAELekOFC+0W-M0SWB9+av9jsu0SJ54yh41DGLg4iOd_xDSMuzg@mail.gmail.com>
 <lpqrsg$rbg$1@ger.gmane.org> <20140712092854.GH5705@ando>
 <lpr2i5$vut$1@ger.gmane.org> <20140712121950.GI5705@ando>
 <53C12C70.301@biologie.uni-freiburg.de>
Message-ID: <20140713050712.GL5705@ando>

On Sat, Jul 12, 2014 at 02:39:12PM +0200, Wolfgang Maier wrote:
[...]
> Very interesting advice. Wasn't aware at all of this feature of casefold.
> As a native German speaker, I have to say that your last two examples 
> involving the capital ? are pretty contrived: although the capital ? is 
> part of unicode, it is not an official part of the German alphabet and 
> nobody is using it (in fact, I had to look it up in Wikipedia now to 
> learn what that letter is).

Interestingly, although capital ? is not official, it used to be a lot 
more common than it is now, and never quite disappeared:

http://opentype.info/blog/2011/01/24/capital-sharp-s/


Now that the common fonts provided on Windows support the capital sharp 
s, I wouldn't be surprised if it starts to come back into vogue. 
Typesetters will be at the forefront, since they care about the look of 
things:

http://www.glyphsapp.com/tutorials/localize-your-font-german-capital-sharp-s



> An even better example than the rest of yours would be Ku? (German for 
> the noun kiss), which only people above 30 (like me) still spell this 
> way, but younger people spell Kuss since the official rules have changed 
> over the last 10 years.
> In this particular case, you should definitely be prepared to handle 
> "Kuss" and "Ku?" as legal input.

Good example! Thank you!


-- 
Steven

From steve at pearwood.info  Sun Jul 13 07:59:59 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 13 Jul 2014 15:59:59 +1000
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
Message-ID: <20140713055958.GN5705@ando>

Hi Danielle, and welcome.

Others have already replied to your post, and I'm going to reply with 
pretty much the same answer:

Please help us to help you! We're not mind-readers, we need to see the 
actual error messages you get, and your actual code, not just a rough 
paraphrase of it.

When Python has an error to report, it will print a traceback like this:

py> x = 1
py> y = 1/(1-x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ZeroDivisionError: division by zero


It's important to copy and paste the whole traceback, starting with the 
first line "Traceback ..." to the end. Tracebacks often contain a lot of 
useful information to help debugging. (Although not always: one of the 
frustrations of programming is that sometimes the error messages aren't 
very useful.)

You say:

> I am supposed to use operand1=2 and operand2=7 

You should be able to use that *exactly* as it is (although putting 
spaces around the = sign is recommended):

py> operand1 = 2
py> operand2 = 7
py> result = operand1 + operand2
py> print(result)
9



> To complete: result= operand1+operand2 etc, but I keep getting invalid 
> syntax either on the " or operand1. Please help

We can't tell what you have mistyped if we don't know what you typed in 
the first place :-(

Regards,


Steve

On Thu, Jul 10, 2014 at 10:50:12PM -0700, Danielle Salaz wrote:
> I'm a noob to Python and cannot figure out how to complete one of my assignments. 
> 
> I am supposed to use operand1=2 and operand2=7 
> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either on the " or operand1. Please help
> 
> Sent from my iPhone
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

From danieshari at gmail.com  Sun Jul 13 09:25:55 2014
From: danieshari at gmail.com (Danielle Salaz)
Date: Sun, 13 Jul 2014 00:25:55 -0700
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
 <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>
Message-ID: <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>

This is what I've been doing, also I'm using version 3.4

set "(operand1 = 2 and operand2 = 7)
print (operand1 = 2)
print (operand2 = 7)
print (result=operand1 + operand2)
print (result=operand2 - operand1)
print (result=operand2 * operand1)
print (result=operand2 / operand1)
print (result=operand2 % operand1)

Traceback (most recent call last):
  File "C:/Python34/Assignment3_DanielleSalaz.py", line 1, in <module>
    print (operand1 = 2)
TypeError: 'operand1' is an invalid keyword argument for this function
>>> 

Sent from my iPhone

> On Jul 11, 2014, at 12:38 PM, William Ray Wing <wrw at mac.com> wrote:
> 
>> On Jul 11, 2014, at 1:50 AM, Danielle Salaz <danieshari at gmail.com> wrote:
>> 
>> I'm a noob to Python and cannot figure out how to complete one of my assignments.
> 
> Welcome to Python - I?d hope you?ve been monitoring this Tutor list for at least a few days -
> 
>> I am supposed to use operand1=2 and operand2=7 
>> To complete: result= operand1+operand2 etc, but I keep getting invalid syntax either on the " or operand1. Please help
> 
> If you have been, you would see that we need to know which version of Python, what operating system, and then see a complete copy and paste of the traceback and the code you were executing.
> 
> In this case, that would be particularly relevant, because it would appear that you have typo?d your iPhone e-mail since there is no " character anyplace in any of the three assignment statements you have given us. Worse, on an iPhone keypad, the ? character isn?t close to anything else you might logically have used.
> 
> -Bill
> 
> 
> 
>> Sent from my iPhone
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
> 

From danieshari at gmail.com  Sun Jul 13 09:26:50 2014
From: danieshari at gmail.com (Danielle Salaz)
Date: Sun, 13 Jul 2014 00:26:50 -0700
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <lppimh$ig2$1@ger.gmane.org>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
 <lppimh$ig2$1@ger.gmane.org>
Message-ID: <98534BA2-D202-4367-BEC9-5734980A6DB5@gmail.com>

I am using idle

Sent from my iPhone

> On Jul 11, 2014, at 1:50 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> 
>> On 11/07/14 06:50, Danielle Salaz wrote:
>> I'm a noob to Python and cannot figure out how to complete one of my assignments.
>> 
>> I am supposed to use operand1=2 and operand2=7
>> To complete: result= operand1+operand2 etc, but
> 
> We need more detail.
> 
> How are you entering your code? Is it using a tool like
> IDLE or an operating system console version of python?
> 
> Are you typing at the interactive python prompt,
> usually looking like
> >>>
> 
> > I keep getting invalid syntax either on the " or operand1.
> 
> Please post the exact code you entered and the
> full error message, do not summarize.
> 
> There is no " in the little bit code you posted.
> And operand1 appears twice.
> We need to see exactly what you are doing - what you
> typed, and what Python told you was wrong.
> 
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From alan.gauld at btinternet.com  Sun Jul 13 10:57:48 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 13 Jul 2014 09:57:48 +0100
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
 <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>
 <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>
Message-ID: <lpthmc$mvg$1@ger.gmane.org>

On 13/07/14 08:25, Danielle Salaz wrote:
> This is what I've been doing, also I'm using version 3.4
>
> set "(operand1 = 2 and operand2 = 7)

Do you by any chance have some Lisp or Scheme experience?
That looks like a Lispy kind of syntax...

Whatever, in Python you don't need to use words
like set or let when assigning values to names.
The above line is meaningless to Python,
hence the errors.

To assign a value you simply do the assignment directly.

operand1 = 2
operand2 = 7


> print (operand1 = 2)

The print function displays output on the screen.
It converts its input (between the parentheses)
to strings for you. But it cannot do assignments.
Your print statement could look like

print(2)   # print a literal value

or

print(operand1)  # print a symbol's value

> print (result=operand1 + operand2)

Again this is trying to print what is inside the parentheses
But it can't execute the assignment. You need to assign
outside the print (or just print the expression).
So you could do it like this:


print (operand1 + operands2)   # print() evaluates and prints result

or

result = operand1 + operand2
print(result)        # just print the stored value

> Traceback (most recent call last):
>    File "C:/Python34/Assignment3_DanielleSalaz.py", line 1, in <module>
>      print (operand1 = 2)
> TypeError: 'operand1' is an invalid keyword argument for this function

See the comments above.

Its possible you have seen code that looks like this before but
that is due to a slightly confusing feature of Python.

Python functions have parameters. Some parameters have default
values so you don't always need to supply them. If you want to change 
one of these default values you can do it by assigning a value in the 
function call. But that is the only kind of assignment you are allowed 
to do, it must be to one of the functions defaulted parameters.

In this case the print function does not have a default parameter called 
operand1 so you cannot do an assignment to operand1 inside
the print function call. So although you might see code like

print(x,y,sep='-')

the sep assignment is a special operation specific to the print function
you cannot assign arbitrary values to arbitrary names inside the 
function. This is true of any function, not just print().

If you didn't understand those last 4 paragraphs don't worry, you
will get to it later in your course and all will become clear,
I hope. They were written on the assumption that you are coming
to python from another language such as Lisp...


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From oguzhanogreden at gmail.com  Sun Jul 13 13:23:52 2014
From: oguzhanogreden at gmail.com (=?UTF-8?B?T8SfdXpoYW4gw5bEn3JlZGVu?=)
Date: Sun, 13 Jul 2014 13:23:52 +0200
Subject: [Tutor] While Loop and Threads
Message-ID: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>

Hi,

I've been practicing with multithreading and gtk for a while and recently
have observed something I can't quite grasp.

This is basically a timer with a settings window and a countdown window
which is produced after setting_window passes necessary arguments to thread.

I have a while loop which counts time, inside the thread, while variable
"runner" is True, which looks like this:

    def run(self):
        cycle = ['work', 'break', 'long_break']
        cycle = cycle[:2]*self.workn+cycle[3]
        self.runner = True
        sec_count = timedelta(seconds=1)

        while self.runner == True:
            for i in cycle:
                self.setState(i)
                print('Start:', i, datetime.now())

                while self.end_time > datetime.now():
                    time.sleep(1)
                    self.duration -= sec_count

                self.count[self.state] += 1

And I want countdown to stop when countdown_window receives delete event,
thus I have a countdown_window.stop() function which is defined as follows:

def stop(self, *args):
        pom.count[pom.state] -= 1
        pom.runner = False # refers to the runner of the thread.
        print(pom.runner) # prints False,
        Gtk.main_quit()

What I expect to happen is that while loop to break, but it does not.

Any suggestions?

Best,
O?uzhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140713/b9678fc5/attachment.html>

From idiallo.spsu at gmail.com  Sun Jul 13 18:16:16 2014
From: idiallo.spsu at gmail.com (idiallo.spsu at gmail.com)
Date: Sun, 13 Jul 2014 12:16:16 -0400
Subject: [Tutor] Python 2 Vs python 3
Message-ID: <20140713161616.6082706.98601.1277@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140713/573c79fe/attachment.html>

From dyoo at hashcollision.org  Sun Jul 13 19:41:43 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 13 Jul 2014 10:41:43 -0700
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
 <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>
 <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>
Message-ID: <CAGZAPF5wyNsmZsf8hWD2h6H+0K6xMSqHhyykLH57n9Rakr+OLQ@mail.gmail.com>

On Sun, Jul 13, 2014 at 12:25 AM, Danielle Salaz <danieshari at gmail.com> wrote:
> This is what I've been doing, also I'm using version 3.4
>
> set "(operand1 = 2 and operand2 = 7)
> print (operand1 = 2)
> print (operand2 = 7)
> print (result=operand1 + operand2)
> print (result=operand2 - operand1)
> print (result=operand2 * operand1)
> print (result=operand2 / operand1)
> print (result=operand2 % operand1)


Beyond what Alan has said, also please also also say what you expected
to happen if the program were to run without error.

I mentioned this earlier in a prior reply in this thread, and I still
stick by the recommendation.  We want to help troubleshoot any
misconceptions as early as possible, and knowing intent is helpful.

Since you are a beginner, try to explain each line and the overall
program goal if possible.  It will help us understand what programming
model you've got in your head.  For example, can you explain what the
first three lines of your program are intended to do?

From joel.goldstick at gmail.com  Sun Jul 13 19:50:44 2014
From: joel.goldstick at gmail.com (Joel Goldstick)
Date: Sun, 13 Jul 2014 13:50:44 -0400
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <20140713161616.6082706.98601.1277@gmail.com>
References: <20140713161616.6082706.98601.1277@gmail.com>
Message-ID: <CAPM-O+wr5FgBcCOUuzpv6mAZDeh_-rqRZwhy0QB-7GeXtsN_Xg@mail.gmail.com>

On Sun, Jul 13, 2014 at 12:16 PM,  <idiallo.spsu at gmail.com> wrote:
> ?Hi All,
>
> I am in the process to dive into python and start learning it. But most
> books advice to install python 2 instead of ?python 3. Any advice from the
> ones with the experiences and what is the main difference?

Many people advise using  3.x if you are totally new to python.  The
downside to python 3.x is that some 3rd party modules and packages are
not available.  That shouldn't matter to a new learner.  On the other
hand, if you find a tutorial that uses 2.7 and you like the tutorial,
you might want to stay there.  There is a lot of python 2.x code
running, and its not going away anytime soon.

I haven't tried python 3.x yet.  The two differences that get talked
about most are 'print' is a statement in 2.x and a function in 3.x.
Unicode support was reworked in 3.x and so if you are working with
non-english characters, you might lean to using 3.x
>
> Thanks,
>
> I.
>
> Sent from my BlackBerry 10 smartphone.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
http://joelgoldstick.com

From steve at pearwood.info  Sun Jul 13 19:55:29 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Mon, 14 Jul 2014 03:55:29 +1000
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <20140713161616.6082706.98601.1277@gmail.com>
References: <20140713161616.6082706.98601.1277@gmail.com>
Message-ID: <20140713175529.GQ5705@ando>

On Sun, Jul 13, 2014 at 12:16:16PM -0400, idiallo.spsu at gmail.com wrote:
>    ?Hi All,
>    I am in the process to dive into python and start learning it. But most
>    books advice to install python 2 instead of ?python 3. Any advice from
>    the ones with the experiences and what is the main difference?

If you have a book that teaches Python 3, use Python 3. If it teaches 
Python 2, use Python 2.

If you have a choice, and you know that your aim is to use some specific 
library that only works with Python 2, then use Python 2. Otherwise, if 
you're learning the language with no fixed plans, then Python 3 is 
better.

The main differences include:

- some of the standard libraries have been moved or renamed;

- strings are Unicode text instead of 8-bit bytes;

- a couple of minor syntax differences (e.g. "print" is a 
  statement in Python 2, a function in Python 3);

- Python 2.7 is the last of the 2 series and will have no 
  new features, while Python 3 is in active improvement.


Don't feel bad about using Python 2 if you must. Version 2.7 will be 
supported until at least 2020, so you will have plenty of time to 
upgrade in the future. But Python 3 really is better.



-- 
Steven

From alan.gauld at btinternet.com  Sun Jul 13 21:33:27 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 13 Jul 2014 20:33:27 +0100
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <CAPM-O+wr5FgBcCOUuzpv6mAZDeh_-rqRZwhy0QB-7GeXtsN_Xg@mail.gmail.com>
References: <20140713161616.6082706.98601.1277@gmail.com>
 <CAPM-O+wr5FgBcCOUuzpv6mAZDeh_-rqRZwhy0QB-7GeXtsN_Xg@mail.gmail.com>
Message-ID: <lpumu8$ps8$1@ger.gmane.org>

On 13/07/14 18:50, Joel Goldstick wrote:

> I haven't tried python 3.x yet.  The two differences that get talked
> about most are 'print' is a statement in 2.x and a function in 3.x.
> Unicode support was reworked in 3.x and so if you are working with
> non-english characters, you might lean to using 3.x

I've been using python 3 almost exclusively for the last 4 months and 
the differences are much more significant than the headlines suggest.
In particular the module structure and naming is very different - enough 
to confuse a beginner using a Python2 tutor for sure.

But there are a lot of subtle changes under the hood - extra
options in functions for example. After about a month I gave up on my 
intention to create dual version code - it was just too much work.

So 6 months ago I thought it didn't make much difference. Now I think 
its quite a big decision. If you can I'd say go with python 3. All the 
biggest libraries now have v3 support or alternatives exist.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From breamoreboy at yahoo.co.uk  Sun Jul 13 21:55:28 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sun, 13 Jul 2014 20:55:28 +0100
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <lpumu8$ps8$1@ger.gmane.org>
References: <20140713161616.6082706.98601.1277@gmail.com>
 <CAPM-O+wr5FgBcCOUuzpv6mAZDeh_-rqRZwhy0QB-7GeXtsN_Xg@mail.gmail.com>
 <lpumu8$ps8$1@ger.gmane.org>
Message-ID: <lpuo7e$77f$1@ger.gmane.org>

On 13/07/2014 20:33, Alan Gauld wrote:
>
> But there are a lot of subtle changes under the hood - extra
> options in functions for example. After about a month I gave up on my
> intention to create dual version code - it was just too much work.
>

FTR tools that are meant to ease the pain.  I've never used them myself 
so can't make recommendations.

https://pypi.python.org/pypi/six/1.7.3
https://github.com/mitsuhiko/python-modernize
http://python-future.org/
https://github.com/nandoflorestan/nine

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From joseph.lee22590 at gmail.com  Sun Jul 13 19:52:41 2014
From: joseph.lee22590 at gmail.com (Joseph Lee)
Date: Sun, 13 Jul 2014 10:52:41 -0700
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <20140713161616.6082706.98601.1277@gmail.com>
References: <20140713161616.6082706.98601.1277@gmail.com>
Message-ID: <007401cf9ec3$3f537880$bdfa6980$@gmail.com>

Hi,

Answers are below.

 

From: Tutor [mailto:tutor-bounces+joseph.lee22590=gmail.com at python.org] On Behalf Of idiallo.spsu at gmail.com
Sent: Sunday, July 13, 2014 9:16 AM
To: Python Tutor Mailing List
Subject: [Tutor] Python 2 Vs python 3

 

I am in the process to dive into python and start learning it. But most books advice to install python 2 instead of ?python 3. Any advice from the ones with the experiences and what is the main difference? 

 

JL: Python 2 and 3 series are backwards incompatible. For instance, whereas in Python 2, you can do something like:

print ?hello?

In Python 3, you need to use:

print(?hello?)

There are other differences, including different division strategies, no more old objects and so on. Major concepts are same in Python 2 and 3, such as classes, exceptions and so on.

Many books recommend Python 2 because some popular libraries such as WXPython has not been ported to Python 3 yet, and Python Foundation announced that they are committed to releasing new 2.7.x series for those who would like to stay in Python 2 for a while (they just released 2.7.8 a few days ago). Once you?re comfortable with 2, using 3 isn?t hard (there are syntax differences you need to be aware of). These days, many libraries and projects are written with both Python 2 and 3 in mind for ease of porting to Python 3 in case Python 3 becomes more popular (not for now). There are also modules such as 2to3 which will try its best to convert Python 2 code to Python 3 with hand-written corrections required in the end.

You can install both Python 2 and 3 on the same computer (I have this setup under Cygwin). I myself speak Python 2 for now due to requirements for a project that I?m involved with.

Hope this helps.

Cheers,

Joseph

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140713/e6ada42b/attachment.html>

From audreyr at gmail.com  Mon Jul 14 02:01:03 2014
From: audreyr at gmail.com (Audrey M Roy)
Date: Sun, 13 Jul 2014 20:01:03 -0400
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <20140712024311.GE5705@ando>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
 <20140711151334.GC5705@ando>
 <CAM0KdEWmarJdtCm1Rxso9GdR=afbaoc3c+gPWDwKXEg3XsHTVQ@mail.gmail.com>
 <20140712024311.GE5705@ando>
Message-ID: <CAM0KdEUoN4Z7dT0Jxrzz8XfaXxbnK81qsx8K2VP20u6EUMRSEw@mail.gmail.com>

On Fri, Jul 11, 2014 at 10:43 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Fri, Jul 11, 2014 at 01:04:59PM -0700, Audrey M Roy wrote:
>> Steven, any chance you could clarify how to interpret that section? I'm
>> assuming it refers to not importing objects that share state across modules?
>
> Importing objects that share state across modules was not the problem
> I was talking about. Let's have two imaginary modules, spam and eggs:
>
> # spam.py
> x = 23
>
>
> # eggs.py
> from spam import x
>
>
> This is perfectly clean: the eggs module reaches into the spam module,
> grabs the current value of x (23), and sticks that value into itself.
> What it's doing may be more clear if we re-write eggs.py in a slightly
> longer way:
>
> import spam
> x = spam.x
> del spam

This was the piece of information that was missing in my head. Thank you. At
first I was surprised to learn that x was rebound in the local namespace. I had
always assumed it worked differently, as some sort of special reference to
the original object rather than a copy.

I tried out several examples locally and played around with "from...import" in
various scenarios. I understand it better now.

If anyone else reading this is struggling to understand "from...import" and
wants my code examples to try out, let me know and I can share them
somewhere. It's just too much code to paste here.

> The common pattern, where you import a function or a class or a
> constant, and it never gets mutated or rebound, is perfectly fine. But
> there are odd gotchas to "from ... import" that may be surprising.
> That's why I think one needs to be cautious about doing "from ...
> import". You need to think about it: are you sharing an object, where
> modifications to the object will be seen across multiple modules? Is it
> intended as a variable or a constant? If you don't think about it, one
> day you'll be bitten.

With this in mind, is the uncommon pattern of using "from...import" to create
a reference to a mutable object in the current namespace okay to use in
some cases?
Or is it bad practice?
I'm not sure whether to think of it as an occasionally-useful feature or as an
avoid-at-all-costs hack.

Steven, thanks so much, this really helped.

Audrey

From steve at pearwood.info  Mon Jul 14 03:21:35 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Mon, 14 Jul 2014 11:21:35 +1000
Subject: [Tutor] Anti-Patterns in Python Programming
In-Reply-To: <CAM0KdEUoN4Z7dT0Jxrzz8XfaXxbnK81qsx8K2VP20u6EUMRSEw@mail.gmail.com>
References: <1405015617.4078.BPMail_high_noncarrier@web163805.mail.gq1.yahoo.com>
 <lpmo81$ja6$1@ger.gmane.org> <lpoolm$bg0$1@ger.gmane.org>
 <1405089569.13227.YahooMailNeo@web163804.mail.gq1.yahoo.com>
 <20140711151334.GC5705@ando>
 <CAM0KdEWmarJdtCm1Rxso9GdR=afbaoc3c+gPWDwKXEg3XsHTVQ@mail.gmail.com>
 <20140712024311.GE5705@ando>
 <CAM0KdEUoN4Z7dT0Jxrzz8XfaXxbnK81qsx8K2VP20u6EUMRSEw@mail.gmail.com>
Message-ID: <20140714012135.GR5705@ando>

On Sun, Jul 13, 2014 at 08:01:03PM -0400, Audrey M Roy wrote:

[...]
> > This is perfectly clean: the eggs module reaches into the spam module,
> > grabs the current value of x (23), and sticks that value into itself.
> > What it's doing may be more clear if we re-write eggs.py in a slightly
> > longer way:
> >
> > import spam
> > x = spam.x
> > del spam
> 
> This was the piece of information that was missing in my head. Thank you. At
> first I was surprised to learn that x was rebound in the local namespace. I had
> always assumed it worked differently, as some sort of special reference to
> the original object rather than a copy.

Yes! That's *exactly* the issue that can cause confusion.


> With this in mind, is the uncommon pattern of using "from...import" to create
> a reference to a mutable object in the current namespace okay to use in
> some cases?
> Or is it bad practice?
> I'm not sure whether to think of it as an occasionally-useful feature or as an
> avoid-at-all-costs hack.

You mean something like this?

# === shared.py ===
data = ['stuff', 'goes', 'here']

# === a.py ===
from shared import data
data.insert(0, 'more')

# === b.py ===
from shared import data
# result of this next line depends on whether a or b runs first
print(data[0] == 'more')



What you're doing here is effectively creating a global variable which 
is shared across multiple modules, instead of safely confined to a 
single module. So long as you only mutate data, and not re-assign it, 
all the other modules will see the same changes.

That makes it occassionally useful, but more often you should avoid this 
as an example of "global variables considered harmful".

(If anyone is unsure about why global variables should be avoided, 
please ask.)

If I really needed this, I'd rather do `import shared` and then refer to 
`shared.data`. That way, it is obvious that you're accessing an external 
object, and you're not limited to mutation methods, you can re-bind the 
value as well:

shared.data = 42

But I stress that, apart from a few exceptions such as application-wide 
config options, relying on global variables is usually a bad idea.



-- 
Steven

From ugajin at talktalk.net  Mon Jul 14 18:13:33 2014
From: ugajin at talktalk.net (ugajin at talktalk.net)
Date: Mon, 14 Jul 2014 12:13:33 -0400
Subject: [Tutor] name error
Message-ID: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>

I am running nodebox 1 on OSX v10.6.8, which is an open source OSX 
Python, 2D data visualiser, and although not legacy, the software it 
isn't well supported. (see http://nodebox.net/code/index.php/Home for 
further info).? I believe nodebox 1, runs with Python 2.5?
?
This may be too specialised a question for the tutor forum, but . . .  
I have posted several e-mails to the nodebox author the first of which 
was almost 3 weeks ago, and although I received an initial  positive 
response, saying he would provide a screen cast to help,  the said 
screencast has not arrived. After, I sent a polite reminder, I received 
a curt if incomplete reply telling me he was now on holiday.?
?
Sometimes it can help, to describe a problem to a 3rd person (real or 
imagined), so here goes (it may have helped a bit, but not enough).?
?
To draw a default rectangle using the nodebox 1, IDE you would simply 
write: rect(0, 0, 100, 100) to a .py file.  When run in nodebox 1, IDE 
it does what you might expect. It renders a 100 x 100 (px) rectangle 
shape, with the top left vertex at the canvas x, y coordinate 0, 0?
?
However, when I try to call the .py file as a module (using the nodebox 
IDE) which is what I am trying to acheive, I get a traceback error 
message e.g.?
# import_test_1.py?
rect(0, 0, 100, 100)?
?
#importer_test_1.py?
import_test_1?
Traceback (most recent call last):?
?File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript?
? File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
2, in &lt;module&gt;?
? File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
line 22, in &lt;module&gt;?
NameError: name 'rect' is not defined?
?
This begins to look like a scope issue.?
?
However, when I execute/run the following command, I get the following 
output?
# import_test_2.py?
print 'dir:', dir()?
?
dir: ['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
'CORNER', 'CURVETO', 'Canvas', 'ClippingPath', 'Color', 'Context', 
'DEFAULT_HEIGHT', 'DEFAULT_WIDTH', 'FORTYFIVE', 'FRAME', 'Grob', 
'HEIGHT', 'HSB', 'Image', 'JUSTIFY', 'KEY_BACKSPACE', 'KEY_DOWN', 
'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 
'MOUSEY', 'MOVETO', 'NORMAL', 'NUMBER', 'NodeBoxError', 'Oval', 
'PAGENUM', 'PathElement', 'Point', 'RGB', 'RIGHT', 'Rect', 'TEXT', 
'Text', 'Transform', 'Variable', 'WIDTH', '__builtins__', '__class__', 
'__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', 
'__init__', '__magic_var__', '__module__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 
'_align', '_arrow', '_arrow45', '_autoclosepath', '_colormode', 
'_colorrange', '_copy_attr', '_copy_attrs', '_ctx', '_fillcolor', 
'_fontname', '_fontsize', '_get_height', '_get_width', '_imagecache', 
'_lineheight', '_makeInstance', '_noImagesHint', '_ns', '_oldvars', 
'_outputmode', '_path', '_resetContext', '_strokecolor', 
'_strokewidth', '_transform', '_transformmode', '_transformstack', 
'_vars', 'addvar', 'align', 'arrow', 'autoclosepath', 'autotext', 
'background', 'beginclip', 'beginpath', 'canvas', 'choice', 
'closepath', 'cm', 'color', 'colormode', 'colorrange', 'curveto', 
'drawpath', 'endclip', 'endpath', 'files', 'fill', 'findpath', 
'findvar', 'font', 'fontsize', 'grid', 'image', 'imagesize', 'inch', 
'key', 'keycode', 'keydown', 'line', 'lineheight', 'lineto', 'mm', 
'mousedown', 'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 
'pop', 'push', 'random', 'rect', 'reset', 'rotate', 'save', 'scale', 
'scrollwheel', 'size', 'skew', 'speed', 'star', 'stroke', 
'strokewidth', 'text', 'textheight', 'textmetrics', 'textpath', 
'textwidth', 'transform', 'translate', 'var', 'wheeldelta', 'ximport']?
?
This seems to suggest (to me) that there is a class object named Rect 
in the default dir()?
I may not have the correct nomenclature here, is there as default IDE 
dir() module??
?
Also, when I execute or run the following command, I get:?
print 'dir(Rect):', dir(Rect)?
dir(Rect): ['__call__', '__class__', '__cmp__', '__delattr__', 
'__doc__', '__get__', '__getattribute__', '__hash__', '__init__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__str__', 'im_class', 'im_func', 'im_self']?
?
Now, I am not sure if this helps, but if I put those two lines of code 
into a file and call the module with the import command, I now get the 
following output::?
# importer_test_2?
import_test_2?
print 'dir:', dir()?
print 'dir(Rect):', dir(Rect)?
?
dir: ['__builtins__', '__doc__', '__file__', '__name__', 'draw_rect', 
'nodebox']?
?
dir(Rect):Traceback (most recent call last):?
?File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript?
? File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
2, in &lt;module&gt;?
? File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
line 18, in &lt;module&gt;?
NameError: name 'Rect' is not defined?

Perhaps someone wiser than me, can suggest an approach, or something 
that I might try??
?
Thanks in anticipation.?
?
-u?
?
After some further tests, with Rect, and some Traceback messages 
telling me that Rect(), which was located in DrawingPrimitives, was 
deprecated, I found some changes noted posted on GitHub. Those at v 
1.9.0 seem apposite (I am running v1.9.5):
for nodebox 1, v 1.9.7:
ellipse() is an alias for oval(). Path.ellipse() works as well.
Support for Line cap and line join styles. Use joinstyle() with MITER, 
ROUND or BEVEL and capstyle() with BUTT, ROUND or SQUARE. 
Path.joinstyle = MITER and Path.capstyle = BUTT works as well.
for v1.9.0:
NodeBox is now packaged: DrawingPrimitives is obsoleted in favor of 
nodebox.graphics.This also means you can work directly with the context:
?
After some further try it and see tests, I noted the following:
#nodebx_graphics.py
print 'dir(nodebox.graphics.BezierPath):', 
dir(nodebox.graphics.BezierPath)

dir(nodebox.graphics.BezierPath): ['__class__', '__delattr__', 
'__dict__', '__doc__', '__getattribute__', '__getitem__', '__hash__', 
'__init__', '__iter__', '__len__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
'__weakref__', '_draw', '_get_bounds', '_get_contours', '_get_fill', 
'_get_length', '_get_path', '_get_stroke', '_get_strokewidth', 
'_get_transform', '_get_transformmode', '_reset', '_set_fill', 
'_set_stroke', '_set_strokewidth', '_set_transform', 
'_set_transformmode', 'addpoint', 'append', 'bounds', 'checkKwargs', 
'closepath', 'contains', 'contours', 'copy', 'curveto', 'difference', 
'draw', 'extend', 'fill', 'fit', 'inheritFromContext', 'intersect', 
'intersects', 'kwargs', 'length', 'line', 'lineto', 'moveto', 'oval', 
'path', 'point', 'points', 'rect', 'reset', 'rotate', 'scale', 
'segmentlengths', 'setlinewidth', 'skew', 'stateAttributes', 'stroke', 
'strokewidth', 'transform', 'transformmode', 'translate', 'union', 
'xor']

Also, noted I can call the rect() function as follows:
#nodebx_graphics.py
import nodebox
nodebox.graphics.BezierPath(rect(0, 0, 100, 100))

However I still get a name error when I call it from another file, 
which is what I am trying to do:
#importer_nb_graphics
import nodebox_graphics

Traceback (most recent call last):
? File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
? File "/Users/apple/Documents/nodeBox/07_10_2014/importer_nb_1.py", 
line 2, in &lt;module&gt;
? File "/Users/apple/Documents/nodeBox/07_10_2014/nodebox_graphics.py", 
line 31, in &lt;module&gt;
NameError: name 'rect' is not defined

I note that now the name error applies to 'rect' not 'Rect'

As asked earlier, perhaps some Pythonistas here can suggest some 
further try it and see tests for me to try?

PS. While I am here perhaps someone can also suggest a plain text 
e-mail client, as I really dislike composing on mine in plain text. I 
lose scroll bars, and text sometimes half fills the editor window when 
saved as a draft draft, and re-opened.? Especially for you guys, I 
wrote this in HTML, saved it, changed my setting, re-opened it, before 
sending it.







  

From james at uplinkzero.com  Mon Jul 14 20:03:52 2014
From: james at uplinkzero.com (James Chapman)
Date: Mon, 14 Jul 2014 19:03:52 +0100
Subject: [Tutor] While Loop and Threads
In-Reply-To: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
References: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
Message-ID: <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>

Multi-threading takes practice!

Are you using an event object to signal the thread should exit? I'm
guessing you're just using a bool which is why it does not work.

See: https://docs.python.org/3.4/library/threading.html#event-objects

I'm very short on time and the moment and therefore can't mock up a working
example. If I have time later/tomorrow and you haven't solved it or no one
else has commented I'll try and put something together.

IMO, move away from GTK until you get threading working as expected, then
add the additional layer. Solve one problem at a time.

James

--
James


On 13 July 2014 12:23, O?uzhan ??reden <oguzhanogreden at gmail.com> wrote:

> Hi,
>
> I've been practicing with multithreading and gtk for a while and recently
> have observed something I can't quite grasp.
>
> This is basically a timer with a settings window and a countdown window
> which is produced after setting_window passes necessary arguments to thread.
>
> I have a while loop which counts time, inside the thread, while variable
> "runner" is True, which looks like this:
>
>     def run(self):
>         cycle = ['work', 'break', 'long_break']
>         cycle = cycle[:2]*self.workn+cycle[3]
>         self.runner = True
>         sec_count = timedelta(seconds=1)
>
>         while self.runner == True:
>             for i in cycle:
>                 self.setState(i)
>                 print('Start:', i, datetime.now())
>
>                 while self.end_time > datetime.now():
>                     time.sleep(1)
>                     self.duration -= sec_count
>
>                 self.count[self.state] += 1
>
> And I want countdown to stop when countdown_window receives delete event,
> thus I have a countdown_window.stop() function which is defined as follows:
>
> def stop(self, *args):
>         pom.count[pom.state] -= 1
>         pom.runner = False # refers to the runner of the thread.
>         print(pom.runner) # prints False,
>         Gtk.main_quit()
>
> What I expect to happen is that while loop to break, but it does not.
>
> Any suggestions?
>
> Best,
> O?uzhan
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140714/9b86bc27/attachment.html>

From alan.gauld at btinternet.com  Mon Jul 14 20:18:14 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 14 Jul 2014 19:18:14 +0100
Subject: [Tutor] name error
In-Reply-To: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>
References: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>
Message-ID: <lq16t6$p0c$1@ger.gmane.org>

On 14/07/14 17:13, ugajin at talktalk.net wrote:
> I am running nodebox 1 on OSX v10.6.8, which is an open source OSX
> Python, 2D data visualiser,

I can't help with the actual query, sorry.
But are you tied to nodebox for a reason? There are other 2D packages 
around, maybe a different package (with better support) would help?

> PS. While I am here perhaps someone can also suggest a plain text e-mail
> client, as I really dislike composing on mine in plain text. I lose
> scroll bars, and text sometimes half fills the editor window when saved
> as a draft draft, and re-opened.

Weird, what tool are you using?
Also which OS?

FWIW I use Thunderbird which runs on most OS...
But I've also used Apple Mail and Microsoft Outlook/Outlook Express
and all have been OK for producing plain text. If you use IMAP you 
should be able to share your mail between multiple clients...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From james at uplinkzero.com  Mon Jul 14 20:24:22 2014
From: james at uplinkzero.com (James Chapman)
Date: Mon, 14 Jul 2014 19:24:22 +0100
Subject: [Tutor] While Loop and Threads
In-Reply-To: <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>
References: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
 <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>
Message-ID: <CAHvkzynzJLxrjigZoAXqqzhOqafR-121aiT-TXW8b0+HH+i3=Q@mail.gmail.com>

OK, so I mocked up an example now...



import time
import threading

g_threadStop = threading.Event()

def threadWorker(_arg1, _arg2):
    print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
    while(not g_threadStop.is_set()):
        print("Thread running.")
        time.sleep(1)
    print("Thread exiting...")

def main():
    t = threading.Thread(target=threadWorker, args = ("arg1", "arg2"))
    t.start()
    print("Main thread sleeping for 10 seconds...")
    time.sleep(5)
    print("Main thread setting g_threadStop")
    g_threadStop.set()
    time.sleep(3)
    print("Main thread exiting...")

if __name__ == '__main__':
    main()





--
James


On 14 July 2014 19:03, James Chapman <james at uplinkzero.com> wrote:

> Multi-threading takes practice!
>
> Are you using an event object to signal the thread should exit? I'm
> guessing you're just using a bool which is why it does not work.
>
> See: https://docs.python.org/3.4/library/threading.html#event-objects
>
> I'm very short on time and the moment and therefore can't mock up a
> working example. If I have time later/tomorrow and you haven't solved it or
> no one else has commented I'll try and put something together.
>
> IMO, move away from GTK until you get threading working as expected, then
> add the additional layer. Solve one problem at a time.
>
> James
>
> --
> James
>
>
> On 13 July 2014 12:23, O?uzhan ??reden <oguzhanogreden at gmail.com> wrote:
>
>> Hi,
>>
>> I've been practicing with multithreading and gtk for a while and recently
>> have observed something I can't quite grasp.
>>
>> This is basically a timer with a settings window and a countdown window
>> which is produced after setting_window passes necessary arguments to thread.
>>
>> I have a while loop which counts time, inside the thread, while variable
>> "runner" is True, which looks like this:
>>
>>     def run(self):
>>         cycle = ['work', 'break', 'long_break']
>>         cycle = cycle[:2]*self.workn+cycle[3]
>>         self.runner = True
>>         sec_count = timedelta(seconds=1)
>>
>>         while self.runner == True:
>>             for i in cycle:
>>                 self.setState(i)
>>                 print('Start:', i, datetime.now())
>>
>>                 while self.end_time > datetime.now():
>>                     time.sleep(1)
>>                     self.duration -= sec_count
>>
>>                 self.count[self.state] += 1
>>
>> And I want countdown to stop when countdown_window receives delete event,
>> thus I have a countdown_window.stop() function which is defined as follows:
>>
>> def stop(self, *args):
>>         pom.count[pom.state] -= 1
>>         pom.runner = False # refers to the runner of the thread.
>>         print(pom.runner) # prints False,
>>         Gtk.main_quit()
>>
>> What I expect to happen is that while loop to break, but it does not.
>>
>> Any suggestions?
>>
>> Best,
>> O?uzhan
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140714/20a2a2fc/attachment.html>

From breamoreboy at yahoo.co.uk  Mon Jul 14 21:51:24 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Mon, 14 Jul 2014 20:51:24 +0100
Subject: [Tutor] name error
In-Reply-To: <lq16t6$p0c$1@ger.gmane.org>
References: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>
 <lq16t6$p0c$1@ger.gmane.org>
Message-ID: <lq1cbe$sij$1@ger.gmane.org>

On 14/07/2014 19:18, Alan Gauld wrote:
> On 14/07/14 17:13, ugajin at talktalk.net wrote:
>> I am running nodebox 1 on OSX v10.6.8, which is an open source OSX
>> Python, 2D data visualiser,
>
> I can't help with the actual query, sorry.
> But are you tied to nodebox for a reason? There are other 2D packages
> around, maybe a different package (with better support) would help?

http://matplotlib.org/ would be very hard to beat.

>
>> PS. While I am here perhaps someone can also suggest a plain text e-mail
>> client, as I really dislike composing on mine in plain text. I lose
>> scroll bars, and text sometimes half fills the editor window when saved
>> as a draft draft, and re-opened.
>
> Weird, what tool are you using?
> Also which OS?
>
> FWIW I use Thunderbird which runs on most OS...
> But I've also used Apple Mail and Microsoft Outlook/Outlook Express
> and all have been OK for producing plain text. If you use IMAP you
> should be able to share your mail between multiple clients...
>

FWIW I also use Thunderbird on Windows.  The big plus to me is being 
able to read hundreds of mailing lists and blogs from news.gmane.org, 
and not just Python related ones.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From davea at davea.name  Mon Jul 14 23:03:12 2014
From: davea at davea.name (Dave Angel)
Date: Mon, 14 Jul 2014 16:03:12 -0500 (CDT)
Subject: [Tutor] name error
References: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>
Message-ID: <lq1gin$g64$1@ger.gmane.org>

ugajin at talktalk.net Wrote in message:
> I am running nodebox 1 on OSX v10.6.8, which is an open source OSX 
> Python, 2D data visualiser, and although not legacy, the software it 
> isn't well supported. (see http://nodebox.net/code/index.php/Home for 
> further info).  I believe nodebox 1, runs with Python 2.5 
>  
> This may be too specialised a question for the tutor forum, but . . .  
> I have posted several e-mails to the nodebox author the first of which 
> was almost 3 weeks ago, and although I received an initial  positive 
> response, saying he would provide a screen cast to help,  the said 
> screencast has not arrived. After, I sent a polite reminder, I received 
> a curt if incomplete reply telling me he was now on holiday. 
>  
> Sometimes it can help, to describe a problem to a 3rd person (real or 
> imagined), so here goes (it may have helped a bit, but not enough). 
>  
> To draw a default rectangle using the nodebox 1, IDE you would simply 
> write: rect(0, 0, 100, 100) to a .py file.  When run in nodebox 1, IDE 
> it does what you might expect. It renders a 100 x 100 (px) rectangle 
> shape, with the top left vertex at the canvas x, y coordinate 0, 0 
>  

Not being familiar with nodebox, I'm mostly guessing.  I presume
 that nodebox comes with an Integrated Development Environment
 (IDE) and that the environment is doing some import,  perhaps the
 dreaded 'from xxxxx import *x' where xxxxx is maybe 'nodebox.
 

Anyway,  whatever they're doing for your interactive environment
 is just confusing you for writing scripts and modules, where your
 imports must be explicit. 

> However, when I try to call the .py file as a module (using the nodebox 
> IDE) which is what I am trying to acheive, I get a traceback error 
> message e.g. 
> # import_test_1.py 
> rect(0, 0, 100, 100) 
>  
> #importer_test_1.py 
> import_test_1 
> Traceback (most recent call last): 
>  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript 
>   File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
> 2, in &lt;module&gt; 
>   File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
> line 22, in &lt;module&gt; 
> NameError: name 'rect' is not defined 
>  
> This begins to look like a scope issue. 

Sure you probably need
import nodebox
nodebox.rect (.....


>  
> However, when I execute/run the following command, I get the following 
> output 
> # import_test_2.py 
> print 'dir:', dir() 
>  
> dir: ['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
> 'CORNER', 'CURVETO', 'Canvas', 'ClippingPath', 'Color', 'Context', 
> 'DEFAULT_HEIGHT', 'DEFAULT_WIDTH', 'FORTYFIVE', 'FRAME', 'Grob', 
> 'HEIGHT', 'HSB', 'Image', 'JUSTIFY', 'KEY_BACKSPACE', 'KEY_DOWN', 
> 'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 
> 'MOUSEY', 'MOVETO', 'NORMAL', 'NUMBER', 'NodeBoxError', 'Oval', 
> 'PAGENUM', 'PathElement', 'Point', 'RGB', 'RIGHT', 'Rect', 'TEXT', 
> 'Text', 'Transform', 'Variable', 'WIDTH', '__builtins__', '__class__', 
> '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', 
> '__init__', '__magic_var__', '__module__', '__new__', '__reduce__', 
> '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 
> '_align', '_arrow', '_arrow45', '_autoclosepath', '_colormode', 
> '_colorrange', '_copy_attr', '_copy_attrs', '_ctx', '_fillcolor', 
> '_fontname', '_fontsize', '_get_height', '_get_width', '_imagecache', 
> '_lineheight', '_makeInstance', '_noImagesHint', '_ns', '_oldvars', 
> '_outputmode', '_path', '_resetContext', '_strokecolor', 
> '_strokewidth', '_transform', '_transformmode', '_transformstack', 
> '_vars', 'addvar', 'align', 'arrow', 'autoclosepath', 'autotext', 
> 'background', 'beginclip', 'beginpath', 'canvas', 'choice', 
> 'closepath', 'cm', 'color', 'colormode', 'colorrange', 'curveto', 
> 'drawpath', 'endclip', 'endpath', 'files', 'fill', 'findpath', 
> 'findvar', 'font', 'fontsize', 'grid', 'image', 'imagesize', 'inch', 
> 'key', 'keycode', 'keydown', 'line', 'lineheight', 'lineto', 'mm', 
> 'mousedown', 'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 
> 'pop', 'push', 'random', 'rect', 'reset', 'rotate', 'save', 'scale', 
> 'scrollwheel', 'size', 'skew', 'speed', 'star', 'stroke', 
> 'strokewidth', 'text', 'textheight', 'textmetrics', 'textpath', 
> 'textwidth', 'transform', 'translate', 'var', 'wheeldelta', 'ximport'] 
>  
> This seems to suggest (to me) that there is a class object named Rect 
> in the default dir() 
> I may not have the correct nomenclature here, is there as default IDE 
> dir() module? 

There are the builtins.  Anything beyond that is put there by your
 IDE. And I don't know how you get from the function rect to the
 class Rect.  Python is case sensitive. I'm not sure what you mea
 n by class obmject. Are you perhaps meaning class instance?
 

>  
> Also, when I execute or run the following command, I get: 
> print 'dir(Rect):', dir(Rect) 
> dir(Rect): ['__call__', '__class__', '__cmp__', '__delattr__', 
> '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', 
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
> '__str__', 'im_class', 'im_func', 'im_self'] 
>  
> Now, I am not sure if this helps, but if I put those two lines of code 
> into a file and call the module with the import command, I now get the 
> following output:: 
> # importer_test_2 
> import_test_2 

You should have gotten an error there, you presumably forgot the
 import keyword.  Or you pasted it wrong. 

> print 'dir:', dir() 
> print 'dir(Rect):', dir(Rect) 
>  
> dir: ['__builtins__', '__doc__', '__file__', '__name__', 'draw_rect', 
> 'nodebox'] 
>  
> dir(Rect):Traceback (most recent call last): 
>  File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript 
>   File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
> 2, in &lt;module&gt; 
>   File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
> line 18, in &lt;module&gt; 
> NameError: name 'Rect' is not defined 

Well you can see that dir () doesn't show Rect, so dir Rect won't work.
> 
> Perhaps someone wiser than me, can suggest an approach, or something 
> that I might try? 
>  
> Thanks in anticipation. 
>  
> -u 
>  
> After some further tests, with Rect, and some Traceback messages 
> telling me that Rect(), which was located in DrawingPrimitives, was 
> deprecated, I found some changes noted posted on GitHub. Those at v 
> 1.9.0 seem apposite (I am running v1.9.5):
> for nodebox 1, v 1.9.7:
> ellipse() is an alias for oval(). Path.ellipse() works as well.
> Support for Line cap and line join styles. Use joinstyle() with MITER, 
> ROUND or BEVEL and capstyle() with BUTT, ROUND or SQUARE. 
> Path.joinstyle = MITER and Path.capstyle = BUTT works as well.
> for v1.9.0:
> NodeBox is now packaged: DrawingPrimitives is obsoleted in favor of 
> nodebox.graphics.This also means you can work directly with the context:
>  
> After some further try it and see tests, I noted the following:
> #nodebx_graphics.py
> print 'dir(nodebox.graphics.BezierPath):', 
> dir(nodebox.graphics.BezierPath)

Can't happen.  Your IDE is messing you up big time.  

> 
> dir(nodebox.graphics.BezierPath): ['__class__', '__delattr__', 
> '__dict__', '__doc__', '__getattribute__', '__getitem__', '__hash__', 
> '__init__', '__iter__', '__len__', '__module__', '__new__', 
> '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', 
> '__weakref__', '_draw', '_get_bounds', '_get_contours', '_get_fill', 
> '_get_length', '_get_path', '_get_stroke', '_get_strokewidth', 
> '_get_transform', '_get_transformmode', '_reset', '_set_fill', 
> '_set_stroke', '_set_strokewidth', '_set_transform', 
> '_set_transformmode', 'addpoint', 'append', 'bounds', 'checkKwargs', 
> 'closepath', 'contains', 'contours', 'copy', 'curveto', 'difference', 
> 'draw', 'extend', 'fill', 'fit', 'inheritFromContext', 'intersect', 
> 'intersects', 'kwargs', 'length', 'line', 'lineto', 'moveto', 'oval', 
> 'path', 'point', 'points', 'rect', 'reset', 'rotate', 'scale', 
> 'segmentlengths', 'setlinewidth', 'skew', 'stateAttributes', 'stroke', 
> 'strokewidth', 'transform', 'transformmode', 'translate', 'union', 
> 'xor']
> 
> Also, noted I can call the rect() function as follows:
> #nodebx_graphics.py
> import nodebox
> nodebox.graphics.BezierPath(rect(0, 0, 100, 100))

Now at least you're showing an import.  But if that reference to
 rect works, your library is doing some serious hacking.  And only
 if it's thoroughly documented would I continue using
 it.

> 
> However I still get a name error when I call it from another file, 
> which is what I am trying to do:
> #importer_nb_graphics
> import nodebox_graphics
> 
> Traceback (most recent call last):
>   File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
>   File "/Users/apple/Documents/nodeBox/07_10_2014/importer_nb_1.py", 
> line 2, in &lt;module&gt;
>   File "/Users/apple/Documents/nodeBox/07_10_2014/nodebox_graphics.py", 
> line 31, in &lt;module&gt;
> NameError: name 'rect' is not defined
> 
> I note that now the name error applies to 'rect' not 'Rect'

Of course,  that's what you tried to use.

> 
> As asked earlier, perhaps some Pythonistas here can suggest some 
> further try it and see tests for me to try?
> 
> PS. While I am here perhaps someone can also suggest a plain text 
> e-mail client, as I really dislike composing on mine in plain text. I 
> lose scroll bars, and text sometimes half fills the editor window when 
> saved as a draft draft, and re-opened.  Especially for you guys, I 
> wrote this in HTML, saved it, changed my setting, re-opened it, before 
> sending it.
> 
> 
> 

If Window or Linux,  use Thunderbird.  I don't know if it runs on
 osx, but I expect it does. Not on Android though and I'm still
 hunting. 
> 
>
> 


-- 
DaveA


From steve at pearwood.info  Tue Jul 15 04:52:31 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Tue, 15 Jul 2014 12:52:31 +1000
Subject: [Tutor] name error
In-Reply-To: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>
References: <8D16D95ADB8671C-870-C3E2@webmail-vfrr08.sis.aol.com>
Message-ID: <20140715025231.GC9112@ando>

On Mon, Jul 14, 2014 at 12:13:33PM -0400, ugajin at talktalk.net wrote:

[...]
> To draw a default rectangle using the nodebox 1, IDE you would simply 
> write: rect(0, 0, 100, 100) to a .py file.  When run in nodebox 1, IDE 
> it does what you might expect. It renders a 100 x 100 (px) rectangle 
> shape, with the top left vertex at the canvas x, y coordinate 0, 0?

Can you confirm that it is spelled "rect" in lowercase, not Rect with an 
initial capital? I suspect that is actually wrong, and you need to spell 
it with a capital R.

Remember that Python is case-sensitive and that "rect", "Rect", "RECT", 
etc. are all considered different.


> However, when I try to call the .py file as a module (using the nodebox 
> IDE) which is what I am trying to acheive, I get a traceback error 
> message e.g.?
> # import_test_1.py?
> rect(0, 0, 100, 100)?

So you have a file called "import_test_1.py", correct? It contains just 
a single command, "rect(...)", correct?

I know nothing about nodebox, but my *guess* is that before calling 
rect, you might need to import the name:

from nodebox import rect  # or perhaps Rect
rect(0, 0, 100, 100)  # Rect?

Reading further along, I would try this:

from nodebox.graphics import Rect
Rect(0, 0, 100, 100)



> #importer_test_1.py?
> import_test_1?
> Traceback (most recent call last):?
> ?File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript?
> ? File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
> 2, in &lt;module&gt;?
> ? File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
> line 22, in &lt;module&gt;?
> NameError: name 'rect' is not defined?

The file names you show do not match the file names in the traceback:

- you give file names import_test_1.py and importer_test_1.py

- Python reports the file names are import_test_2.py and importer_2.py

So I think the code you are showing us is different from the code you 
are running.


> This begins to look like a scope issue.?

NameError is almost always either a scope issue or a misspelling issue.


> However, when I execute/run the following command, I get the following 
> output?
> # import_test_2.py?
> print 'dir:', dir()?
> ?
> dir: ['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
[snip long output]


> This seems to suggest (to me) that there is a class object named Rect 
> in the default dir()?

This hints that your earlier code needs to say

Rect(0, 0, 100, 100)

rather than lowercase "rect".


> I may not have the correct nomenclature here, is there as default IDE 
> dir() module??

dir(obj) inspects the argument "obj" and returns the names of any 
attributes, methods or functions in obj. With no argument, dir() does 
the same to the current namespace. Roughly speaking, you can consider 
"namespace" to be almost the same as "the current module", at least when 
running interactively at the top-level (not inside a class or function).

IDEs often add things to the top-level namespace without your knowledge, 
so it is possible that when running in the nodebox IDE, it does the 
equivalent of "from nodebox import *" before you start.


> Also, when I execute or run the following command, I get:?
> print 'dir(Rect):', dir(Rect)?
> dir(Rect): ['__call__', '__class__', '__cmp__', '__delattr__', 
> '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', 
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
> '__str__', 'im_class', 'im_func', 'im_self']?

Now you're looking at the methods and attributes provided by the Rect 
object, which isn't very interesting. More interesting would be:

print Rect
print Rect.__name__


which may help track down where it is coming from.

?
> Now, I am not sure if this helps, but if I put those two lines of code 
> into a file and call the module with the import command, I now get the 
> following output::?
> # importer_test_2?
> import_test_2?
> print 'dir:', dir()?
> print 'dir(Rect):', dir(Rect)?

That code cannot work, because "import_test_2" should give a NameError. 
I think you mean:

import test_2  # note the space, not underscore

Please, it is important that when asking questions about your code, 
DON'T retype them from memory, always copy and paste. Otherwise you 
waste our time trying to debug a problem in code A by reading code B, 
which may be critically different.


> dir: ['__builtins__', '__doc__', '__file__', '__name__', 'draw_rect', 
> 'nodebox']?

Where do draw_rect and nodebox come from? I suspect you may not be 
showing us all the code you are running. Either that, or the notebox IDE 
is importing things in the background without telling you. (This is why 
I dislike IDEs. You never know what they are doing.)

 ?
> dir(Rect):Traceback (most recent call last):?
> ?File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript?
> ? File "/Users/apple/Documents/nodeBox/07_10_2014/importer_2.py", line 
> 2, in &lt;module&gt;?
> ? File "/Users/apple/Documents/nodeBox/07_10_2014/import_test_2.py", 
> line 18, in &lt;module&gt;?
> NameError: name 'Rect' is not defined?

Try replacing "Rect" with "draw_rect". What happens?



> After some further tests, with Rect, and some Traceback messages 
> telling me that Rect(), 

The text you quote does not say that Rect is deprecated. It says 
DrawingPrimitives is deprecated and you should use graphics instead.


> which was located in DrawingPrimitives, was 
> deprecated, I found some changes noted posted on GitHub. Those at v 
> 1.9.0 seem apposite (I am running v1.9.5):
> for nodebox 1, v 1.9.7:
[...snip irrelevent information...]

You are running v1.9.5. The comment you quote is for 1.9.7. It is not 
relevent to you, or us.


> for v1.9.0:
> NodeBox is now packaged: DrawingPrimitives is obsoleted in favor of 
> nodebox.graphics.This also means you can work directly with the context:
> ?
> After some further try it and see tests, I noted the following:
> #nodebx_graphics.py
> print 'dir(nodebox.graphics.BezierPath):', 
> dir(nodebox.graphics.BezierPath)

I don't trust that this is the code you actually are running. I would 
expect that to give a NameError that nodebox is not defined.

Did you have a line

import nodebox

first, that you negected to show?


> Also, noted I can call the rect() function as follows:
> #nodebx_graphics.py
> import nodebox
> nodebox.graphics.BezierPath(rect(0, 0, 100, 100))

I do not expect that would work. I expect that you would have to write 
this:

import nodebox
nodebox.graphics.BezierPath.rect(0, 0, 100, 100)

or possibly:

import nodebox
nodebox.graphics.Rect(0, 0, 100, 100)



At this point, I'm going to stop. I've already spent well over 30 
minutes typing up this response, and I feel like I have got nowhere 
because I have no confidence that the code you show us is the code you 
ae actually running. Please, please please, in future, do not retype 
your code from memory, copy and paste it. I believe that many of the 
problems you are experiencing come from mistyping names, or failing to 
import, and that by telling us "this code works" when it doesn't 
actually work, you are just adding confusion.

Please try the suggestions I have made, and if you are still having 
problems, report back and we'll see what further assistence we can give.

Good luck!



-- 
Steven

From danieshari at gmail.com  Tue Jul 15 07:51:13 2014
From: danieshari at gmail.com (Danielle Salaz)
Date: Mon, 14 Jul 2014 22:51:13 -0700
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <CAGZAPF5wyNsmZsf8hWD2h6H+0K6xMSqHhyykLH57n9Rakr+OLQ@mail.gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
 <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>
 <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>
 <CAGZAPF5wyNsmZsf8hWD2h6H+0K6xMSqHhyykLH57n9Rakr+OLQ@mail.gmail.com>
Message-ID: <CAHx+wuA2ggTwsX4P9wKGqfzJOA=rjfgtFdPJi1k8V1fhX=_yCQ@mail.gmail.com>

This is the assignment:

Write a Python script as follows:



Use 3 variables named:

   operand1

   operand2

   result

Set operand1 = 2 and operand2 = 7.



Evaluate the following expressions and produce the output as shown:

   result = operand1 + operand2

   result = operand2 ? operand1

   result = operand2 * operand1

   result = operand2 / operand1

   result = operand2 % operand1



Your output should look like:



   operand1 = 2

   operand2 = 7

   2 + 7 = 9

   7 ? 2 = 5

   7 * 2 = 14

    etc.


I am using Python 3.4 and my OS is Windows 7 Ultimate.
Thank you everyone for all of your help


On Sun, Jul 13, 2014 at 10:41 AM, Danny Yoo <dyoo at hashcollision.org> wrote:

> On Sun, Jul 13, 2014 at 12:25 AM, Danielle Salaz <danieshari at gmail.com>
> wrote:
> > This is what I've been doing, also I'm using version 3.4
> >
> > set "(operand1 = 2 and operand2 = 7)
> > print (operand1 = 2)
> > print (operand2 = 7)
> > print (result=operand1 + operand2)
> > print (result=operand2 - operand1)
> > print (result=operand2 * operand1)
> > print (result=operand2 / operand1)
> > print (result=operand2 % operand1)
>
>
> Beyond what Alan has said, also please also also say what you expected
> to happen if the program were to run without error.
>
> I mentioned this earlier in a prior reply in this thread, and I still
> stick by the recommendation.  We want to help troubleshoot any
> misconceptions as early as possible, and knowing intent is helpful.
>
> Since you are a beginner, try to explain each line and the overall
> program goal if possible.  It will help us understand what programming
> model you've got in your head.  For example, can you explain what the
> first three lines of your program are intended to do?
>



-- 
Thank you,
Danielle Salaz
Signature Financial Services, Inc.
21 W. Laurel Dr. #47, Salinas, Ca. 93906
(831) 754-0600

Your perception has everything to do with your progression!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140714/459d3aa7/attachment.html>

From jdcast at stanford.edu  Tue Jul 15 03:17:44 2014
From: jdcast at stanford.edu (John Cast)
Date: Mon, 14 Jul 2014 18:17:44 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
Message-ID: <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>

Hey everyone,

I really appreciate all of the help you given me.
I am making progress, however I have reached a problem I'm not sure how
best to tackle and would like someone with more experience with excel and
python to lend their knowledge/opinion before I dive in further.

I have two questions:
1) I'd like to be able to do a 'save-as web page' in python for my excel
workbook.  I tried this by hand and everything looks good EXCEPT that the
header cells sometimes were too narrow (because the person who created the
workbook didn't expand out each column enough sometimes) and thus blocked
some of the text in them occasionally.
Is it possible to do a 'save-as web page' for the workbook in python?

2)  So (assuming I can do this 'save-as webpage' in code) I need to go
through each sheet in the workbook and change each column's width so that
it can hold all of its text.  I realize that xlrd is for reading and xlwt
is for writing and there is xutils for particular combinations of both
reading and writing.  However, nothing to do quite what I've stated as far
as I can tell (so far).  I currently open the workbook I want to modify
using the open_workbook functionality in the xlrd module.  As I understand
it I need the xlwt module to write to this workbook, but since it's opened
in xlrd do I just open the same workbook in xlwt again?  If so does each
module simply have a handle to the same file?

NOTE: I'm basically just trying to present my excel workbook on the web as
it's shown in excel (retaining as much formatting as possible).

Thanks again,
John


On Sat, Jul 12, 2014 at 4:32 PM, Danny Yoo <dyoo at hashcollision.org> wrote:

> Hi Chris,
>
> Yikes.  I need to say that as, for disclosure: I work at Google.  I do
> not work on the App Engine team, but I need to acknowledge my
> potential conflict-of-interest, and I apologize for not stating this
> in my reply.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140714/a3856e67/attachment-0001.html>

From wescpy at gmail.com  Tue Jul 15 08:47:09 2014
From: wescpy at gmail.com (wesley chun)
Date: Mon, 14 Jul 2014 23:47:09 -0700
Subject: [Tutor] how do I set variables in Python 3.4
In-Reply-To: <CAHx+wuA2ggTwsX4P9wKGqfzJOA=rjfgtFdPJi1k8V1fhX=_yCQ@mail.gmail.com>
References: <9C055044-E031-4A20-989A-937FC5AC5484@gmail.com>
 <530CFBD2-A443-48A9-9F89-8C29D1AAE6EB@mac.com>
 <D1433EEF-B59E-4B79-8E4B-C4FC2EE97AA0@gmail.com>
 <CAGZAPF5wyNsmZsf8hWD2h6H+0K6xMSqHhyykLH57n9Rakr+OLQ@mail.gmail.com>
 <CAHx+wuA2ggTwsX4P9wKGqfzJOA=rjfgtFdPJi1k8V1fhX=_yCQ@mail.gmail.com>
Message-ID: <CAB6eaA660YZkRA1vDs1vs-D1LNiRhiUJHdg_SJcqLTbm6OPhGg@mail.gmail.com>

Greetings Danielle,

Welcome to programming! Thanks for the additional clarification as to what
your project is. Starting from scratch isn't easy, but with a little bit of
guidance, you'll soon be able to "drive on your own!"

In the course you're taking, can you share a bit about what resources your
instructor has provided you? Is there a book or an online website that
you're using? From looking at the code you've created, it seems that you're
trying to just take the requirements and hoping that it matches with the
languages syntax. Because it does *not*, the Python interpreter cannot
figure out what you're trying to do.

The solution is to learn the language that the Python interpreter is
"speaking," and converse in that language to help you meet your goal. For
example, the book or website that you're using should be indicating that
when the requirement is: "Set operand1 = 2 and operand2 = 7," this does not
mean that 'set "(operand1 = 2 and operand2 = 7)"' is what you would do in
Python.

The reading should have told you that "set" is not a keyword in Python.
Instead, you would think, "I need to set these variables... how do I do
that?" In your study guide, you would then find something like: "In order
to assign a value to a variable in Python, for example, to assign the
integer 10 to the variable 'x', the correct syntax is: x = 10". You then
bring that back to your example and do something similar: "operand1 = 2".

In fact, all of us here on the mailing list would go a step further and ask
you to experiment, like set the variable and then display it, and to
cut-n-paste the output here so we can confirm you know how to do it, and
that it works:

>>> operand1 = 2
>>> print(operand1)
2
>>> print(1 + operand1)
3

Once you've gained some confidence, you can then do the same for operand2,
and after this, go back to your learning resource and learn how to add,
subtract, etc. The best part is that you only have to learn these steps
once. The rules don't change for this aspect of programming in Python, and
you can then go ahead and complete your assignment. The most important
thing is to reference your learning resource and not to guess based on the
requirements in the assignment. Check out all the examples and model your
solution after them.

Best of luck!
--Wesley


On Mon, Jul 14, 2014 at 10:51 PM, Danielle Salaz <danieshari at gmail.com>
wrote:

> This is the assignment:
>
> Write a Python script as follows:
>
>
>
> Use 3 variables named:
>
>    operand1
>
>    operand2
>
>    result
>
> Set operand1 = 2 and operand2 = 7.
>
>
>
> Evaluate the following expressions and produce the output as shown:
>
>    result = operand1 + operand2
>
>    result = operand2 ? operand1
>
>    result = operand2 * operand1
>
>    result = operand2 / operand1
>
>    result = operand2 % operand1
>
>
>
> Your output should look like:
>
>
>
>    operand1 = 2
>
>    operand2 = 7
>
>    2 + 7 = 9
>
>    7 ? 2 = 5
>
>    7 * 2 = 14
>
>     etc.
>
>
> I am using Python 3.4 and my OS is Windows 7 Ultimate.
> Thank you everyone for all of your help
>
>
> On Sun, Jul 13, 2014 at 10:41 AM, Danny Yoo <dyoo at hashcollision.org>
> wrote:
>
>> On Sun, Jul 13, 2014 at 12:25 AM, Danielle Salaz <danieshari at gmail.com>
>> wrote:
>> > This is what I've been doing, also I'm using version 3.4
>> >
>> > set "(operand1 = 2 and operand2 = 7)
>> > print (operand1 = 2)
>> > print (operand2 = 7)
>> > print (result=operand1 + operand2)
>> > print (result=operand2 - operand1)
>> > print (result=operand2 * operand1)
>> > print (result=operand2 / operand1)
>> > print (result=operand2 % operand1)
>>
>>
>> Beyond what Alan has said, also please also also say what you expected
>> to happen if the program were to run without error.
>>
>> I mentioned this earlier in a prior reply in this thread, and I still
>> stick by the recommendation.  We want to help troubleshoot any
>> misconceptions as early as possible, and knowing intent is helpful.
>>
>> Since you are a beginner, try to explain each line and the overall
>> program goal if possible.  It will help us understand what programming
>> model you've got in your head.  For example, can you explain what the
>> first three lines of your program are intended to do?
>>
>
>
>
> --
> Thank you,
> Danielle Salaz
> Signature Financial Services, Inc.
> 21 W. Laurel Dr. #47, Salinas, Ca. 93906
> (831) 754-0600
>
> Your perception has everything to do with your progression!!
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    +wesley chun <http://google.com/+WesleyChun> : wescpy at gmail : @wescpy
<http://twitter.com/wescpy>
    Python training & consulting : http://CyberwebConsulting.com
    "Core Python" books : http://CorePython.com
    Python blog: http://wescpy.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140714/b6a0a3ab/attachment.html>

From wescpy at gmail.com  Tue Jul 15 09:33:09 2014
From: wescpy at gmail.com (wesley chun)
Date: Tue, 15 Jul 2014 00:33:09 -0700
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <007401cf9ec3$3f537880$bdfa6980$@gmail.com>
References: <20140713161616.6082706.98601.1277@gmail.com>
 <007401cf9ec3$3f537880$bdfa6980$@gmail.com>
Message-ID: <CAB6eaA4_B6pX7Ek2Lbcrq=hLNZjbNctCS6nha4MF6ceiU2Gc+w@mail.gmail.com>

*> From:* idiallo.spsu at gmail.com
*> Sent:* Sunday, July 13, 2014 9:16 AM
*> To:* Python Tutor Mailing List
*> Subject:* [Tutor] Python 2 Vs python 3

>
> I am in the process to dive into python and start learning it. But most
books
> advice to install python 2 instead of ?python 3. Any advice from the ones
with
> the experiences and what is the main difference?



Everyone's given good reasons for each version and where to start. This, as
you can imagine, is also an FAQ which is asked several times a year, so it
may also be worthwhile to search the archives to see what has been said in
the past.

I also answered this question on Quora
<http://www.quora.com/Python-programming-language-1/As-someone-interested-in-learning-Python-should-I-start-with-2-x-or-go-straight-to-3-x/answer/Wesley-Chun>and
provided several references as well as a few talks I've given in the past
on the subject.

Cheers,
-- Wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    +wesley chun <http://google.com/+WesleyChun> : wescpy at gmail : @wescpy
<http://twitter.com/wescpy>
    Python training & consulting : http://CyberwebConsulting.com
    "Core Python" books : http://CorePython.com
    Python blog: http://wescpy.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/9e18da22/attachment.html>

From kwpolska at gmail.com  Tue Jul 15 10:20:31 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Tue, 15 Jul 2014 10:20:31 +0200
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
 <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
Message-ID: <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>

On Jul 15, 2014 3:17 AM, "John Cast" <jdcast at stanford.edu> wrote:
>
> Hey everyone,
>
> I really appreciate all of the help you given me.
> I am making progress, however I have reached a problem I'm not sure how
best to tackle and would like someone with more experience with excel and
python to lend their knowledge/opinion before I dive in further.
>
> I have two questions:
> 1) I'd like to be able to do a 'save-as web page' in python for my excel
workbook.  I tried this by hand and everything looks good EXCEPT that the
header cells sometimes were too narrow (because the person who created the
workbook didn't expand out each column enough sometimes) and thus blocked
some of the text in them occasionally.
> Is it possible to do a 'save-as web page' for the workbook in python?
>
> 2)  So (assuming I can do this 'save-as webpage' in code) I need to go
through each sheet in the workbook and change each column's width so that
it can hold all of its text.  I realize that xlrd is for reading and xlwt
is for writing and there is xutils for particular combinations of both
reading and writing.  However, nothing to do quite what I've stated as far
as I can tell (so far).  I currently open the workbook I want to modify
using the open_workbook functionality in the xlrd module.  As I understand
it I need the xlwt module to write to this workbook, but since it's opened
in xlrd do I just open the same workbook in xlwt again?  If so does each
module simply have a handle to the same file?
>
> NOTE: I'm basically just trying to present my excel workbook on the web
as it's shown in excel (retaining as much formatting as possible).
>
> Thanks again,
> John

If you want to have output that's very close to Excel?s, why not just use
Excel?s save as webpage capabilities? You can automate that, with Python or
something else (like Excel macros or Windows-specific automation software).
It's much easier to do it this way, and it guarantees good output without
much effort.

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
Sent from my SGS3.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/9906c03a/attachment-0001.html>

From oguzhanogreden at gmail.com  Tue Jul 15 12:09:01 2014
From: oguzhanogreden at gmail.com (=?UTF-8?B?T8SfdXpoYW4gw5bEn3JlZGVu?=)
Date: Tue, 15 Jul 2014 12:09:01 +0200
Subject: [Tutor] While Loop and Threads
In-Reply-To: <CAHvkzynzJLxrjigZoAXqqzhOqafR-121aiT-TXW8b0+HH+i3=Q@mail.gmail.com>
References: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
 <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>
 <CAHvkzynzJLxrjigZoAXqqzhOqafR-121aiT-TXW8b0+HH+i3=Q@mail.gmail.com>
Message-ID: <CABV10F-e9L7rp2ULgr0pp0UD_6obYiAbgYGhc7AdVz6C8eKsWA@mail.gmail.com>

Thanks!

I'll have a side question. If I implement this idea to my case,
threadWorker() would look like this:

def threadWorker(_arg1, _arg2):
    print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
    while g_threadStop.is_set() == False:
        ## here comes a for loop:
            while time_now < time_finish: # time_finish and counter defined
somewhere above and
                print("Thread running.")      # and expression of the
condition is intentionally (and necessarily, I believe)
                counter += 1                     # left out of for
expression.
                print(counter)
                time.sleep(1)
    print("Thread exiting...")

Of course in this case value of g_threadStop.is_set() is not checked until
for loop finishes its iteration. Would the suggestion below be a good way
to handle the event signal?

def threadWorker(_arg1, _arg2):
    print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
    ## here comes a for loop:
        while time_now  < time_finish: # counter and count_until defined
somewhere above and
            if g_threadStop.is_set() == False:
                # return something or raise an exception to signal
iteration was interrupted
            print("Thread running.")   # and expression of the condition is
intentionally (and necessarily, I believe)
            counter += 1                  # left out of for expression.
            time.sleep(1)
    print("Iteration done.")

This comes with a problem, due to time.sleep(1), signal is handled with a
delay. I can think of a work around through GTK:

   1. changing (1) to something like while time_now < time_finish -
   actually that is the way it is in original code.
   2. dealing with the counter in the GTK main loop since it's main use is
   for GTK display of the timer.

But let's now follow your advice and leave GTK out for a while and keep
imagining I want:

   1. Command line output for the timer.
   2. Event signal handling without a delay.

I have a felling that 'thread-way of thinking' would come up with another
thread for counter. Is that correct? If yes, would there be an obvious
advantage to either using GTK main loop or dealing with another thread?

2014-07-14 20:24 GMT+02:00 James Chapman <james at uplinkzero.com>:

> OK, so I mocked up an example now...
>
>
>
> import time
> import threading
>
> g_threadStop = threading.Event()
>
> def threadWorker(_arg1, _arg2):
>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>     while(not g_threadStop.is_set()):
>         print("Thread running.")
>         time.sleep(1)
>     print("Thread exiting...")
>
> def main():
>     t = threading.Thread(target=threadWorker, args = ("arg1", "arg2"))
>     t.start()
>     print("Main thread sleeping for 10 seconds...")
>     time.sleep(5)
>     print("Main thread setting g_threadStop")
>     g_threadStop.set()
>     time.sleep(3)
>     print("Main thread exiting...")
>
> if __name__ == '__main__':
>     main()
>
>
>
>
>
> --
> James
>
>
> On 14 July 2014 19:03, James Chapman <james at uplinkzero.com> wrote:
>
>> Multi-threading takes practice!
>>
>> Are you using an event object to signal the thread should exit? I'm
>> guessing you're just using a bool which is why it does not work.
>>
>> See: https://docs.python.org/3.4/library/threading.html#event-objects
>>
>> I'm very short on time and the moment and therefore can't mock up a
>> working example. If I have time later/tomorrow and you haven't solved it or
>> no one else has commented I'll try and put something together.
>>
>> IMO, move away from GTK until you get threading working as expected, then
>> add the additional layer. Solve one problem at a time.
>>
>> James
>>
>> --
>> James
>>
>>
>> On 13 July 2014 12:23, O?uzhan ??reden <oguzhanogreden at gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I've been practicing with multithreading and gtk for a while and
>>> recently have observed something I can't quite grasp.
>>>
>>> This is basically a timer with a settings window and a countdown window
>>> which is produced after setting_window passes necessary arguments to thread.
>>>
>>> I have a while loop which counts time, inside the thread, while variable
>>> "runner" is True, which looks like this:
>>>
>>>     def run(self):
>>>         cycle = ['work', 'break', 'long_break']
>>>         cycle = cycle[:2]*self.workn+cycle[3]
>>>         self.runner = True
>>>         sec_count = timedelta(seconds=1)
>>>
>>>         while self.runner == True:
>>>             for i in cycle:
>>>                 self.setState(i)
>>>                 print('Start:', i, datetime.now())
>>>
>>>                 while self.end_time > datetime.now():
>>>                     time.sleep(1)
>>>                     self.duration -= sec_count
>>>
>>>                 self.count[self.state] += 1
>>>
>>> And I want countdown to stop when countdown_window receives delete
>>> event, thus I have a countdown_window.stop() function which is defined as
>>> follows:
>>>
>>> def stop(self, *args):
>>>         pom.count[pom.state] -= 1
>>>         pom.runner = False # refers to the runner of the thread.
>>>         print(pom.runner) # prints False,
>>>         Gtk.main_quit()
>>>
>>> What I expect to happen is that while loop to break, but it does not.
>>>
>>> Any suggestions?
>>>
>>> Best,
>>> O?uzhan
>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> To unsubscribe or change subscription options:
>>> https://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/20c51a04/attachment.html>

From ugajin at talktalk.net  Tue Jul 15 14:46:13 2014
From: ugajin at talktalk.net (ugajin at talktalk.net)
Date: Tue, 15 Jul 2014 08:46:13 -0400
Subject: [Tutor] name error
Message-ID: <8D16E41E109A1B5-870-CF44@webmail-vfrr08.sis.aol.com>

Thanks all, for your time and trouble spent on this issue.?
?
There are other 2D packages around including; Shoebot, which runs 
Python 2.7 and is a rewrite of nodebox 1, and is said to be inspired by 
DrawBot and Shoes. However, its installation is not well documented (or 
straightforward).  nodebox 1 is declared as a fork of DrawBot, and 
Shoes is written in Ruby.  The precursor of all these seem to be a 
language/environment named DBN (design by numbers), which appears also 
to have spawned Processing, a better known (and better supported) Java 
based IDE. I migrated from Processing to nodebox because of a small 
anomaly in how Processing out-processes bitmaps (no pun intended).? One 
really great thing (for me) is the discovery that DrawBot will out-put 
fully compliant native SVG. I do not think Matplotlib is quite the same 
type of thing.

shoebot seems to be the way forward, but as said, its installation on 
OSX is not straightforward. The GitHub repository suggests using 
MacPorts and Python 2.5 with, py25-numpy - atlas, pango + quartz, 
librsvg, py25-pil, py25-cairo, py25-gtk
But it goes on to say 'MacPorts does not have the python-rsvg package, 
so svg output won't work (see above). Perhaps they mean Python 2.5 does 
not have the Python-rsvg package. Not sure.
It goes on to state as a TODO: 'probably installing py27 packages and 
gnome-python-desktop would fix the missing python-rsvg problem.
It is unclear what py27 packages are. How do I check to see what 
packages I have, and e.g. if I have gnome-python-desktop?
I have OSX installed Python 2.5, as well as Python 2.7 via MacPorts

Apologies for any earlier confusion caused. The nodebox IDE is indeed 
messing me up, big time.?
?The function rect(x, y, w, h) is called as it is shown in the nodebox 
IDE (lowercase - see below).
# file named rect_1
rect(0, 0, 100, 100)
To clarify, this produces the expected output, but if I try importing 
this file with a simple import statement I get the name error:
# file named import_rect_1
import rect_1
Outputs:
Traceback (most recent call last):
? File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
? File "/Users/apple/Documents/nodeBox/06_15_2014/import_rect_1.py", 
line 1, in &lt;module&gt;
? File "/Users/apple/Documents/nodeBox/06_15_2014/rect_1.py", line 1, 
in &lt;module&gt;
NameError: name 'rect' is not defined

I can use the exec statement, but this rather defeats my purpose.
f = open('rect_1.py')
code = f.read()
exec code

If I put the following statement in an otherwise empty document
print dir()
I get the following information displayed in the IDE console window:
['BOOLEAN', 'BUTTON', 'BezierPath', 'CENTER', 'CLOSE', 'CMYK', 
'CORNER', 'CURVETO', 'Canvas', 'ClippingPath', 'Color', 'Context', 
'DEFAULT_HEIGHT', 'DEFAULT_WIDTH', 'FORTYFIVE', 'FRAME', 'Grob', 
'HEIGHT', 'HSB', 'Image', 'JUSTIFY', 'KEY_BACKSPACE', 'KEY_DOWN', 
'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'LEFT', 'LINETO', 'MOUSEX', 
'MOUSEY', 'MOVETO', 'NORMAL', 'NUMBER', 'NodeBoxError', 'Oval', 
'PAGENUM', 'PathElement', 'Point', 'RGB', 'RIGHT', 'Rect', 'TEXT', 
'Text', 'Transform', 'Variable', 'WIDTH', '__builtins__', '__class__', 
'__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', 
'__init__', '__magic_var__', '__module__', '__new__', '__reduce__', 
'__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 
'_align', '_arrow', '_arrow45', '_autoclosepath', '_colormode', 
'_colorrange', '_copy_attr', '_copy_attrs', '_ctx', '_fillcolor', 
'_fontname', '_fontsize', '_get_height', '_get_width', '_imagecache', 
'_lineheight', '_makeInstance', '_noImagesHint', '_ns', '_oldvars', 
'_outputmode', '_path', '_resetContext', '_strokecolor', 
'_strokewidth', '_transform', '_transformmode', '_transformstack', 
'_vars', 'addvar', 'align', 'arrow', 'autoclosepath', 'autotext', 
'background', 'beginclip', 'beginpath', 'canvas', 'choice', 
'closepath', 'cm', 'color', 'colormode', 'colorrange', 'curveto', 
'drawpath', 'endclip', 'endpath', 'files', 'fill', 'findpath', 
'findvar', 'font', 'fontsize', 'grid', 'image', 'imagesize', 'inch', 
'key', 'keycode', 'keydown', 'line', 'lineheight', 'lineto', 'mm', 
'mousedown', 'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 
'pop', 'push', 'random', 'rect', 'reset', 'rotate', 'save', 'scale', 
'scrollwheel', 'size', 'skew', 'speed', 'star', 'stroke', 
'strokewidth', 'text', 'textheight', 'textmetrics', 'textpath', 
'textwidth', 'transform', 'translate', 'var', 'wheeldelta', 'ximport']

As you see, there is something named 'Rect' (capitalised).

As Steven has suggested it would be more interesting, I have tried the 
same:
print Rect
#prints: &lt;bound method Context.Rect of &lt;nodebox.graphics.Context 
object at 0x1d33b670&gt;&gt;
print Rect.__name__
# prints: Rect

I am still considering this.
Running the following code;
print dir(Context)

produces:
['BezierPath', 'ClippingPath', 'Color', 'HEIGHT', 'Image', 
'KEY_BACKSPACE', 'KEY_DOWN', 'KEY_LEFT', 'KEY_RIGHT', 'KEY_UP', 'Oval', 
'Rect', 'Text', 'WIDTH', '__class__', '__delattr__', '__dict__', 
'__doc__', '__getattribute__', '__hash__', '__init__', '__module__', 
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', 
'__str__', '__weakref__', '_arrow', '_arrow45', '_get_height', 
'_get_width', '_makeInstance', '_resetContext', 'addvar', 'align', 
'arrow', 'autoclosepath', 'background', 'beginclip', 'beginpath', 
'closepath', 'color', 'colormode', 'colorrange', 'curveto', 'drawpath', 
'endclip', 'endpath', 'fill', 'findpath', 'findvar', 'font', 
'fontsize', 'image', 'imagesize', 'line', 'lineheight', 'lineto', 
'moveto', 'nofill', 'nostroke', 'outputmode', 'oval', 'pop', 'push', 
'rect', 'reset', 'rotate', 'save', 'scale', 'size', 'skew', 'speed', 
'star', 'stroke', 'strokewidth', 'text', 'textheight', 'textmetrics', 
'textpath', 'textwidth', 'transform', 'translate', 'var', 'ximport']

I note here that 'rect' is now all in lowercase.

Further, to confirm, the following code does execute correctly:
import nodebox
nodebox.graphics.BezierPath(rect(0, 0, 100, 100))

The suggestions, which I thank you for, of running:
import nodebox
nodebox.graphics.BezierPath.rect(0, 0, 100, 100)
produces the following outputs:
Traceback (most recent call last):
? File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
? File "&lt;untitled&gt;", line 5, in &lt;module&gt;
TypeError: unbound method rect() must be called with BezierPath 
instance as first argument (got int instance instead)
and:
import nodebox
nodebox.graphics.Rect(0, 0, 100, 100)
Traceback (most recent call last):
? File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
? File "&lt;untitled&gt;", line 8, in &lt;module&gt;
TypeError: __init__() takes exactly 6 arguments (5 given)

However, I now find the following code also executes correctly:
import nodebox
nodebox.graphics.Context(BezierPath(rect(0, 0, 100, 100)))

Interesting as it is, I am no closer to finding a solution.
If, I try calling the the above as a module I get:
# file named rect_2
import nodebox
nodebox.graphics.Context(BezierPath(rect(0, 0, 100, 100)))
# file named import_rect_2
import rect_2

I now get:
Traceback (most recent call last):
? File "nodebox/gui/mac/__init__.pyo", line 358, in _execScript
? File "/Users/apple/Documents/nodeBox/07_15_2014/import_rect_2.py", 
line 1, in &lt;module&gt;
? File "/Users/apple/Documents/nodeBox/07_15_2014/rect_2.py", line 3, 
in &lt;module&gt;
NameError: name 'BezierPath' is not defined

I hope this helps clear up any confusion.

Kind regards

-u

PS - I use a web-based mail client, which is I think based on AOL's 
client and its takeover by talktalk.

PPS - The comment for v.1.9.7? is not relevant to the issues here, but 
it is something I wanted to note, for future reference.?
I apologise for its inclusion, I was too tired to think where else to 
put it.

PPPS - Re:
&gt; dir: ['__builtins__', '__doc__', '__file__', '__name__', 
'draw_rect', &gt; 'nodebox']

I have tried to repeat this outcome, and I am surprised that it was not 
so easy to do.
I still have the original files, and they produced the same output as 
shown previously.
After some investigation, it seems that 'draw_rect' results from an 
earlier test that had been comment out.
What I had done, was to place the rect(x, y, w, h) function in a def 
wrapper.
I had then abandoned this line of enquiry, and had commented out the 
code.
nodebox 1 does not have a kernel restart command.

I hope this makes sense.







  

From james at uplinkzero.com  Tue Jul 15 15:14:22 2014
From: james at uplinkzero.com (James Chapman)
Date: Tue, 15 Jul 2014 14:14:22 +0100
Subject: [Tutor] While Loop and Threads
In-Reply-To: <CABV10F-e9L7rp2ULgr0pp0UD_6obYiAbgYGhc7AdVz6C8eKsWA@mail.gmail.com>
References: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
 <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>
 <CAHvkzynzJLxrjigZoAXqqzhOqafR-121aiT-TXW8b0+HH+i3=Q@mail.gmail.com>
 <CABV10F-e9L7rp2ULgr0pp0UD_6obYiAbgYGhc7AdVz6C8eKsWA@mail.gmail.com>
Message-ID: <CAHvkzymAGMi6p4JPVr4Qde3hnqe0dbMv3-TVT8e6rsSF=5et6Q@mail.gmail.com>

So if I understand this correctly, you want to start a thread and then stop
it after a certain time period?

Here's an adapted example that includes a timer. (I believe in learning by
example where possible)
With that said, if it were my code going into production I'd move the timer
logic out of the thread and only signal the thread when it should exit.
Keep the logic within the thread simple and try and make each
method/function do one thing only. It makes for testable, reusable code.

In my new example
* The first thread should exit because the time limit is met.
* The second thread should exit because the Event is set.

Hope this helps...

James



import time
import threading

class ThreadExample(object):

    def __init__(self):
        self.thread1Stop = threading.Event()
        self.thread2Stop = threading.Event()
        self.timeFinish = time.time() + 12

    def threadWorkerOne(self, _arg1, _arg2):
        print("THREAD1 - started with args: %s, %s" % (_arg1, _arg2))
        while(not self.thread1Stop.is_set()):
            while(time.time() < self.timeFinish):
                print("THREAD1 - Running")
                if (self.thread1Stop.is_set()):
                    break # Break out of the time while loop
                time.sleep(1)
            if time.time() > self.timeFinish:
                print("THREAD1 - Time limit exceeded")
                self.thread1Stop.set()
        print("THREAD1 - Exiting because thread1Stop is TRUE")

    def threadWorkerTwo(self, _arg1, _arg2):
        print("THREAD2 - started with args: %s, %s" % (_arg1, _arg2))
        while(not self.thread2Stop.is_set()):
            while(time.time() < self.timeFinish):
                print("THREAD2 - Running")
                if (self.thread2Stop.is_set()):
                    break # Break out of the time while loop
                time.sleep(1)
            if time.time() > self.timeFinish:
                print("THREAD2 - Time limit exceeded")
                self.thread2Stop.set()
        print("THREAD2 - Exiting because thread2Stop is TRUE")

    def main(self):
        t1 = threading.Thread(target=self.threadWorkerOne, args = ("arg1",
"arg2"))
        t1.start()
        t2 = threading.Thread(target=self.threadWorkerTwo, args = ("arg1",
"arg2"))
        t2.start()
        print("MAIN - sleep(5)")
        time.sleep(5)
        print("MAIN - setting thread1Stop")
        self.thread1Stop.set()
        print("MAIN - sleep(10)")
        time.sleep(10)
        print("MAIN - exiting...")

if __name__ == '__main__':
    runExample = ThreadExample()
    runExample.main()







--
James


On 15 July 2014 11:09, O?uzhan ??reden <oguzhanogreden at gmail.com> wrote:

> Thanks!
>
> I'll have a side question. If I implement this idea to my case,
> threadWorker() would look like this:
>
>
> def threadWorker(_arg1, _arg2):
>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>     while g_threadStop.is_set() == False:
>         ## here comes a for loop:
>             while time_now < time_finish: # time_finish and counter
> defined somewhere above and
>                 print("Thread running.")      # and expression of the
> condition is intentionally (and necessarily, I believe)
>                 counter += 1                     # left out of for
> expression.
>                 print(counter)
>                 time.sleep(1)
>     print("Thread exiting...")
>
> Of course in this case value of g_threadStop.is_set() is not checked until
> for loop finishes its iteration. Would the suggestion below be a good way
> to handle the event signal?
>
>
> def threadWorker(_arg1, _arg2):
>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>     ## here comes a for loop:
>         while time_now  < time_finish: # counter and count_until defined
> somewhere above and
>             if g_threadStop.is_set() == False:
>                 # return something or raise an exception to signal
> iteration was interrupted
>             print("Thread running.")   # and expression of the condition
> is intentionally (and necessarily, I believe)
>             counter += 1                  # left out of for expression.
>             time.sleep(1)
>     print("Iteration done.")
>
> This comes with a problem, due to time.sleep(1), signal is handled with a
> delay. I can think of a work around through GTK:
>
>    1. changing (1) to something like while time_now < time_finish -
>    actually that is the way it is in original code.
>    2. dealing with the counter in the GTK main loop since it's main use
>    is for GTK display of the timer.
>
> But let's now follow your advice and leave GTK out for a while and keep
> imagining I want:
>
>    1. Command line output for the timer.
>    2. Event signal handling without a delay.
>
> I have a felling that 'thread-way of thinking' would come up with another
> thread for counter. Is that correct? If yes, would there be an obvious
> advantage to either using GTK main loop or dealing with another thread?
>
> 2014-07-14 20:24 GMT+02:00 James Chapman <james at uplinkzero.com>:
>
> OK, so I mocked up an example now...
>>
>>
>>
>> import time
>> import threading
>>
>> g_threadStop = threading.Event()
>>
>> def threadWorker(_arg1, _arg2):
>>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>>     while(not g_threadStop.is_set()):
>>         print("Thread running.")
>>         time.sleep(1)
>>     print("Thread exiting...")
>>
>> def main():
>>     t = threading.Thread(target=threadWorker, args = ("arg1", "arg2"))
>>     t.start()
>>     print("Main thread sleeping for 10 seconds...")
>>     time.sleep(5)
>>     print("Main thread setting g_threadStop")
>>     g_threadStop.set()
>>     time.sleep(3)
>>     print("Main thread exiting...")
>>
>> if __name__ == '__main__':
>>     main()
>>
>>
>>
>>
>>
>> --
>> James
>>
>>
>> On 14 July 2014 19:03, James Chapman <james at uplinkzero.com> wrote:
>>
>>> Multi-threading takes practice!
>>>
>>> Are you using an event object to signal the thread should exit? I'm
>>> guessing you're just using a bool which is why it does not work.
>>>
>>> See: https://docs.python.org/3.4/library/threading.html#event-objects
>>>
>>> I'm very short on time and the moment and therefore can't mock up a
>>> working example. If I have time later/tomorrow and you haven't solved it or
>>> no one else has commented I'll try and put something together.
>>>
>>> IMO, move away from GTK until you get threading working as expected,
>>> then add the additional layer. Solve one problem at a time.
>>>
>>> James
>>>
>>> --
>>> James
>>>
>>>
>>> On 13 July 2014 12:23, O?uzhan ??reden <oguzhanogreden at gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I've been practicing with multithreading and gtk for a while and
>>>> recently have observed something I can't quite grasp.
>>>>
>>>> This is basically a timer with a settings window and a countdown window
>>>> which is produced after setting_window passes necessary arguments to thread.
>>>>
>>>> I have a while loop which counts time, inside the thread, while
>>>> variable "runner" is True, which looks like this:
>>>>
>>>>     def run(self):
>>>>         cycle = ['work', 'break', 'long_break']
>>>>         cycle = cycle[:2]*self.workn+cycle[3]
>>>>         self.runner = True
>>>>         sec_count = timedelta(seconds=1)
>>>>
>>>>         while self.runner == True:
>>>>             for i in cycle:
>>>>                 self.setState(i)
>>>>                 print('Start:', i, datetime.now())
>>>>
>>>>                 while self.end_time > datetime.now():
>>>>                     time.sleep(1)
>>>>                     self.duration -= sec_count
>>>>
>>>>                 self.count[self.state] += 1
>>>>
>>>> And I want countdown to stop when countdown_window receives delete
>>>> event, thus I have a countdown_window.stop() function which is defined as
>>>> follows:
>>>>
>>>> def stop(self, *args):
>>>>         pom.count[pom.state] -= 1
>>>>         pom.runner = False # refers to the runner of the thread.
>>>>         print(pom.runner) # prints False,
>>>>         Gtk.main_quit()
>>>>
>>>> What I expect to happen is that while loop to break, but it does not.
>>>>
>>>> Any suggestions?
>>>>
>>>> Best,
>>>> O?uzhan
>>>>
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor at python.org
>>>> To unsubscribe or change subscription options:
>>>> https://mail.python.org/mailman/listinfo/tutor
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/8c96c4c3/attachment.html>

From james at uplinkzero.com  Tue Jul 15 15:34:11 2014
From: james at uplinkzero.com (James Chapman)
Date: Tue, 15 Jul 2014 14:34:11 +0100
Subject: [Tutor] While Loop and Threads
In-Reply-To: <CAHvkzymAGMi6p4JPVr4Qde3hnqe0dbMv3-TVT8e6rsSF=5et6Q@mail.gmail.com>
References: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
 <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>
 <CAHvkzynzJLxrjigZoAXqqzhOqafR-121aiT-TXW8b0+HH+i3=Q@mail.gmail.com>
 <CABV10F-e9L7rp2ULgr0pp0UD_6obYiAbgYGhc7AdVz6C8eKsWA@mail.gmail.com>
 <CAHvkzymAGMi6p4JPVr4Qde3hnqe0dbMv3-TVT8e6rsSF=5et6Q@mail.gmail.com>
Message-ID: <CAHvkzykPvtUXzWo3nSw3n2wDTwqBjBLj+vfd2yhdtAsX1Z9Pjw@mail.gmail.com>

Apologies, I didn't answer your question.

        while time_now  < time_finish: # counter and count_until defined
somewhere above and
            if g_threadStop.is_set() == False:
                # return something

Thread methods are typically void, meaning they return nothing. At least
this is the case in other languages, so I would expect the return to fail.
Also, what would you be returning it to?
Perhaps just a return without a value to indicate exit. (Probably some
reading required here)

Exceptions should be raised when something occurs that you were not
expecting and not used as an exit mechanism for normal operation.

Where to place the timer is up to you. Another thread is an option, but is
it necessary? Overhead needs to be considered.


--
James


On 15 July 2014 14:14, James Chapman <james at uplinkzero.com> wrote:

> So if I understand this correctly, you want to start a thread and then
> stop it after a certain time period?
>
> Here's an adapted example that includes a timer. (I believe in learning by
> example where possible)
> With that said, if it were my code going into production I'd move the
> timer logic out of the thread and only signal the thread when it should
> exit. Keep the logic within the thread simple and try and make each
> method/function do one thing only. It makes for testable, reusable code.
>
> In my new example
> * The first thread should exit because the time limit is met.
> * The second thread should exit because the Event is set.
>
> Hope this helps...
>
> James
>
>
>
> import time
> import threading
>
> class ThreadExample(object):
>
>     def __init__(self):
>         self.thread1Stop = threading.Event()
>         self.thread2Stop = threading.Event()
>         self.timeFinish = time.time() + 12
>
>     def threadWorkerOne(self, _arg1, _arg2):
>         print("THREAD1 - started with args: %s, %s" % (_arg1, _arg2))
>         while(not self.thread1Stop.is_set()):
>             while(time.time() < self.timeFinish):
>                 print("THREAD1 - Running")
>                 if (self.thread1Stop.is_set()):
>                     break # Break out of the time while loop
>                 time.sleep(1)
>             if time.time() > self.timeFinish:
>                 print("THREAD1 - Time limit exceeded")
>                 self.thread1Stop.set()
>         print("THREAD1 - Exiting because thread1Stop is TRUE")
>
>     def threadWorkerTwo(self, _arg1, _arg2):
>         print("THREAD2 - started with args: %s, %s" % (_arg1, _arg2))
>         while(not self.thread2Stop.is_set()):
>             while(time.time() < self.timeFinish):
>                 print("THREAD2 - Running")
>                 if (self.thread2Stop.is_set()):
>                     break # Break out of the time while loop
>                 time.sleep(1)
>             if time.time() > self.timeFinish:
>                 print("THREAD2 - Time limit exceeded")
>                 self.thread2Stop.set()
>         print("THREAD2 - Exiting because thread2Stop is TRUE")
>
>     def main(self):
>         t1 = threading.Thread(target=self.threadWorkerOne, args = ("arg1",
> "arg2"))
>         t1.start()
>         t2 = threading.Thread(target=self.threadWorkerTwo, args = ("arg1",
> "arg2"))
>         t2.start()
>         print("MAIN - sleep(5)")
>         time.sleep(5)
>         print("MAIN - setting thread1Stop")
>         self.thread1Stop.set()
>         print("MAIN - sleep(10)")
>         time.sleep(10)
>         print("MAIN - exiting...")
>
> if __name__ == '__main__':
>     runExample = ThreadExample()
>     runExample.main()
>
>
>
>
>
>
>
> --
> James
>
>
> On 15 July 2014 11:09, O?uzhan ??reden <oguzhanogreden at gmail.com> wrote:
>
>> Thanks!
>>
>> I'll have a side question. If I implement this idea to my case,
>> threadWorker() would look like this:
>>
>>
>> def threadWorker(_arg1, _arg2):
>>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>>     while g_threadStop.is_set() == False:
>>         ## here comes a for loop:
>>             while time_now < time_finish: # time_finish and counter
>> defined somewhere above and
>>                 print("Thread running.")      # and expression of the
>> condition is intentionally (and necessarily, I believe)
>>                 counter += 1                     # left out of for
>> expression.
>>                 print(counter)
>>                 time.sleep(1)
>>     print("Thread exiting...")
>>
>> Of course in this case value of g_threadStop.is_set() is not checked
>> until for loop finishes its iteration. Would the suggestion below be a good
>> way to handle the event signal?
>>
>>
>> def threadWorker(_arg1, _arg2):
>>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>>     ## here comes a for loop:
>>         while time_now  < time_finish: # counter and count_until defined
>> somewhere above and
>>             if g_threadStop.is_set() == False:
>>                 # return something or raise an exception to signal
>> iteration was interrupted
>>             print("Thread running.")   # and expression of the condition
>> is intentionally (and necessarily, I believe)
>>             counter += 1                  # left out of for expression.
>>             time.sleep(1)
>>     print("Iteration done.")
>>
>> This comes with a problem, due to time.sleep(1), signal is handled with a
>> delay. I can think of a work around through GTK:
>>
>>    1. changing (1) to something like while time_now < time_finish -
>>    actually that is the way it is in original code.
>>    2. dealing with the counter in the GTK main loop since it's main use
>>    is for GTK display of the timer.
>>
>> But let's now follow your advice and leave GTK out for a while and keep
>> imagining I want:
>>
>>    1. Command line output for the timer.
>>    2. Event signal handling without a delay.
>>
>> I have a felling that 'thread-way of thinking' would come up with another
>> thread for counter. Is that correct? If yes, would there be an obvious
>> advantage to either using GTK main loop or dealing with another thread?
>>
>> 2014-07-14 20:24 GMT+02:00 James Chapman <james at uplinkzero.com>:
>>
>> OK, so I mocked up an example now...
>>>
>>>
>>>
>>> import time
>>> import threading
>>>
>>> g_threadStop = threading.Event()
>>>
>>> def threadWorker(_arg1, _arg2):
>>>     print("Starting worker thread with args: %s, %s" % (_arg1, _arg2))
>>>     while(not g_threadStop.is_set()):
>>>         print("Thread running.")
>>>         time.sleep(1)
>>>     print("Thread exiting...")
>>>
>>> def main():
>>>     t = threading.Thread(target=threadWorker, args = ("arg1", "arg2"))
>>>     t.start()
>>>     print("Main thread sleeping for 10 seconds...")
>>>     time.sleep(5)
>>>     print("Main thread setting g_threadStop")
>>>     g_threadStop.set()
>>>     time.sleep(3)
>>>     print("Main thread exiting...")
>>>
>>> if __name__ == '__main__':
>>>     main()
>>>
>>>
>>>
>>>
>>>
>>> --
>>> James
>>>
>>>
>>> On 14 July 2014 19:03, James Chapman <james at uplinkzero.com> wrote:
>>>
>>>> Multi-threading takes practice!
>>>>
>>>> Are you using an event object to signal the thread should exit? I'm
>>>> guessing you're just using a bool which is why it does not work.
>>>>
>>>> See: https://docs.python.org/3.4/library/threading.html#event-objects
>>>>
>>>> I'm very short on time and the moment and therefore can't mock up a
>>>> working example. If I have time later/tomorrow and you haven't solved it or
>>>> no one else has commented I'll try and put something together.
>>>>
>>>> IMO, move away from GTK until you get threading working as expected,
>>>> then add the additional layer. Solve one problem at a time.
>>>>
>>>> James
>>>>
>>>> --
>>>> James
>>>>
>>>>
>>>> On 13 July 2014 12:23, O?uzhan ??reden <oguzhanogreden at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I've been practicing with multithreading and gtk for a while and
>>>>> recently have observed something I can't quite grasp.
>>>>>
>>>>> This is basically a timer with a settings window and a countdown
>>>>> window which is produced after setting_window passes necessary arguments to
>>>>> thread.
>>>>>
>>>>> I have a while loop which counts time, inside the thread, while
>>>>> variable "runner" is True, which looks like this:
>>>>>
>>>>>     def run(self):
>>>>>         cycle = ['work', 'break', 'long_break']
>>>>>         cycle = cycle[:2]*self.workn+cycle[3]
>>>>>         self.runner = True
>>>>>         sec_count = timedelta(seconds=1)
>>>>>
>>>>>         while self.runner == True:
>>>>>             for i in cycle:
>>>>>                 self.setState(i)
>>>>>                 print('Start:', i, datetime.now())
>>>>>
>>>>>                 while self.end_time > datetime.now():
>>>>>                     time.sleep(1)
>>>>>                     self.duration -= sec_count
>>>>>
>>>>>                 self.count[self.state] += 1
>>>>>
>>>>> And I want countdown to stop when countdown_window receives delete
>>>>> event, thus I have a countdown_window.stop() function which is defined as
>>>>> follows:
>>>>>
>>>>> def stop(self, *args):
>>>>>         pom.count[pom.state] -= 1
>>>>>         pom.runner = False # refers to the runner of the thread.
>>>>>         print(pom.runner) # prints False,
>>>>>         Gtk.main_quit()
>>>>>
>>>>> What I expect to happen is that while loop to break, but it does not.
>>>>>
>>>>> Any suggestions?
>>>>>
>>>>> Best,
>>>>> O?uzhan
>>>>>
>>>>> _______________________________________________
>>>>> Tutor maillist  -  Tutor at python.org
>>>>> To unsubscribe or change subscription options:
>>>>> https://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/6b311584/attachment-0001.html>

From japhy at pearachute.com  Tue Jul 15 16:49:52 2014
From: japhy at pearachute.com (Japhy Bartlett)
Date: Tue, 15 Jul 2014 09:49:52 -0500
Subject: [Tutor] While Loop and Threads
In-Reply-To: <CABV10F-e9L7rp2ULgr0pp0UD_6obYiAbgYGhc7AdVz6C8eKsWA@mail.gmail.com>
References: <CABV10F_JgfKxAp7eosSkQV6i2i4yUVa6pS-Z7MTy8Zm9yGmcwQ@mail.gmail.com>
 <CAHvkzykbLicd9qmwNoEP9Yy0a76e67yLShZ9zShTKpd4x9Cizg@mail.gmail.com>
 <CAHvkzynzJLxrjigZoAXqqzhOqafR-121aiT-TXW8b0+HH+i3=Q@mail.gmail.com>
 <CABV10F-e9L7rp2ULgr0pp0UD_6obYiAbgYGhc7AdVz6C8eKsWA@mail.gmail.com>
Message-ID: <CANTsVHLXoQx6NYDF1Ko3hjLX-qDLo0uY_hUeiWHv-1Jjfm2o0Q@mail.gmail.com>

this construct:


On Tue, Jul 15, 2014 at 5:09 AM, O?uzhan ??reden <oguzhanogreden at gmail.com>
wrote:
>
>
>         while time_now  < time_finish: # counter and count_until defined
> somewhere above and
>             if g_threadStop.is_set() == False:
>                 # return something or raise an exception to signal
> iteration was interrupted
>
>
 might work better as something like


while (time_now < time_finish) and (not g_threadStop.is_set()):

to avoid the 'interrupt iteration' dilemma
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/ad21866d/attachment.html>

From jdcast at stanford.edu  Tue Jul 15 18:48:37 2014
From: jdcast at stanford.edu (John Cast)
Date: Tue, 15 Jul 2014 09:48:37 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
 <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
 <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>
Message-ID: <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>

Yes, that's exactly what I'm trying to do.  However, when testing this out
manually like I pointed to above, the output of the save as feature freezes
the column widths.  This would be fine except that not all of the column
widths are expanded so that all of the text can be seen (at the moment I
don't have any control over how the sheets are made, just access to them),
so when the save as feature does its thing, some text is blocked.
That's why I need a way to go through each sheet and adjust the widths and
then programmatically do a save as webpage for all of them from python.

So I guess this brings me back to my previous post's questions:

1) How does one automate the save as webpage from python?

2) What is the most straightforward way to adjust the column widths of the
existing excel sheets?

Any hints/guidance/answers are greatly appreciated.

Thanks again


On Tue, Jul 15, 2014 at 1:20 AM, Chris ?Kwpolska? Warrick <
kwpolska at gmail.com> wrote:

>
> On Jul 15, 2014 3:17 AM, "John Cast" <jdcast at stanford.edu> wrote:
> >
> > Hey everyone,
> >
> > I really appreciate all of the help you given me.
> > I am making progress, however I have reached a problem I'm not sure how
> best to tackle and would like someone with more experience with excel and
> python to lend their knowledge/opinion before I dive in further.
> >
> > I have two questions:
> > 1) I'd like to be able to do a 'save-as web page' in python for my excel
> workbook.  I tried this by hand and everything looks good EXCEPT that the
> header cells sometimes were too narrow (because the person who created the
> workbook didn't expand out each column enough sometimes) and thus blocked
> some of the text in them occasionally.
> > Is it possible to do a 'save-as web page' for the workbook in python?
> >
> > 2)  So (assuming I can do this 'save-as webpage' in code) I need to go
> through each sheet in the workbook and change each column's width so that
> it can hold all of its text.  I realize that xlrd is for reading and xlwt
> is for writing and there is xutils for particular combinations of both
> reading and writing.  However, nothing to do quite what I've stated as far
> as I can tell (so far).  I currently open the workbook I want to modify
> using the open_workbook functionality in the xlrd module.  As I understand
> it I need the xlwt module to write to this workbook, but since it's opened
> in xlrd do I just open the same workbook in xlwt again?  If so does each
> module simply have a handle to the same file?
> >
> > NOTE: I'm basically just trying to present my excel workbook on the web
> as it's shown in excel (retaining as much formatting as possible).
> >
> > Thanks again,
> > John
>
> If you want to have output that's very close to Excel?s, why not just use
> Excel?s save as webpage capabilities? You can automate that, with Python or
> something else (like Excel macros or Windows-specific automation software).
> It's much easier to do it this way, and it guarantees good output without
> much effort.
>
> --
> Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
> Sent from my SGS3.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/cbfcfe5c/attachment.html>

From joel.goldstick at gmail.com  Tue Jul 15 19:39:41 2014
From: joel.goldstick at gmail.com (Joel Goldstick)
Date: Tue, 15 Jul 2014 13:39:41 -0400
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
 <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
 <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>
 <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>
Message-ID: <CAPM-O+xF6b8gJJuFhKDYHjaBp3UFbAJGrra0GtB0anq-G=nSHw@mail.gmail.com>

On Tue, Jul 15, 2014 at 12:48 PM, John Cast <jdcast at stanford.edu> wrote:

> Yes, that's exactly what I'm trying to do.  However, when testing this out
> manually like I pointed to above, the output of the save as feature freezes
> the column widths.  This would be fine except that not all of the column
> widths are expanded so that all of the text can be seen (at the moment I
> don't have any control over how the sheets are made, just access to them),
> so when the save as feature does its thing, some text is blocked.
> That's why I need a way to go through each sheet and adjust the widths and
> then programmatically do a save as webpage for all of them from python.
>
> So I guess this brings me back to my previous post's questions:
>
> 1) How does one automate the save as webpage from python?
>
> 2) What is the most straightforward way to adjust the column widths of the
> existing excel sheets?
>
> Any hints/guidance/answers are greatly appreciated.
>
> Thanks again
>

I see you have received guidance as to web hosting, but I have questions
about the excel side.

Does the program that creates the spreadsheet produce an xls formatted
file, or a csv file?

You seem to indicate that want to write python to actually perform the
steps you would do if you were editing the spreadsheet in person:
  1. open the file in excel
  2. click on the various columns to make them expand to see the data
properly
  3. Save as some file in html format.
  4. put that file in some location to be read by your web server.

If your files are csv you can use python csv file to read them, then create
the web page by inserting each value in an appropriately created html
template (with <table> markup).

Can you show the actual input file here? and the markeup for your output
file as well?

If you are doing this on a windows machine, there may be a module that
manipulates .xls files directly using something they used to call .com
objects, I can't help you there except to say that seems like a bad way to
go.  Computer programs are best written to solve a problem, but not usually
to act as a stand in for the steps that would be used to solve that problem
as a user by hand.





_______________________________________________

> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/174df3db/attachment-0001.html>

From alan.gauld at btinternet.com  Tue Jul 15 21:46:54 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 15 Jul 2014 20:46:54 +0100
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
 <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
 <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>
 <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>
Message-ID: <lq40fe$7c3$1@ger.gmane.org>

On 15/07/14 17:48, John Cast wrote:

> 1) How does one automate the save as webpage from python?

It is possible using COM objects and the pywin32 library.
However that's rarely the best way to approach things.
But if you insist...

Here is a short example of opening a FileOpen dialog...

import win32com.client as com
filepath = r"D:\Whatever\You\want"
fileopen = 1  # change to whatever code you need of 1-4
app = com.Dispatch("Excel.Ap[plication")
app.Visible = True
fd - app.FileDialog(fileopen)
fd.InitialFileName = filepath
fd.Title = "Open a file"
if fd.Show() == -1:
    fd.Execute()

I'll let you use your imagination (and the MSDN web site?) to
work out how to do a SaveAs dialog and populate it with the
right values.

The last 2 lines check if the user actually hit the Open or OK
button and then tell Excel to open the file.

There are other direct commands so you preobably can saveAs
directly if you search the docs.

> 2) What is the most straightforward way to adjust the column widths of
> the existing excel sheets?

Again its possible by using COM to drive the workbook objects.
But again its not the best way to address this.

> Any hints/guidance/answers are greatly appreciated.

OK, Use another approach!

Use xlrd to read the data out and insert it into an HTML page.
Use the one output by Excel as a template (although you can probably 
delete most of it as unnecessary cruft produced by Microsoft.(

That gives you control over the look independent of anything
the users of Excel may do.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From jdcast at stanford.edu  Tue Jul 15 19:54:00 2014
From: jdcast at stanford.edu (John Cast)
Date: Tue, 15 Jul 2014 10:54:00 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <CAPM-O+xF6b8gJJuFhKDYHjaBp3UFbAJGrra0GtB0anq-G=nSHw@mail.gmail.com>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
 <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
 <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>
 <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>
 <CAPM-O+xF6b8gJJuFhKDYHjaBp3UFbAJGrra0GtB0anq-G=nSHw@mail.gmail.com>
Message-ID: <CAHdK22_WU8JnznuRREmKEi+MjybXvFEiyRjGCdz0JikZxqsTJQ@mail.gmail.com>

Yes, that pretty well sums up what I would like to do.  I can't show the
input here, but it is saved as an xlsx file (this is proving problematic
for me already since I'm using python 3.4 and it doesn't fully support this
format yet...I may have to switch to python 2 for better support).
I don't think this will require very much code, but since I am new to the
language and having trouble finding documentation on methods such as
"saveAs", it's proving difficult.

Thanks again


On Tue, Jul 15, 2014 at 10:39 AM, Joel Goldstick <joel.goldstick at gmail.com>
wrote:

>
>
>
> On Tue, Jul 15, 2014 at 12:48 PM, John Cast <jdcast at stanford.edu> wrote:
>
>> Yes, that's exactly what I'm trying to do.  However, when testing this
>> out manually like I pointed to above, the output of the save as feature
>> freezes the column widths.  This would be fine except that not all of the
>> column widths are expanded so that all of the text can be seen (at the
>> moment I don't have any control over how the sheets are made, just access
>> to them), so when the save as feature does its thing, some text is blocked.
>>
>> That's why I need a way to go through each sheet and adjust the widths
>> and then programmatically do a save as webpage for all of them from python.
>>
>> So I guess this brings me back to my previous post's questions:
>>
>> 1) How does one automate the save as webpage from python?
>>
>> 2) What is the most straightforward way to adjust the column widths of
>> the existing excel sheets?
>>
>> Any hints/guidance/answers are greatly appreciated.
>>
>> Thanks again
>>
>
> I see you have received guidance as to web hosting, but I have questions
> about the excel side.
>
> Does the program that creates the spreadsheet produce an xls formatted
> file, or a csv file?
>
> You seem to indicate that want to write python to actually perform the
> steps you would do if you were editing the spreadsheet in person:
>   1. open the file in excel
>   2. click on the various columns to make them expand to see the data
> properly
>   3. Save as some file in html format.
>   4. put that file in some location to be read by your web server.
>
> If your files are csv you can use python csv file to read them, then
> create the web page by inserting each value in an appropriately created
> html template (with <table> markup).
>
> Can you show the actual input file here? and the markeup for your output
> file as well?
>
> If you are doing this on a windows machine, there may be a module that
> manipulates .xls files directly using something they used to call .com
> objects, I can't help you there except to say that seems like a bad way to
> go.  Computer programs are best written to solve a problem, but not usually
> to act as a stand in for the steps that would be used to solve that problem
> as a user by hand.
>
>
>
>
>
> _______________________________________________
>
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140715/e55d86d8/attachment.html>

From cs at zip.com.au  Wed Jul 16 08:06:53 2014
From: cs at zip.com.au (Cameron Simpson)
Date: Wed, 16 Jul 2014 16:06:53 +1000
Subject: [Tutor] Python 2 Vs python 3
In-Reply-To: <lpumu8$ps8$1@ger.gmane.org>
References: <lpumu8$ps8$1@ger.gmane.org>
Message-ID: <20140716060653.GA29986@cskk.homeip.net>

On 13Jul2014 20:33, Alan Gauld <alan.gauld at btinternet.com> wrote:
>I've been using python 3 almost exclusively for the last 4 months and
>the differences are much more significant than the headlines suggest.
>In particular the module structure and naming is very different - 
>enough to confuse a beginner using a Python2 tutor for sure.
>
>But there are a lot of subtle changes under the hood - extra
>options in functions for example. After about a month I gave up on my 
>intention to create dual version code - it was just too much work.

Just for contrast, most of my code is dual 2.x and 3.x. That does mean at least 
2.7 on occasion, and I have some code that is Python 3 only.

Like many, I'd say go with Python 3 unless you're using a tutorial that is 2.x 
specific.

Aside from print being a function, you'll find the code very very similar.  
There are differences, but that can be a smaller problem that you expect.

Cheers,
Cameron Simpson <cs at zip.com.au>

An ambassador is a man of virtue sent to lie abroad for his country; a news-
writer is a man without virtue who lies at home for himself.
         - Sir Henry Wotton, Reliquae Wottonianae

From jarod_v6 at libero.it  Wed Jul 16 10:04:39 2014
From: jarod_v6 at libero.it (jarod_v6 at libero.it)
Date: Wed, 16 Jul 2014 10:04:39 +0200 (CEST)
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 49
Message-ID: <386916741.11163891405497879919.JavaMail.actor@webmail9>

Hi there!!!
I have a file  with this data
['uc002uvo.3 ', 'uc001mae.1']
['uc010dya.2 ', 'uc001kko.2']
['uc003ejx.2 ', 'uc010yfr.1']
['uc001bhk.2 ', 'uc003eib.2']
['uc001znc.2 ', 'uc001efn.2']
['uc002ycq.2 ', 'uc001vnh.2']
['uc001odf.1 ', 'uc002mwd.2']
['uc010jkn.1 ', 'uc010luk.1']
['uc003uhf.3 ', 'uc010tqd.1']
['uc002rue.3 ', 'uc001tex.2']
['uc011dtt.1 ', 'uc001lkv.1']
['uc003yyt.2 ', 'uc003mkl.2']
['uc003pkv.2 ', 'uc003ytw.2']
['uc010bhz.2 ', 'uc002kbt.1']
['uc001wnj.2 ', 'uc009wtj.1']
['uc011lyh.1 ', 'uc003jvb.2']
['uc002awj.1 ', 'uc009znm.1']
['uc010bft.2 ', 'uc002cxz.1']
['uc011mar.1 ', 'uc001lvb.1']
['uc001oxl.2 ', 'uc002lvx.1']

I want to replace of the things after the dots, so I want to have  a file with 
this output:

['uc002uvo ', 'uc001mae']
['uc010dya ', 'uc001kko']
...

I try to use regular expression but I have  a strange output

with open("non_annotati.csv") as p:
    for i in p:
        lines= i.rstrip("\n").split("\t")
        mit = re.sub(r'(\.\d$)','',lines[0])
        mit2 = re.sub(r'(\.\d$)','',lines[1])
        print mit,mit2


uc003klv.2  uc010lxj
uc001tzy.2  uc011kzk
uc010qdj.1  uc001iku
uc004coe.2  uc002vmf
uc002dvw.2  uc004bxn
uc001dmp.2  uc001dmo
uc002rqd.2  uc010ynl
uc010cvm.1  uc002qjc
uc003ewy.3  uc003hgx
uc002ejy.2  uc003mvb
uc002fou.1  uc010ilx
uc003vhf.2  uc010qlo
uc003mix.2  uc010tdt
uc002nez.1  uc003wxe
uc011cpu.1  uc002keg
uc001ovu.2  uc011dne
uc010zfg.1  uc001jvq
uc010jlf.2  uc011azi
uc001ors.3  uc001vzx
uc010tyt.1  uc003vih
uc010fde.2  uc002xgq
uc010bit.1  uc003zle
uc010xcb.1  uc010wsg
uc011acg.1  uc009wlp
uc002bnj.2  uc004ckd


Where is the error? what is wrong in my regular expression code? 



From dyoo at hashcollision.org  Wed Jul 16 11:02:33 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 16 Jul 2014 02:02:33 -0700
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 49
In-Reply-To: <386916741.11163891405497879919.JavaMail.actor@webmail9>
References: <386916741.11163891405497879919.JavaMail.actor@webmail9>
Message-ID: <CAGZAPF61WFFyaSw2NphTXvR_VCO5ZXt6hsDwKhg5uRZYOCHGew@mail.gmail.com>

Hi Jarod,

Ah.  Note the extra space on the first column elements.  For example,
one of your inputs that you've split on tabs:

    ['uc011lyh.1 ', 'uc003jvb.2']

If you look really closely, you'll see the whitespace at the end of
"uc011lyh.1".  That's why the regex isn't matching.

Good luck!

From dyoo at hashcollision.org  Wed Jul 16 11:08:33 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 16 Jul 2014 02:08:33 -0700
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 49
In-Reply-To: <CAGZAPF61WFFyaSw2NphTXvR_VCO5ZXt6hsDwKhg5uRZYOCHGew@mail.gmail.com>
References: <386916741.11163891405497879919.JavaMail.actor@webmail9>
 <CAGZAPF61WFFyaSw2NphTXvR_VCO5ZXt6hsDwKhg5uRZYOCHGew@mail.gmail.com>
Message-ID: <CAGZAPF7JBQAwtahcTdp-zpwPTDOPpAvSJ7SNe1w1-0oNsXDgoA@mail.gmail.com>

By the way, those look like gene locus names.  Reminds me of the ones
I saw when I worked at arabidopsis.org.  e.g.:

   http://www.arabidopsis.org/servlets/TairObject?id=1000638674&type=gene

From ljmamoreira at gmail.com  Wed Jul 16 13:49:05 2014
From: ljmamoreira at gmail.com (Jose Amoreira)
Date: Wed, 16 Jul 2014 12:49:05 +0100
Subject: [Tutor] Question about style
Message-ID: <53C666B1.5080104@gmail.com>

Hello
I wrote a function that, given a list of numbers, finds clusters of 
values by proximity and returns a reduced list containing the centers of 
these clusters. However, I find it rather unclear. I would appreciate 
any comments on how pythonic my function is and suggestions to improve 
its readability.
The function is:

def aglomerate(x_lst, delta=1.e-5):
     clusters = [] #list of pairs [center, number of clustered values]
     for x in x_lst:
         close_to = [abs(x - y) < delta for y,_ in clusters]
         if any(close_to):
             # x is close to a cluster
             index = close_to.index(True)
             center, n = clusters[index]
             #update the cluster center including the new value,
             #and increment dimension of cluster
             clusters[index] = (n * center + x)/(n+1), n+1
         else:
             # x does not belong to any cluster, create a new one
             clusters.append([x,1])
     # return list with centers
     return [center for center, _ in clusters]

Examples:
1. No clusters in x_lst:
In [52]: aglomerate([1., 2., 3., 4.])
Out[52]: [1.0, 2.0, 3.0, 4.0]

2. Some elements in x_lst are equal:
In [53]: aglomerate([1., 2., 1., 3.])
Out[53]: [1.0, 2.0, 3.0]

3. Some elements in x_lst should be clustered:
In [54]: aglomerate([1., 2., 1.1, 3.], delta=0.2)
Out[54]: [1.05, 2.0, 3.0]

So, the function seems to work as it should, but can it be made more 
readable?

Thanks for any help.
Ze

From joel.goldstick at gmail.com  Wed Jul 16 14:10:23 2014
From: joel.goldstick at gmail.com (Joel Goldstick)
Date: Wed, 16 Jul 2014 08:10:23 -0400
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 49
In-Reply-To: <386916741.11163891405497879919.JavaMail.actor@webmail9>
References: <386916741.11163891405497879919.JavaMail.actor@webmail9>
Message-ID: <CAPM-O+ykqcwdMJ+HYB6ZzYEX2YZ-S3h_BYbBScSWHj3Ugd=OGQ@mail.gmail.com>

2014-07-16 4:04 GMT-04:00 jarod_v6 at libero.it <jarod_v6 at libero.it>:

> Hi there!!!
> I have a file  with this data
> ['uc002uvo.3 ', 'uc001mae.1']
> ['uc010dya.2 ', 'uc001kko.2']
>


> I want to replace of the things after the dots, so I want to have  a file
> with
> this output:
>
> ['uc002uvo ', 'uc001mae']
> ['uc010dya ', 'uc001kko']
> ...
>
> I try to use regular expression but I have  a strange output
>

I'm one of those who doesn't choose regex first for string manipulation
that are simpler without them.

>
> with open("non_annotati.csv") as p:
>     for i in p:
>         lines= i.rstrip("\n").split("\t")
>         mit = re.sub(r'(\.\d$)','',lines[0])
>         mit2 = re.sub(r'(\.\d$)','',lines[1])
>         print mit,mit2
>

            mit  = lines[0].split('.')[0]
            mit  = lines[1].split('.')[0]

>>> s = 'uc003klv.2  '
>>> s.split('.')
['uc003klv', '2  ']



> uc003klv.2  uc010lxj
> uc001tzy.2  uc011kzk
> uc010qdj.1  uc001iku
> uc004coe.2  uc002vmf
> uc002dvw.2  uc004bxn
> uc001dmp.2  uc001dmo
> uc002rqd.2  uc010ynl
> uc010cvm.1  uc002qjc
> uc003ewy.3  uc003hgx
> uc002ejy.2  uc003mvb
> uc002fou.1  uc010ilx
> uc003vhf.2  uc010qlo
> uc003mix.2  uc010tdt
> uc002nez.1  uc003wxe
> uc011cpu.1  uc002keg
> uc001ovu.2  uc011dne
> uc010zfg.1  uc001jvq
> uc010jlf.2  uc011azi
> uc001ors.3  uc001vzx
> uc010tyt.1  uc003vih
> uc010fde.2  uc002xgq
> uc010bit.1  uc003zle
> uc010xcb.1  uc010wsg
> uc011acg.1  uc009wlp
> uc002bnj.2  uc004ckd
>
>
> Where is the error? what is wrong in my regular expression code?
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140716/b6899f2f/attachment.html>

From wolfgang.maier at biologie.uni-freiburg.de  Wed Jul 16 22:18:00 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Wed, 16 Jul 2014 22:18:00 +0200
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 49
In-Reply-To: <386916741.11163891405497879919.JavaMail.actor@webmail9>
References: <386916741.11163891405497879919.JavaMail.actor@webmail9>
Message-ID: <53C6DDF8.5020703@biologie.uni-freiburg.de>

On 16.07.2014 10:04, jarod_v6 at libero.it wrote:
> Hi there!!!
> I have a file  with this data
> ['uc002uvo.3 ', 'uc001mae.1']
> ['uc010dya.2 ', 'uc001kko.2']
> ['uc003ejx.2 ', 'uc010yfr.1']
> ['uc001bhk.2 ', 'uc003eib.2']
> ['uc001znc.2 ', 'uc001efn.2']
> ['uc002ycq.2 ', 'uc001vnh.2']
> ['uc001odf.1 ', 'uc002mwd.2']
> ['uc010jkn.1 ', 'uc010luk.1']
> ['uc003uhf.3 ', 'uc010tqd.1']
> ['uc002rue.3 ', 'uc001tex.2']
> ['uc011dtt.1 ', 'uc001lkv.1']
> ['uc003yyt.2 ', 'uc003mkl.2']
> ['uc003pkv.2 ', 'uc003ytw.2']
> ['uc010bhz.2 ', 'uc002kbt.1']
> ['uc001wnj.2 ', 'uc009wtj.1']
> ['uc011lyh.1 ', 'uc003jvb.2']
> ['uc002awj.1 ', 'uc009znm.1']
> ['uc010bft.2 ', 'uc002cxz.1']
> ['uc011mar.1 ', 'uc001lvb.1']
> ['uc001oxl.2 ', 'uc002lvx.1']
>
> I want to replace of the things after the dots, so I want to have  a file with
> this output:
>
> ['uc002uvo ', 'uc001mae']
> ['uc010dya ', 'uc001kko']
> ...
>
> I try to use regular expression but I have  a strange output
>
> with open("non_annotati.csv") as p:
>      for i in p:
>          lines= i.rstrip("\n").split("\t")

lines is not the best variable name why not use:
            gene1, gene2 = i.rstrip("\n").split("\t")

>          mit = re.sub(r'(\.\d$)','',lines[0])
>          mit2 = re.sub(r'(\.\d$)','',lines[1])
>          print mit,mit2
>

While Danny has pointed out the actual reason why your code is not 
working with this specific input data, it's generally not a good idea to 
make too specific assumptions about input formatting by specifying '\n' 
and ?\t' explicitly when all you want to do is to eliminate whitespace:

 >>> help(s.split)
Help on built-in function split:

split(...) method of builtins.str instance
     S.split(sep=None, maxsplit=-1) -> list of strings

     Return a list of the words in S, using sep as the
     delimiter string.  If maxsplit is given, at most maxsplit
     splits are done. If sep is not specified or is None, any
     whitespace string is a separator and empty strings are
     removed from the result.

 >>> s='uc002uvo.3 \tuc001mae.1\r\n'  # Windows line breaks
 >>> s.split()
['uc002uvo.3', 'uc001mae.1']

and I agree with Joel that re is overkill here. In fact, your current 
regexp will fail with two digit numbers after the dot though I don't 
know whether such names can occur in your data.

Best,
Wolfgang


From ljmamoreira at gmail.com  Wed Jul 16 23:50:44 2014
From: ljmamoreira at gmail.com (Jose Amoreira)
Date: Wed, 16 Jul 2014 22:50:44 +0100
Subject: [Tutor] Question about style
In-Reply-To: <53C6EB4A.4030806@biologie.uni-freiburg.de>
References: <53C666B1.5080104@gmail.com>
 <53C6EB4A.4030806@biologie.uni-freiburg.de>
Message-ID: <53C6F3B4.4010008@gmail.com>

Hi!

On 07/16/2014 10:14 PM, Wolfgang Maier wrote:
>
> careful here: you just stored a tuple instead of a list; doesn't matter
> for your current implementation, but may bite you at some point.

Oh, you're right. Silly mistake, even if harmless for the application I 
have in mind.
>
>>          else:
>>              # x does not belong to any cluster, create a new one
>>              clusters.append([x,1])
>>      # return list with centers
>>      return [center for center, _ in clusters]
>>
>
> Your building of the close_to list with Trues and Falses, then using it
> to find the original element again makes me think that you're a regular
> R user ? Using such a logical vector (I guess that's what you'd call it
> in R) should (almost) never be required in Python.

No, I use mainly python and fortran (but I'm not a "real" programmer). I 
arrived at this particular function from a previous version which only 
took one single line and was quite readable, but it didn't compute the 
centers of the clusters; the first value added to a new cluster would be 
the cluster value, regardless of other added values. Then I decided that 
I wanted the centroids of each cluster and this was the result. It 
smelled bad, but I was trying to hang on to my (supposedly) smart one 
liner...

> Here's an implementation of this idea demonstrating how, in Python, you
> typically use the builtin enumerate function to avoid "logical vectors"
> or other kinds of index juggling:
>
> def aglomerate(x_lst, delta=1.e-5):
>      centers = []
>      sizes = []
>      for x in x_lst:
>          for i, center in enumerate(centers):
>              if abs(x - center) < delta:
>                  # x is close to a cluster
>                  #update the cluster center including the new value,
>                  #and increment dimension of cluster
>                  n = sizes[i]
>                  centers[i] = (n * center + x)/(n+1)
>                  sizes[i] = n+1
>                  break
>          else:
>              # this block is executed only when the break in the preceeding
>              # block wasn't reached =>
>              # x does not belong to any cluster, create a new one
>              centers.append(x)
>              sizes.append(1)
>      # return list with centers
>      return centers
>
Thanks, Wolfgang. You were very helpful.


From alan.gauld at btinternet.com  Thu Jul 17 01:05:24 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 17 Jul 2014 00:05:24 +0100
Subject: [Tutor] Question about style
In-Reply-To: <53C666B1.5080104@gmail.com>
References: <53C666B1.5080104@gmail.com>
Message-ID: <lq70fk$hk0$1@ger.gmane.org>

On 16/07/14 12:49, Jose Amoreira wrote:
> Hello
> I wrote a function that, given a list of numbers, finds clusters of
> values by proximity and returns a reduced list containing the centers of
> these clusters. However, I find it rather unclear. I would appreciate
> any comments on how pythonic my function is and suggestions to improve
> its readability.

Just throwing this idea in without really thinking about it...
Would itertools.groupby work?

It takes a sorted collection and groups the items found based on a key 
function. If the key function deemed two items identical if they were 
within distance X of each other then groupby might help.

The itertools functions are generally space efficient and
therefore good for large volumes of data.

Just a thought.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From wolfgang.maier at biologie.uni-freiburg.de  Wed Jul 16 23:14:50 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Wed, 16 Jul 2014 23:14:50 +0200
Subject: [Tutor] Question about style
In-Reply-To: <53C666B1.5080104@gmail.com>
References: <53C666B1.5080104@gmail.com>
Message-ID: <53C6EB4A.4030806@biologie.uni-freiburg.de>

On 16.07.2014 13:49, Jose Amoreira wrote:
> Hello
> I wrote a function that, given a list of numbers, finds clusters of
> values by proximity and returns a reduced list containing the centers of
> these clusters. However, I find it rather unclear. I would appreciate
> any comments on how pythonic my function is and suggestions to improve
> its readability.
> The function is:
>
> def aglomerate(x_lst, delta=1.e-5):
>      clusters = [] #list of pairs [center, number of clustered values]
>      for x in x_lst:
>          close_to = [abs(x - y) < delta for y,_ in clusters]
>          if any(close_to):
>              # x is close to a cluster
>              index = close_to.index(True)
>              center, n = clusters[index]
>              #update the cluster center including the new value,
>              #and increment dimension of cluster
>              clusters[index] = (n * center + x)/(n+1), n+1

careful here: you just stored a tuple instead of a list; doesn't matter 
for your current implementation, but may bite you at some point.

>          else:
>              # x does not belong to any cluster, create a new one
>              clusters.append([x,1])
>      # return list with centers
>      return [center for center, _ in clusters]
>

Your building of the close_to list with Trues and Falses, then using it 
to find the original element again makes me think that you're a regular 
R user ? Using such a logical vector (I guess that's what you'd call it 
in R) should (almost) never be required in Python.
Possible solutions for your case depend somewhat on what you want to be 
able to do. Currently, you are identifying all possible clusters that a 
new value may belong to, but then you are simply adding it to the first 
cluster. If that's all your code needs to do, then you could do (this 
avoids indexing altogether by exploiting the fact that lists are mutable):

def aglomerate(x_lst, delta=1.e-5):
     clusters = [] #list of pairs [center, number of clustered values]
     for x in x_lst:
         for cluster in clusters:
	    # cluster is now a list of two elements
	    # lists are mutable objects
             center, n = cluster # to keep things readable
             if abs(x - center) < delta:
                 # x is close to a cluster
                 #update the cluster center including the new value,
                 #and increment dimension of cluster
                 # since list are mutable objects you can do this as an
                 # in-place operation
                 cluster[0] = (n * center + x)/(n+1)
                 cluster[1] = n+1
                 break
         else:
             # this block is executed if the break in the preceeding
             # block wasn't reached =>
             # x does not belong to any cluster, create a new one
             clusters.append([x,1])
     # return list with centers
     return [center for center, _ in clusters]

Given your return value on the other hand, it looks like your clusters 
data structure is somewhat suboptimal. In fact, you would be better off 
with two separate lists for centers and sizes, in which case you could 
simply
return centers.

Here's an implementation of this idea demonstrating how, in Python, you 
typically use the builtin enumerate function to avoid "logical vectors" 
or other kinds of index juggling:

def aglomerate(x_lst, delta=1.e-5):
     centers = []
     sizes = []
     for x in x_lst:
         for i, center in enumerate(centers):
             if abs(x - center) < delta:
                 # x is close to a cluster
                 #update the cluster center including the new value,
                 #and increment dimension of cluster
                 n = sizes[i]
                 centers[i] = (n * center + x)/(n+1)
                 sizes[i] = n+1
                 break
         else:
             # this block is executed only when the break in the preceeding
             # block wasn't reached =>
             # x does not belong to any cluster, create a new one
             centers.append(x)
             sizes.append(1)
     # return list with centers
     return centers

In summary, indices in Python should be handled using enumerate and 
sometimes can be avoided completely by in-place manipulations of mutable 
objects.

Best,
Wolfgang

From mitesh.budhabhatti at gmail.com  Thu Jul 17 06:25:14 2014
From: mitesh.budhabhatti at gmail.com (Mitesh H. Budhabhatti)
Date: Thu, 17 Jul 2014 09:55:14 +0530
Subject: [Tutor] Python open source for beginners
Message-ID: <CADv7osio8mNtxuJakiopmCLaPA3RSfimoNw_8H9R-nyQMt3PXg@mail.gmail.com>

I am learning Python 3 for fun and as hobby.  I am experienced in C#,
ASP.Net.  I want to gain more knowledge in Python.  Can somebody please
suggest open source projects/sites?
Thanks

Warm Regards,
Mitesh H. Budhabhatti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140717/442b7f16/attachment.html>

From wescpy at gmail.com  Thu Jul 17 06:55:04 2014
From: wescpy at gmail.com (wesley chun)
Date: Wed, 16 Jul 2014 21:55:04 -0700
Subject: [Tutor] Python open source for beginners
In-Reply-To: <CADv7osio8mNtxuJakiopmCLaPA3RSfimoNw_8H9R-nyQMt3PXg@mail.gmail.com>
References: <CADv7osio8mNtxuJakiopmCLaPA3RSfimoNw_8H9R-nyQMt3PXg@mail.gmail.com>
Message-ID: <CAB6eaA4komHZ_T=0EkNio_GFZisLWpAE_bmH5QEzom4HC50sJA@mail.gmail.com>

> I am learning Python 3 for fun and as hobby.  I am experienced in C#,
> ASP.Net.  I want to gain more knowledge in Python.  Can somebody
> please suggest open source projects/sites?


Greetings Mitesh, and welcome to Python!

Others will have more advice to give on specific projects, but I would
initially suggest: 1) http://python.org which is the main website for the
open source language -- it has all the docs and a beginners' tutorial, 2)
http://ironpython.net which is the website for IronPython, the open source
version of Python implemented for .NET, an area that you're familiar with,
and where you may feel more comfortable joining the Python world. Finally,
3) http://sf.net/projects/pywin32 -- this is the Python Extensions for
Windows library which allows you to create apps using the MFC library,
including COM clients.

As you start coding and running into issues/problems, feel free to drop by
and ask your questions here along with a description of what you tried,
what didn't work, and what was the output and/or stack trace that you got.

Best of luck!
--Wesley

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
    +wesley chun <http://google.com/+WesleyChun> : wescpy at gmail : @wescpy
<http://twitter.com/wescpy>
    Python training & consulting : http://CyberwebConsulting.com
    "Core Python" books : http://CorePython.com
    Python blog: http://wescpy.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140716/cb267040/attachment.html>

From mitesh.budhabhatti at gmail.com  Thu Jul 17 10:25:55 2014
From: mitesh.budhabhatti at gmail.com (Mitesh H. Budhabhatti)
Date: Thu, 17 Jul 2014 13:55:55 +0530
Subject: [Tutor] Python open source for beginners
In-Reply-To: <CAB6eaA4komHZ_T=0EkNio_GFZisLWpAE_bmH5QEzom4HC50sJA@mail.gmail.com>
References: <CADv7osio8mNtxuJakiopmCLaPA3RSfimoNw_8H9R-nyQMt3PXg@mail.gmail.com>
 <CAB6eaA4komHZ_T=0EkNio_GFZisLWpAE_bmH5QEzom4HC50sJA@mail.gmail.com>
Message-ID: <CADv7osgAUzrw1XtfGe8dVbUcR4je2sMuydrHcLGCZOpFd3aMrg@mail.gmail.com>

Thanks Wesley for the reply.  I wanted to utilize what I've learnt so far.
 So I thought learning using open source could be a good idea.
Thanks.

Warm Regards,
Mitesh H. Budhabhatti


On Thu, Jul 17, 2014 at 10:25 AM, wesley chun <wescpy at gmail.com> wrote:
>
> > I am learning Python 3 for fun and as hobby.  I am experienced in C#,
> > ASP.Net.  I want to gain more knowledge in Python.  Can somebody
> > please suggest open source projects/sites?
>
>
> Greetings Mitesh, and welcome to Python!
>
> Others will have more advice to give on specific projects, but I would
initially suggest: 1) http://python.org which is the main website for the
open source language -- it has all the docs and a beginners' tutorial, 2)
http://ironpython.net which is the website for IronPython, the open source
version of Python implemented for .NET, an area that you're familiar with,
and where you may feel more comfortable joining the Python world. Finally,
3) http://sf.net/projects/pywin32 -- this is the Python Extensions for
Windows library which allows you to create apps using the MFC library,
including COM clients.
>
> As you start coding and running into issues/problems, feel free to drop
by and ask your questions here along with a description of what you tried,
what didn't work, and what was the output and/or stack trace that you got.
>
> Best of luck!
> --Wesley
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> "A computer never does what you want... only what you tell it."
>     +wesley chun : wescpy at gmail : @wescpy
>     Python training & consulting : http://CyberwebConsulting.com
>     "Core Python" books : http://CorePython.com
>     Python blog: http://wescpy.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140717/c356088e/attachment.html>

From ljmamoreira at gmail.com  Thu Jul 17 18:23:46 2014
From: ljmamoreira at gmail.com (Jose Amoreira)
Date: Thu, 17 Jul 2014 17:23:46 +0100
Subject: [Tutor] Question about style
In-Reply-To: <lq70fk$hk0$1@ger.gmane.org>
References: <53C666B1.5080104@gmail.com> <lq70fk$hk0$1@ger.gmane.org>
Message-ID: <53C7F892.5010900@gmail.com>

Hello,

On 07/17/2014 12:05 AM, Alan Gauld wrote:

> Just throwing this idea in without really thinking about it...
> Would itertools.groupby work?
>
> It takes a sorted collection and groups the items found based on a key
> function. If the key function deemed two items identical if they were
> within distance X of each other then groupby might help.
>
> The itertools functions are generally space efficient and
> therefore good for large volumes of data.
>

Thanks for the suggestion, I didn't know about groupby. I gave it a try. 
The key function argument is optional; if we don't supply one, grouby 
groups *equal* list elements. But I want to group *close enough* 
elements (close enough meaning that their distance is less than some 
reference value), and I didn't manage to specify a key function in a 
form suitable for use with groubpy. I should spend some more time 
studying the examples.

Anyway, thanks a lot, it's always good to know a new module in the 
standard library.

Ze

From ljmamoreira at gmail.com  Thu Jul 17 19:26:43 2014
From: ljmamoreira at gmail.com (Jose Amoreira)
Date: Thu, 17 Jul 2014 18:26:43 +0100
Subject: [Tutor] Surprising behaviour of optional argument
Message-ID: <53C80753.8050202@gmail.com>

Hello
I stumbled on something I found surprising. I'm using standard python 
(cpython, I guess) 2.7 on openSuse 13.1.

Consider the function

In [2]: def f(x,y=[]):
    ...:     print y
    ...:     y.append(x)
    ...:     return x

This is the output of repeated calls to this function:

In [3]: f(1)
[]
Out[3]: 1
In [4]: f(2)
[1]
Out[4]: 2
In [5]: f(3)
[1, 2]
Out[5]: 3

So, the function seems to keep the value of the optional argument y over 
repeated calls. I was expecting that the optional argument, if not set 
explicitly in the calling command, would always assume the default value 
(the empty list), at every call.

I guess it has something to do with the mutability of the optional 
argument (in this case, a list), because it works as I expect if the 
optional argument is an int, for instance:

In [8]: def g(x,y=0):
    ...:     print y
    ...:     y += x
    ...:     return x
    ...:

In [9]: g(1)
0
Out[9]: 1
In [10]: g(2)
0
Out[10]: 2

(No memory of previous calls to the function.)
Is there a rationale for this behavior?
Thanks for any help,
Ze

From dyoo at hashcollision.org  Thu Jul 17 19:34:09 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 17 Jul 2014 10:34:09 -0700
Subject: [Tutor] Surprising behaviour of optional argument
In-Reply-To: <53C80753.8050202@gmail.com>
References: <53C80753.8050202@gmail.com>
Message-ID: <CAGZAPF5dA=BmMGyn-EcfBK6fehGgp5fUsB3Zw_H0HQ7Y9Jmg=A@mail.gmail.com>

On Jul 17, 2014 10:22 AM, "Jose Amoreira" <ljmamoreira at gmail.com> wrote:
>
> Hello
> I stumbled on something I found surprising. I'm using standard python
(cpython, I guess) 2.7 on openSuse 13.1.
>
> Consider the function
>
> In [2]: def f(x,y=[]):
>    ...:     print y
>    ...:     y.append(x)
>    ...:     return x
>

Yeah; the default value is not reevaluated between calls.  It's a common
gotcha.  Here are a few links to read more:

http://effbot.org/zone/default-values.htm

http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments

Good luck!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140717/1c422c07/attachment.html>

From rhce.san at gmail.com  Thu Jul 17 20:35:07 2014
From: rhce.san at gmail.com (Santosh Kumar)
Date: Fri, 18 Jul 2014 00:05:07 +0530
Subject: [Tutor] Modules to work with curl.
Message-ID: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>

Hi,

I am currently working on a project , which has lots of curl commands. I am
using subprocess.Popen to run these curl commands. But somehow i see its
bit slow.
Is there a way/module by which i can improve the performance of the program.

Thanks,
-- 
D. Santosh Kumar
RHCE | SCSA
+91-9703206361


Every task has a unpleasant side .. But you must focus on the end result
you are producing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140718/783b673d/attachment.html>

From dyoo at hashcollision.org  Thu Jul 17 21:15:18 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 17 Jul 2014 12:15:18 -0700
Subject: [Tutor] Modules to work with curl.
In-Reply-To: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>
References: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>
Message-ID: <CAGZAPF7Xw-6eo+STWAYPLEFSpAVffj_+AQ7ooRVSrvd-TH1qTg@mail.gmail.com>

On Thu, Jul 17, 2014 at 11:35 AM, Santosh Kumar <rhce.san at gmail.com> wrote:

> I am currently working on a project , which has lots of curl commands. I am
> using subprocess.Popen to run these curl commands. But somehow i see its bit
> slow.
> Is there a way/module by which i can improve the performance of the program.


If the use of curl really is responsible and worthwhile to optimize,
then you might consider using pycurl if you really need the full
features of curl.

    http://pycurl.sourceforge.net/

But can you say more what you're doing with curl?  More information
may let us give better advice.  The core lesson of
http://www.cs.bell-labs.com/cm/cs/pearls/cto.html is always in my
mind: we may not actually know the right question yet, so we must be
careful about our answers, lest we mislead.

I don't think we really understand the problem yet, so tell us more if you can.

I would also recommend profiling if you haven't done so already.
You've pointed out that something is slow, but unless you've actually
measured what's really responsible, anything could be contributing.
It may be, for example, that you're being limited by your network
throughput, in which case trying to make your program go faster will
not be effective.  You really must measure: otherwise, it's guesswork
and crossed fingers.

See:  https://docs.python.org/2/library/profile.html for documentation
on Python profiling.

From martin at linux-ip.net  Thu Jul 17 21:23:39 2014
From: martin at linux-ip.net (Martin A. Brown)
Date: Thu, 17 Jul 2014 15:23:39 -0400
Subject: [Tutor] Modules to work with curl.
In-Reply-To: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>
References: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>
Message-ID: <alpine.LSU.2.11.1407171454310.7499@kale.renesys.com>


Hi,

 : I am currently working on a project , which has lots of curl 
 : commands. I am using subprocess.Popen to run these curl commands. 
 : But somehow i see its bit slow. Is there a way/module by which i 
 : can improve the performance of the program.

Wow.  Is curl a requirement or do you simply need to speak HTTP?

Some suggestions and questions come to my mind:

  * Is your problem / cost the forking (i.e. how many times are you 
    calling curl)?

  * Is the problem unresponsive or sluggish HTTP servers?

  * Have you localized the slowness?  (I use logging data and timing
    information to try to figure that out.)

  * How do you define 'slow'?  How many curl commands is 'lots'?  
    Like 100 or 100,000?

Suggestions:

  * Profile the code and see where the slowness is.
 
  * Consider python-requests [0] to handle the HTTP fetches, instead 
    of calling subprocess.

  * If after that, you discover that your bottleneck is mostly 
    network, consider a task parallelizing solution.  One option 
    could be multiprocessing [1].  There are doubtless others.

-Martin

 [0] http://docs.python-requests.org/en/latest/
 [1] https://docs.python.org/2/library/multiprocessing.html

--
Martin A. Brown
http://linux-ip.net/

From breamoreboy at yahoo.co.uk  Thu Jul 17 23:44:16 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Thu, 17 Jul 2014 22:44:16 +0100
Subject: [Tutor] Question about style
In-Reply-To: <53C7F892.5010900@gmail.com>
References: <53C666B1.5080104@gmail.com> <lq70fk$hk0$1@ger.gmane.org>
 <53C7F892.5010900@gmail.com>
Message-ID: <lq9g3k$ft1$1@ger.gmane.org>

On 17/07/2014 17:23, Jose Amoreira wrote:
> Hello,
>
> On 07/17/2014 12:05 AM, Alan Gauld wrote:
>
>> Just throwing this idea in without really thinking about it...
>> Would itertools.groupby work?
>>
>> It takes a sorted collection and groups the items found based on a key
>> function. If the key function deemed two items identical if they were
>> within distance X of each other then groupby might help.
>>
>> The itertools functions are generally space efficient and
>> therefore good for large volumes of data.
>>
>
> Thanks for the suggestion, I didn't know about groupby. I gave it a try.
> The key function argument is optional; if we don't supply one, grouby
> groups *equal* list elements. But I want to group *close enough*
> elements (close enough meaning that their distance is less than some
> reference value), and I didn't manage to specify a key function in a
> form suitable for use with groubpy. I should spend some more time
> studying the examples.
>
> Anyway, thanks a lot, it's always good to know a new module in the
> standard library.
>
> Ze
>

Also take a look at the operator module 
https://docs.python.org/3/library/operator.html#module-operator as it's 
often used with itertools.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From ljmamoreira at gmail.com  Fri Jul 18 00:00:33 2014
From: ljmamoreira at gmail.com (Jose Amoreira)
Date: Thu, 17 Jul 2014 23:00:33 +0100
Subject: [Tutor] Surprising behaviour of optional argument
In-Reply-To: <CAGZAPF5dA=BmMGyn-EcfBK6fehGgp5fUsB3Zw_H0HQ7Y9Jmg=A@mail.gmail.com>
References: <53C80753.8050202@gmail.com>
 <CAGZAPF5dA=BmMGyn-EcfBK6fehGgp5fUsB3Zw_H0HQ7Y9Jmg=A@mail.gmail.com>
Message-ID: <53C84781.2090309@gmail.com>

Hi
On 07/17/2014 06:34 PM, Danny Yoo wrote:
>

> Yeah; the default value is not reevaluated between calls.  It's a common
> gotcha.  Here are a few links to read more:
>
> http://effbot.org/zone/default-values.htm
>
> http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments
>
> Good luck!
>

Aha, the object that stores the default value for the optional argument 
is created at the time of the execution of the function definition and 
mutable objects do mutate, so that's that. It makes a lot of sense.
Thanks, Danny

From alan.gauld at btinternet.com  Fri Jul 18 00:05:00 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 17 Jul 2014 23:05:00 +0100
Subject: [Tutor] Surprising behaviour of optional argument
In-Reply-To: <53C84781.2090309@gmail.com>
References: <53C80753.8050202@gmail.com>
 <CAGZAPF5dA=BmMGyn-EcfBK6fehGgp5fUsB3Zw_H0HQ7Y9Jmg=A@mail.gmail.com>
 <53C84781.2090309@gmail.com>
Message-ID: <lq9hac$t7b$1@ger.gmane.org>

On 17/07/14 23:00, Jose Amoreira wrote:

> Aha, the object that stores the default value for the optional argument
> is created at the time of the execution of the function definition and
> mutable objects do mutate, so that's that. It makes a lot of sense.

Yes, think of it as a feature, not a bug :-)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From ch2009 at arcor.de  Fri Jul 18 05:54:12 2014
From: ch2009 at arcor.de (Chris)
Date: Fri, 18 Jul 2014 05:54:12 +0200
Subject: [Tutor] Using module Facebook
Message-ID: <53C89A64.10800@arcor.de>

Dear All,

I'm trying to use the facebook-sdk for python [1]. I'm asking here and
not on the SDK groups, because I think this is a basic beginner's
question, not directly related to the framework.

I installed facebook-sdk:
	virtualenv .
	source bin/activate
	pip install facebook-sdk
	pip install requests

and I'm trying to use it now:

	#!/usr/bin/python
	from facebook import Facebook
	token = 'xxx'
	graph = facebook.GraphAPI(token)
	profile = graph.get_object("me")
	friends = graph.get_connections("me", "friends")
	friend_list = [friend['name'] for friend in friends['data']]
	print friend_list

but I'm getting the following error:

	(facebook)[chris at cd facebook]$ ./fb1.py
	Traceback (most recent call last):
	  File "./fb1.py", line 3, in <module>
	    from facebook import Facebook
	ImportError: No module named facebook

facebook.py is in:

	./lib/python2.6/site-packages/facebook.py

Thank you in advance.


[1] https://github.com/pythonforfacebook/facebook-sdk

-- 
Christian

From dan.janzen at gmail.com  Thu Jul 17 21:50:06 2014
From: dan.janzen at gmail.com (Dan Janzen)
Date: Thu, 17 Jul 2014 15:50:06 -0400
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 49
In-Reply-To: <386916741.11163891405497879919.JavaMail.actor@webmail9>
References: <386916741.11163891405497879919.JavaMail.actor@webmail9>
Message-ID: <53C828EE.6030404@gmail.com>

****DISCLAIMER*****

I have deliberately not read any of the other replies to this problem so 
my answer may be totally redundant! (but here it is anyway...)

One of the first issues that had to be addressed is the fact that your 
"CSV" file is probably not in the format you assume it is. Every line is 
a list, not the traditional "string separated by commas" format that one 
normally expects in a CSV file. One way to deal with that is to resave 
the file as a .txt file and deal with each line as one would normally do 
with a list, i.e. use list subscripting to manipulate each list element 
with regex code. Having said that, in the spirit of minimalism, there 
are ways to deal with it as a CSV file as well.

First, import the csv module and use the reader() method to properly 
access the contents.

importre

importcsv

withopen(/'non.csv'/, /'r'/) asp:

f = csv.reader(p, delimiter = /','/)

Then use a for loop to access each line and put the regex statements in 
the print statement

forw inf:

print(re.sub(r/'(\.\d)'/,/''/,w[0]), re.sub(r/'(\.\d)'/,/''/, w[1]))

The regex statements access the list elements with subscripting. The "$" 
was not necessary and without it you get the desired results.

TO SUMMARIZE:

With the following contents of file named "non.csv":

['uc002uvo.3 ', 'uc001mae.1']

['uc010dya.2 ', 'uc001kko.2']

and the following code run in Eclipse:

##test.py

importre

importcsv

withopen(/'non.csv'/, /'r'/) asp:

f = csv.reader(p, delimiter = /','/)

forw inf:

print(re.sub(r/'(\.\d)'/,/''/,w[0]), re.sub(r/'(\.\d)'/,/''/, w[1]))

I get:

['uc002uvo ''uc001mae']

['uc010dya ''uc001kko']





On 7/16/14, 4:04 AM, jarod_v6 at libero.it wrote:
> Hi there!!!
> I have a file  with this data
> ['uc002uvo.3 ', 'uc001mae.1']
> ['uc010dya.2 ', 'uc001kko.2']
> ['uc003ejx.2 ', 'uc010yfr.1']
> ['uc001bhk.2 ', 'uc003eib.2']
> ['uc001znc.2 ', 'uc001efn.2']
> ['uc002ycq.2 ', 'uc001vnh.2']
> ['uc001odf.1 ', 'uc002mwd.2']
> ['uc010jkn.1 ', 'uc010luk.1']
> ['uc003uhf.3 ', 'uc010tqd.1']
> ['uc002rue.3 ', 'uc001tex.2']
> ['uc011dtt.1 ', 'uc001lkv.1']
> ['uc003yyt.2 ', 'uc003mkl.2']
> ['uc003pkv.2 ', 'uc003ytw.2']
> ['uc010bhz.2 ', 'uc002kbt.1']
> ['uc001wnj.2 ', 'uc009wtj.1']
> ['uc011lyh.1 ', 'uc003jvb.2']
> ['uc002awj.1 ', 'uc009znm.1']
> ['uc010bft.2 ', 'uc002cxz.1']
> ['uc011mar.1 ', 'uc001lvb.1']
> ['uc001oxl.2 ', 'uc002lvx.1']
>
> I want to replace of the things after the dots, so I want to have  a file with
> this output:
>
> ['uc002uvo ', 'uc001mae']
> ['uc010dya ', 'uc001kko']
> ...
>
> I try to use regular expression but I have  a strange output
>
> with open("non_annotati.csv") as p:
>      for i in p:
>          lines= i.rstrip("\n").split("\t")
>          mit = re.sub(r'(\.\d$)','',lines[0])
>          mit2 = re.sub(r'(\.\d$)','',lines[1])
>          print mit,mit2
>
>
> uc003klv.2  uc010lxj
> uc001tzy.2  uc011kzk
> uc010qdj.1  uc001iku
> uc004coe.2  uc002vmf
> uc002dvw.2  uc004bxn
> uc001dmp.2  uc001dmo
> uc002rqd.2  uc010ynl
> uc010cvm.1  uc002qjc
> uc003ewy.3  uc003hgx
> uc002ejy.2  uc003mvb
> uc002fou.1  uc010ilx
> uc003vhf.2  uc010qlo
> uc003mix.2  uc010tdt
> uc002nez.1  uc003wxe
> uc011cpu.1  uc002keg
> uc001ovu.2  uc011dne
> uc010zfg.1  uc001jvq
> uc010jlf.2  uc011azi
> uc001ors.3  uc001vzx
> uc010tyt.1  uc003vih
> uc010fde.2  uc002xgq
> uc010bit.1  uc003zle
> uc010xcb.1  uc010wsg
> uc011acg.1  uc009wlp
> uc002bnj.2  uc004ckd
>
>
> Where is the error? what is wrong in my regular expression code?
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140717/4be3d93c/attachment-0001.html>

From alan.gauld at btinternet.com  Fri Jul 18 09:44:13 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 18 Jul 2014 08:44:13 +0100
Subject: [Tutor] Using module Facebook
In-Reply-To: <53C89A64.10800@arcor.de>
References: <53C89A64.10800@arcor.de>
Message-ID: <lqaj8d$6e1$1@ger.gmane.org>

On 18/07/14 04:54, Chris wrote:

> but I'm getting the following error:
>
> 	(facebook)[chris at cd facebook]$ ./fb1.py
> 	Traceback (most recent call last):
> 	  File "./fb1.py", line 3, in <module>
> 	    from facebook import Facebook
> 	ImportError: No module named facebook
>
> facebook.py is in:
>
> 	./lib/python2.6/site-packages/facebook.py

Are you sure thats the version of Python you are running
in the virtualenv?

And have you checked that that exact folder is in the sys.path?


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From ch2009 at arcor.de  Fri Jul 18 18:29:05 2014
From: ch2009 at arcor.de (Chris)
Date: Fri, 18 Jul 2014 18:29:05 +0200
Subject: [Tutor] Using module Facebook
In-Reply-To: <lqaj8d$6e1$1@ger.gmane.org>
References: <53C89A64.10800@arcor.de> <lqaj8d$6e1$1@ger.gmane.org>
Message-ID: <53C94B51.5010901@arcor.de>

On 07/18/2014 09:44 AM, Alan Gauld wrote:
> Are you sure thats the version of Python you are running
> in the virtualenv?

I've modified the first line to #!./bin/python (instead of
#!/usr/bin/python).

Now, there's another error message:

(facebook)[chris at cd facebook]$ ./fb1.py
Traceback (most recent call last):
  File "./fb1.py", line 6, in <module>
    import facebook
  File
"/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py",
line 811
    args = {k: v for k, v in args.iteritems() if v is not None}
                   ^
SyntaxError: invalid syntax



> And have you checked that that exact folder is in the sys.path?

Yes, it is.

-- 
Christian

From marc.tompkins at gmail.com  Fri Jul 18 19:47:12 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Fri, 18 Jul 2014 10:47:12 -0700
Subject: [Tutor] Using module Facebook
In-Reply-To: <53C94B51.5010901@arcor.de>
References: <53C89A64.10800@arcor.de> <lqaj8d$6e1$1@ger.gmane.org>
 <53C94B51.5010901@arcor.de>
Message-ID: <CAKK8jXaJUQJFd5CtxLV33==a7X5WRHidJsFysf-XiW6+T=nq8Q@mail.gmail.com>

On Fri, Jul 18, 2014 at 9:29 AM, Chris <ch2009 at arcor.de> wrote:

> On 07/18/2014 09:44 AM, Alan Gauld wrote:
> > Are you sure thats the version of Python you are running
> > in the virtualenv?
>
> I've modified the first line to #!./bin/python (instead of
> #!/usr/bin/python).
>
> Now, there's another error message:
>
> (facebook)[chris at cd facebook]$ ./fb1.py
> Traceback (most recent call last):
>   File "./fb1.py", line 6, in <module>
>     import facebook
>   File
> "/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py",
> line 811
>     args = {k: v for k, v in args.iteritems() if v is not None}
>                    ^
> SyntaxError: invalid syntax
>
>
Well, you've fixed your original problem - that the facebook module wasn't
in the path for the copy of Python you were running - and exchanged it for
another: a syntax error in the facebook module itself.  (Might be that the
module isn't compatible with the version of Python you're now running;
might be an actual problem with the module, but you'd think that would've
been caught before...)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140718/2435398f/attachment.html>

From fomcl at yahoo.com  Fri Jul 18 21:39:15 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Fri, 18 Jul 2014 12:39:15 -0700
Subject: [Tutor] Using module Facebook
Message-ID: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>



------------------------------
On Fri, Jul 18, 2014 7:47 PM CEST Marc Tompkins wrote:

>On Fri, Jul 18, 2014 at 9:29 AM, Chris <ch2009 at arcor.de> wrote:
>
>> On 07/18/2014 09:44 AM, Alan Gauld wrote:
>> > Are you sure thats the version of Python you are running
>> > in the virtualenv?
>>
>> I've modified the first line to #!./bin/python (instead of
>> #!/usr/bin/python).
>>
>> Now, there's another error message:
>>
>> (facebook)[chris at cd facebook]$ ./fb1.py
>> Traceback (most recent call last):
>>   File "./fb1.py", line 6, in <module>
>>     import facebook
>>   File
>> "/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py",
>> line 811
>>     args = {k: v for k, v in args.iteritems() if v is not None}
>>                    ^
>> SyntaxError: invalid syntax
>>

That' a dict comprehension and I am quite sure that those were introduced in Pyton 2.7. And you seem to be using v2.6

From rhce.san at gmail.com  Fri Jul 18 22:05:36 2014
From: rhce.san at gmail.com (Santosh Kumar)
Date: Sat, 19 Jul 2014 01:35:36 +0530
Subject: [Tutor] Modules to work with curl.
In-Reply-To: <CAGZAPF7Xw-6eo+STWAYPLEFSpAVffj_+AQ7ooRVSrvd-TH1qTg@mail.gmail.com>
References: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>
 <CAGZAPF7Xw-6eo+STWAYPLEFSpAVffj_+AQ7ooRVSrvd-TH1qTg@mail.gmail.com>
Message-ID: <CACHcGvmfNZNXu9Mi3W3+-Emc4WWdExJfz4S=tWCfiPhFP5tqQA@mail.gmail.com>

its a curl command caliing a http function.

for example:

curl <username>:<password> <xml> GET http://<somelink>/app/somefunction

so i have to use this to create a wrapper which can scale better . While i
use the subprocess it taking some time which i feel as bit slow.

so here are the questions again:
1) what are the different ways to run the above statement in a effective
way ?
2) How to improve the performance if any?

Thanks,
santosh



On Fri, Jul 18, 2014 at 12:45 AM, Danny Yoo <dyoo at hashcollision.org> wrote:

> On Thu, Jul 17, 2014 at 11:35 AM, Santosh Kumar <rhce.san at gmail.com>
> wrote:
>
> > I am currently working on a project , which has lots of curl commands. I
> am
> > using subprocess.Popen to run these curl commands. But somehow i see its
> bit
> > slow.
> > Is there a way/module by which i can improve the performance of the
> program.
>
>
> If the use of curl really is responsible and worthwhile to optimize,
> then you might consider using pycurl if you really need the full
> features of curl.
>
>     http://pycurl.sourceforge.net/
>
> But can you say more what you're doing with curl?  More information
> may let us give better advice.  The core lesson of
> http://www.cs.bell-labs.com/cm/cs/pearls/cto.html is always in my
> mind: we may not actually know the right question yet, so we must be
> careful about our answers, lest we mislead.
>
> I don't think we really understand the problem yet, so tell us more if you
> can.
>
> I would also recommend profiling if you haven't done so already.
> You've pointed out that something is slow, but unless you've actually
> measured what's really responsible, anything could be contributing.
> It may be, for example, that you're being limited by your network
> throughput, in which case trying to make your program go faster will
> not be effective.  You really must measure: otherwise, it's guesswork
> and crossed fingers.
>
> See:  https://docs.python.org/2/library/profile.html for documentation
> on Python profiling.
>



-- 
D. Santosh Kumar
RHCE | SCSA
+91-9703206361


Every task has a unpleasant side .. But you must focus on the end result
you are producing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140719/6ac2f0ea/attachment.html>

From dyoo at hashcollision.org  Fri Jul 18 22:50:04 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 18 Jul 2014 13:50:04 -0700
Subject: [Tutor] Modules to work with curl.
In-Reply-To: <CACHcGvmfNZNXu9Mi3W3+-Emc4WWdExJfz4S=tWCfiPhFP5tqQA@mail.gmail.com>
References: <CACHcGvmv5pDT_EyvzrgbYsimsc+k6fS=yMEP7h+Di7hPhnQPSA@mail.gmail.com>
 <CAGZAPF7Xw-6eo+STWAYPLEFSpAVffj_+AQ7ooRVSrvd-TH1qTg@mail.gmail.com>
 <CACHcGvmfNZNXu9Mi3W3+-Emc4WWdExJfz4S=tWCfiPhFP5tqQA@mail.gmail.com>
Message-ID: <CAGZAPF5wfxMmyfLC0YAhLmHfgjbVNGkKgPfuN2c+ZeSzAVv17Q@mail.gmail.com>

On Fri, Jul 18, 2014 at 1:05 PM, Santosh Kumar <rhce.san at gmail.com> wrote:
> its a curl command caliing a http function.
>
> for example:
>
> curl <username>:<password> <xml> GET http://<somelink>/app/somefunction

Hi Santosh,

Ok, good.  This is some of the information that we wanted to know.

So you are performing HTTP requests to get content, and you also need
to be able to provide username and password for authentication.
Sounds good so far.



> so i have to use this to create a wrapper which can scale better.

This actually doesn't follow from the requirement.  Let me explain.

You're fixated on using the "curl" shell command to do this task.  But
that's not the only way you can get the content of a URL from Python.
For example, Python's standard library includes a URL-downloading
library in urllib (https://docs.python.org/2/library/urllib.html)
which might work just as well as curl.


You're saying that you need to scale better.  In that case, you must
identify what exactly is causing that slowness.

To that end, please respond to Martin Brown's questions in this
thread.  You should try to address them, because I share those
questions too.


If you're just talking about a single HTTP request, for example, then
I don't see an obvious solution to speed up a single download besides
throwing more hardware and networking equipment at the problem.

But if we're talking about many HTTP requests at once, where the
current solution is getting each URL's content in a serial manner,
then perhaps some kind of concurrent solution will be appropriate.
(e.g. http://www.ibm.com/developerworks/aix/library/au-threadingpython/)
 But such a concurrent approach is only effective if you aren't
already saturating your network, and you're connecting to slow
servers, and... etc.  Those are the details that matter, the ones you
need to talk about and describe.

"Slowness" isn't sufficiently descriptive to let us give you technical
advice.  Please say more about the problem by answering Martin's
questions.


Good luck!

From dyoo at hashcollision.org  Fri Jul 18 23:04:44 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 18 Jul 2014 14:04:44 -0700
Subject: [Tutor] Using module Facebook
In-Reply-To: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
Message-ID: <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>

>>>
>>> Now, there's another error message:
>>>
>>> (facebook)[chris at cd facebook]$ ./fb1.py
>>> Traceback (most recent call last):
>>>   File "./fb1.py", line 6, in <module>
>>>     import facebook
>>>   File
>>> "/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py",
>>> line 811
>>>     args = {k: v for k, v in args.iteritems() if v is not None}
>>>                    ^
>>> SyntaxError: invalid syntax
>>>
>
> That' a dict comprehension and I am quite sure that those were introduced in Pyton 2.7. And you seem to be using v2.6


Yes, this unfortunately looks like the facebook-sdk folks are using
something that isn't in Python 2.6.  They say that their library
should be compatible with 2.6, according to:

    http://facebook-sdk.readthedocs.org/en/latest/install.html

but the dictionary comprehension used there is a Python 2.7 feature:

    https://docs.python.org/3.5/whatsnew/2.7.html#other-language-changes

And in this situation, you will want to send a ping to the
facebook-sdk folks: this is either considered a bug in the
documentation, or a bug in the implementation.  :P

From dyoo at hashcollision.org  Sat Jul 19 03:11:37 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 18 Jul 2014 18:11:37 -0700
Subject: [Tutor] Using module Facebook
In-Reply-To: <53C9BFA6.9070803@arcor.de>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
Message-ID: <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>

Hi Chris,


Wait.  There is one more possibility that I didn't account for: it may
be that somehow you haven't installed facebook-sdk, but you may have
installed some other package that is providing a facebook.py library.

I've was looking more closely at the source code to try to file a bug for you:

    https://github.com/pythonforfacebook/facebook-sdk/tree/master/facebook

but when I look again at the reported error message:

#################################################################
Traceback (most recent call last):
  File "./fb1.py", line 6, in <module>
    import facebook
  File
"/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py",
line 811
    args = {k: v for k, v in args.iteritems() if v is not None}
                   ^
SyntaxError: invalid syntax
#################################################################

As of this writing, I still can't find such a file or line in the facebook-sdk.


So that is very weird, right?


I have to consider the possibility, then, that the library file in:

     "/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py"

might not be the one provided by facebook-sdk: it sounds like it's
coming from Somewhere Else.



I'd like you to do two things:

1.  Can you put that file somewhere in a pastebin so that someone can
investigate where it comes from?

2.  Can you see if there's a directory called:

     "/home/chris/software/facebook/lib/python2.6/site-packages/facebook/"

Let us know if you see such a directory.

From dyoo at hashcollision.org  Sat Jul 19 03:26:35 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 18 Jul 2014 18:26:35 -0700
Subject: [Tutor] Using module Facebook
In-Reply-To: <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
Message-ID: <CAGZAPF4sYvhcqqUZdZr2XRfhKLgv+dAmtj=4ZFGdegHDDay4=g@mail.gmail.com>

> I've was looking more closely at the source code to try to file a bug for you:
>
>     https://github.com/pythonforfacebook/facebook-sdk/tree/master/facebook
>
> but when I look again at the reported error message:
>
> #################################################################
> Traceback (most recent call last):
>   File "./fb1.py", line 6, in <module>
>     import facebook
>   File
> "/home/chris/software/facebook/lib/python2.6/site-packages/facebook.py",
> line 811
>     args = {k: v for k, v in args.iteritems() if v is not None}
>                    ^
> SyntaxError: invalid syntax
> #################################################################
>
> As of this writing, I still can't find such a file or line in the facebook-sdk.


Hi Chris,

For the sake of reproducibility, let me show what I'm doing to search
for that in the repository, and show why I think the file you're
running is not a part of the one provided by the facebook-sdk package.

#############################################################
$ git clone https://github.com/pythonforfacebook/facebook-sdk.git
Cloning into 'facebook-sdk'...
remote: Reusing existing pack: 792, done.
remote: Total 792 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (792/792), 136.14 KiB | 0 bytes/s, done.
Resolving deltas: 100% (361/361), done.
Checking connectivity... done.
$ cd facebook-sdk/
$ git grep 'iteritems' $(git rev-list --all)
$
#############################################################

This is what piqued my concerns.  As you can see from the transcript,
the search shows that there's not a single use of 'iteritems' anywhere
in the facebook-sdk, across the entire history of that project.  And
yet the error message you're showing has a use of "args.iteritems()".
Therefore, there's a discrepancy there that needs to be explained.


Hope this helps!

From akleider at sonic.net  Sat Jul 19 03:33:04 2014
From: akleider at sonic.net (Alex Kleider)
Date: Fri, 18 Jul 2014 18:33:04 -0700
Subject: [Tutor] how to expand "../../myfile"
In-Reply-To: <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
Message-ID: <13d2ba91d849f009587cb078e210ca52@sonic.net>

Is there a function that can return the full path name when provided 
with something along the lines of
"../../myfile"?

Just to be able to glean the current working directory would suffice. (I 
could use a shell command if I had to but was hoping it could be done 
all within Python.

(python 2.7 on Ubuntu 12.4)

I've searched the os.path and glob modules to no avail.


From dyoo at hashcollision.org  Sat Jul 19 03:46:18 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Fri, 18 Jul 2014 18:46:18 -0700
Subject: [Tutor] how to expand "../../myfile"
In-Reply-To: <13d2ba91d849f009587cb078e210ca52@sonic.net>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <13d2ba91d849f009587cb078e210ca52@sonic.net>
Message-ID: <CAGZAPF5sLjZYWTvnBb0K9GG=mfPz-k4_U2iUd66_++ArtvkLNQ@mail.gmail.com>

On Fri, Jul 18, 2014 at 6:33 PM, Alex Kleider <akleider at sonic.net> wrote:
> Is there a function that can return the full path name when provided with
> something along the lines of
> "../../myfile"?
>
> Just to be able to glean the current working directory would suffice. (I
> could use a shell command if I had to but was hoping it could be done all
> within Python.

os.path.abspath() should be able to do it.  See:

    https://docs.python.org/2/library/os.path.html#os.path.abspath

    http://www.diveintopython.net/functional_programming/finding_the_path.html

From akleider at sonic.net  Sat Jul 19 04:51:02 2014
From: akleider at sonic.net (Alex Kleider)
Date: Fri, 18 Jul 2014 19:51:02 -0700
Subject: [Tutor] how to expand "../../myfile"
In-Reply-To: <CAGZAPF5sLjZYWTvnBb0K9GG=mfPz-k4_U2iUd66_++ArtvkLNQ@mail.gmail.com>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <13d2ba91d849f009587cb078e210ca52@sonic.net>
 <CAGZAPF5sLjZYWTvnBb0K9GG=mfPz-k4_U2iUd66_++ArtvkLNQ@mail.gmail.com>
Message-ID: <3e55a7d5a5017e10202087bf9fc88aac@sonic.net>

On 2014-07-18 18:46, Danny Yoo wrote:
> On Fri, Jul 18, 2014 at 6:33 PM, Alex Kleider <akleider at sonic.net> 
> wrote:
>> Is there a function that can return the full path name when provided 
>> with
>> something along the lines of
>> "../../myfile"?
>> 
>> Just to be able to glean the current working directory would suffice. 
>> (I
>> could use a shell command if I had to but was hoping it could be done 
>> all
>> within Python.
> 
> os.path.abspath() should be able to do it.  See:
> 
>     https://docs.python.org/2/library/os.path.html#os.path.abspath
> 
>     
> http://www.diveintopython.net/functional_programming/finding_the_path.html

Just what I wanted. (Don't know how I missed it.)  Thank you very much.
alex

From alan.gauld at btinternet.com  Sat Jul 19 08:44:52 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 19 Jul 2014 07:44:52 +0100
Subject: [Tutor] how to expand "../../myfile"
In-Reply-To: <13d2ba91d849f009587cb078e210ca52@sonic.net>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <13d2ba91d849f009587cb078e210ca52@sonic.net>
Message-ID: <lqd454$fqj$1@ger.gmane.org>

On 19/07/14 02:33, Alex Kleider wrote:

> Just to be able to glean the current working directory would suffice.

os.getcwd()

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From ch2009 at arcor.de  Sat Jul 19 02:45:26 2014
From: ch2009 at arcor.de (Chris)
Date: Sat, 19 Jul 2014 02:45:26 +0200
Subject: [Tutor] Using module Facebook
In-Reply-To: <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
Message-ID: <53C9BFA6.9070803@arcor.de>

On 07/18/2014 11:04 PM, Danny Yoo wrote:
> Yes, this unfortunately looks like the facebook-sdk folks are using
> something that isn't in Python 2.6.  They say that their library
> should be compatible with 2.6, according to:

Albert-Jan and Danny, thank you very much. That's a bug I wouldn't have
found as beginner, especially since I've read in the documentation the
sdk would be compatible with 2.6. Now, I'm trying to install Python 2.7
on CentOS. Unfortunately, there's no RPM-package available so I'll try
to compile and install it manually.

-- 
Christian

From glen at glenjarvis.com  Sat Jul 19 06:42:23 2014
From: glen at glenjarvis.com (Glen Jarvis)
Date: Fri, 18 Jul 2014 21:42:23 -0700
Subject: [Tutor] how to expand "../../myfile"
In-Reply-To: <13d2ba91d849f009587cb078e210ca52@sonic.net>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <13d2ba91d849f009587cb078e210ca52@sonic.net>
Message-ID: <CA+UBrj7XhzyDD=UEhoS6CwvKkic1u24AxHcA+Ck3WZYen3LsFw@mail.gmail.com>

On Fri, Jul 18, 2014 at 6:33 PM, Alex Kleider <akleider at sonic.net> wrote:

> Is there a function that can return the full path name when provided with
> something along the lines of
> "../../myfile"?
>

The OS module is great at this. Here's an example:

import os

MYFILE= '../../myfile'

print "MYFILE", MYFILE

print "abspath", os.path.abspath(MYFILE)


And, here is the output:

prompt> python example01.py

MYFILE ../../myfile

abspath /Users/glenjarvis/Desktop/test/myfile


>
> Just to be able to glean the current working directory would suffice. (I
> could use a shell command if I had to but was hoping it could be done all
> within Python.
>

You can also glean just the current working directory:

import os

print "pwd", os.getcwd()


And it's output:

prompt> python example02.py

pwd /Users/glenjarvis/Desktop/test/x/y


Cheers,


Glen
-- 

"You grab mindshare by being there."

-- Alex Martelli

   Bay Area Python Interest Group Talk

   24-Oct, 2013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140718/63f72a7a/attachment.html>

From akleider at sonic.net  Sat Jul 19 09:38:58 2014
From: akleider at sonic.net (Alex Kleider)
Date: Sat, 19 Jul 2014 00:38:58 -0700
Subject: [Tutor] how to expand "../../myfile"
In-Reply-To: <lqd454$fqj$1@ger.gmane.org>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <13d2ba91d849f009587cb078e210ca52@sonic.net> <lqd454$fqj$1@ger.gmane.org>
Message-ID: <5e1f017039ee5b6c64af619bc67703a5@sonic.net>

On 2014-07-18 23:44, Alan Gauld wrote:
> On 19/07/14 02:33, Alex Kleider wrote:
> 
>> Just to be able to glean the current working directory would suffice.
> 
> os.getcwd()

solutions are tumbling from the sky!
Thank you, Alan.
alex

From lnartist at yahoo.com  Sat Jul 19 23:27:27 2014
From: lnartist at yahoo.com (LN A-go-go)
Date: Sat, 19 Jul 2014 14:27:27 -0700
Subject: [Tutor] Read, Write, Split and Append lines from a text file
Message-ID: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>

????????????
I have given it all I got: a week trying to open, read, write, split, append, convert to integers and then manipulate the data.? I have attached the file I want to pull the names and numbers from.? I'll cut and paste it incase that doesn't work and then include a sample of the python shell code.? 

AK?36
AL?39
AR?39
AZ?45
CA?61
CO?54
CT?61
DC?93
DE?62
FL?51
GA?47
HI?72
IA?54
ID?36
IL?62
IN?50
KS?41
KY?41
LA?40
MA?62
MD?62
ME?58
MI?57
MN?54
MO?49
MS?43
MT?47
NC?50
ND?45
NE?41
NH?54
NJ?57
NM?57
NV?55
NY?62
OH?51
OK?34
OR?57
PA?55
RI?63
SC?45
SD?45
TN?42
TX?44
UT?34
VA?53
VT?67
WA?58
WI?56
WV?43
WY?33

# and now my newbie attempt:
# I can get this far in approach #1
>>> filename = "z:/Geog482/egund919/Program1/BOJ.txt"
>>> myfile = open(filename,"r")
>>> newfile = "z:/Geog482/egund919/Program1/BOJ_B.txt"
>>> mynewfile = open(newfile,"w")
>>> while True:
?line = myfile.readline()
?print line
?mynewfile.write(line)
?if not line: break
?
States?OJ
AK?36
AL?39
AR?39
AZ?45
CA?61
CO?54
CT?61
DC?93
DE?62
FL?51
GA?47
HI?72
IA?54
ID?36
IL?62
IN?50
KS?41
KY?41
LA?40
MA?62
MD?62
ME?58
MI?57
MN?54
MO?49
MS?43
MT?47
NC?50
ND?45
NE?41
NH?54
NJ?57
NM?57
NV?55
NY?62
OH?51
OK?34
OR?57
PA?55
RI?63
SC?45
SD?45
TN?42
TX?44
UT?34
VA?53
VT?67
WA?58
WI?56
WV?43
WY?33


In approach number 2: trying to append, convert to integer, but the list comes up empty:

>>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
>>> import string
>>> state_name = []
>>> data_value = []
>>> counter = 0
>>> x = 0
>>> line = infile.readline()
>>> while True:
???????????? ?line = infile.readline()
???????????? ?if not line: break
????????????? counter = counter + 1
????????????? States, OJ = string.split(line)
????????????? XSTATES = str(States)
???????????? ?XNUM = int(OJ)
??????????????state_name.append(XSTATES)
???????????? ?data_value.append(XNUM)
?
>>> type(data_value)
<type 'list'>
>>> print(data_value)
[]
>>> print (line)


All I get is errors from here on out.....


LN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140719/eaa95dbb/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: BOJ.txt
URL: <http://mail.python.org/pipermail/tutor/attachments/20140719/eaa95dbb/attachment.txt>

From jslozier at gmail.com  Sun Jul 20 01:59:11 2014
From: jslozier at gmail.com (Jay Lozier)
Date: Sat, 19 Jul 2014 19:59:11 -0400
Subject: [Tutor] Read, Write, Split and Append lines from a text file
In-Reply-To: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
References: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
Message-ID: <53CB064F.30902@gmail.com>

An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140719/bd6515f7/attachment-0001.html>

From breamoreboy at yahoo.co.uk  Sun Jul 20 02:56:12 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Sun, 20 Jul 2014 01:56:12 +0100
Subject: [Tutor] Read, Write, Split and Append lines from a text file
In-Reply-To: <53CB064F.30902@gmail.com>
References: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
 <53CB064F.30902@gmail.com>
Message-ID: <lqf438$a7d$2@ger.gmane.org>

On 20/07/2014 00:59, Jay Lozier wrote:
> Please include the complete stack trace error message
>
> It will help in determining what the error is.
>
> Jay
>
> --
> Jay Lozier
> jslozier at gmail.com
>

Please don't top post here.  Did you have to include the entire message 
just to include a two sentence reply?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From dyoo at hashcollision.org  Sun Jul 20 03:57:01 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sat, 19 Jul 2014 18:57:01 -0700
Subject: [Tutor] Read, Write, Split and Append lines from a text file
In-Reply-To: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
References: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
Message-ID: <CAGZAPF5=2NnQwf7NkQzkpfOiKqM_iRvOD583VYjbzo4JnREAHQ@mail.gmail.com>

On Sat, Jul 19, 2014 at 2:27 PM, LN A-go-go
<lnartist at yahoo.com.dmarc.invalid> wrote:
>
>
> I have given it all I got: a week trying to open, read, write, split, append, convert to integers and then manipulate the data.  I have attached the file I want to pull the names and numbers from.  I'll cut and paste it incase that doesn't work and then include a sample of the python shell code.
>

[cut]

Sounds good so far.

> # and now my newbie attempt:
> # I can get this far in approach #1
> >>> filename = "z:/Geog482/egund919/Program1/BOJ.txt"
> >>> myfile = open(filename,"r")
> >>> newfile = "z:/Geog482/egund919/Program1/BOJ_B.txt"
> >>> mynewfile = open(newfile,"w")
> >>> while True:
>  line = myfile.readline()
>  print line
>  mynewfile.write(line)
>  if not line: break


After you have written all these lines to 'newfile', did you call
close() on "newfile"?  I was expecting:

    mynewfile.close()

at the end of this block; the fact that it's missing looks unusual to me.

It may matter.  File buffering may prevent another read of the file
from seeing the output you've written until the file has been
committed to disk.



> In approach number 2: trying to append, convert to integer, but the list comes up empty:

Given the logic of the block, there are a few ways that the data_value
may be empty.  Let's take a look at it again.

    infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
    # ...
    data_value = []
    # ...
    while True:
        line = infile.readline()
        if not line: break
        # some content cut
        data_value.append(...)

I've omitted all but what I think is essential for analyzing this
problem.  I believe that the only way that data_value can be empty,
given the control flow of this program, if is the infile.readline()
returns a false value.  The suggestion above about making sure the
file has been committed to disk is meant to address this possibility.


By the way, the looping over the file, using readline(), is
stylistically unusual.  Files are "iterable": they can be used in for
loops directly.  That is, the block:

    infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
    while True:
        line = infile.readline()
        ...

can be written as:

    infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
    for line in infile:
        ...

and in general, this is preferable to the explicit readline() approach
you're using to iterate over the lines of a file.

From davea at davea.name  Sun Jul 20 04:08:37 2014
From: davea at davea.name (Dave Angel)
Date: Sat, 19 Jul 2014 21:08:37 -0500 (CDT)
Subject: [Tutor] Read, Write, Split and Append lines from a text file
References: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
Message-ID: <lqf8b7$u88$1@ger.gmane.org>

LN A-go-go <lnartist at yahoo.com.dmarc.invalid> Wrote in message:


By trying to include an attachment,  you make it impossible for me
 to quote your actual message. Please use plain text message
 without attachments,  to maximize the number of people that can
 read and readily respond. 


> States	OJ
> AK	36
> AL	39
> AR	39
> AZ	45

5 lines should be enough to get the idea.

You don't specify the environment,  so I'll have to assume Python
 3.x. And it is likely Windows since you use x: as though it were
 part of the path.

>  You'll have to pretend this is properly quoted.

?????????????

 and now my newbie attempt:
# I can get this far in approach #1
>>> filename = "z:/Geog482/egund919/Program1/BOJ.txt"
>>> myfile = open(filename,"r")
>>> newfile = "z:/Geog482/egund919/Program1/BOJ_B.txt"
>>> mynewfile = open(newfile,"w")
>>> while True:
 line = myfile.readline()
 print
 line
 mynewfile.write(line)
 if not line: break
 
???????????

print by itself is a no-op. If you had included the parentheses, 
 it'd at least produce a blank line.

line by itself is also a no-op. What were you trying to do with
 the variable? 

You neglected to close either of the files. Won't probably matter
 here, but it will someday.  Best get the habit now.

Just what was the point of this fragment?  In what way did it fall
 short, other than having two no-ops in it?

You have a different fragment with other apparent problems.  But
 you never spell out the problem. 

-- 
DaveA


From alan.gauld at btinternet.com  Sun Jul 20 10:16:40 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 20 Jul 2014 09:16:40 +0100
Subject: [Tutor] Read, Write, Split and Append lines from a text file
In-Reply-To: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
References: <1405805247.36981.YahooMailNeo@web161303.mail.bf1.yahoo.com>
Message-ID: <lqftt9$5j8$1@ger.gmane.org>

On 19/07/14 22:27, LN A-go-go wrote:

> AK 36
> AL 39
> AR 39
> AZ 45
> CA 61
> CO 54
>
> # and now my newbie attempt:
> # I can get this far in approach #1
>  >>> filename = "z:/Geog482/egund919/Program1/BOJ.txt"
>  >>> myfile = open(filename,"r")
>  >>> newfile = "z:/Geog482/egund919/Program1/BOJ_B.txt"
>  >>> mynewfile = open(newfile,"w")
>  >>> while True:
>   line = myfile.readline()
>   print line
>   mynewfile.write(line)
>   if not line: break


>
> States OJ
> AK 36

Assuming this is the output... where does the first
line come from?
Its not in your data above and you don't print it?
So either your data is not the real data or the code
is not the real code.
Either case makes it difficult for us to work out what is
really going on.

> UT 34
> VA 53
> VT 67
> WA 58
> WI 56
> WV 43
> WY 33

If this is the output what exactly is "wrong" with it?
Apart from the first line anomaly it looks exactly like
what I'd expect.

> In approach number 2: trying to append, convert to integer, but the list
> comes up empty:
>
>  >>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
>  >>> import string

Don't import string. Use the string methods instead.

>  >>> state_name = []
>  >>> data_value = []
>  >>> counter = 0
>  >>> x = 0
>  >>> line = infile.readline()
>  >>> while True:
>                line = infile.readline()
>                if not line: break

It would be easier to use enumerate and a for loop:

for counter, line in enumerate(infile):

>                counter = counter + 1
>                States, OJ = string.split(line)
>                XSTATES = str(States)
>                XNUM = int(OJ)

By convention all caps means a constant value. These obviously
change so it would be better to name them xstates and xnum.
Also since there is only one state per line it should be
xstate rather than xstates. Just minor style points.

>                state_name.append(XSTATES)
>                data_value.append(XNUM)

You could use a dictionary here instead of two lists.

states = dict()
for counter,line in ....
     ...
     states[xtstate] = xnum

>  >>> type(data_value)
> <type 'list'>
>  >>> print(data_value)
> []

This suggests your loop exited on the first iteration.
Is there a blank line at the start of the file?
This is another reason why using a for loop is better,
it wouldn't get caught out that way.


>  >>> print (line)
>
> All I get is errors from here on out.....

Tell us what the errors are. If they are actual Python
error messages then show us the full error message - it
is full of useful data. If they are just errors in the
sense that they are not what you expected, then tell us
what you expected and show us what you got.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From ch2009 at arcor.de  Sun Jul 20 18:16:20 2014
From: ch2009 at arcor.de (Chris)
Date: Sun, 20 Jul 2014 18:16:20 +0200
Subject: [Tutor] Using module Facebook
In-Reply-To: <CAGZAPF4sYvhcqqUZdZr2XRfhKLgv+dAmtj=4ZFGdegHDDay4=g@mail.gmail.com>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <CAGZAPF4sYvhcqqUZdZr2XRfhKLgv+dAmtj=4ZFGdegHDDay4=g@mail.gmail.com>
Message-ID: <53CBEB54.2060602@arcor.de>

Dear Danny,

thank you for your detailed reply.

On 07/19/2014 03:26 AM, Danny Yoo wrote:
> This is what piqued my concerns.  As you can see from the transcript,
> the search shows that there's not a single use of 'iteritems' anywhere
> in the facebook-sdk, across the entire history of that project.  And
> yet the error message you're showing has a use of "args.iteritems()".
> Therefore, there's a discrepancy there that needs to be explained.

I'm not sure, what the error was. I had also installed another facebook
package, not facebook-sdk. Maybe this was the reason. I've deleted the
directory, upgraded to Python 2.7 and reinstalled facebook:

git clone "https://github.com/pythonforfacebook/facebook-sdk"
pip install facebook-sdk

Now, accessing the facebook API is working.

-- 
Christian

From lnartist at yahoo.com  Sun Jul 20 17:40:48 2014
From: lnartist at yahoo.com (LN A-go-go)
Date: Sun, 20 Jul 2014 08:40:48 -0700
Subject: [Tutor] (no subject)
Message-ID: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>

My apologies Python Gurus for repeating this request for read, write, split and append from a text file in notepad.? I worked on it till late last night and will again today.? I can't seem to get past trying to write the names to one list and the numbers (converted to integers)?to the other.? My lists come up empty.

I am a full-time firefighter?that taught myself to use ArcGIS to make maps and now am in school so I can move into emergency mgmt.? I can't seem to teach myself Python and I am really trying.
thank-you,

LN


>>> filename = "C:/Python27/egund919/Program1/BOJ.txt"
>>> myfile = open(filename,"r")
>>> newfile = "C:/Python27/egund919/Program1/BOJ_B.txt"
>>> mynewfile = open(newfile,"w")
>>> while True:
?line = myfile.readline()
?print line
?mynewfile.write(line)
?if not line: break
?
States?OJ
AK?36
AL?39
AR?39
AZ?45
CA?61
CO?54
CT?61
DC?93
DE?62
FL?51
GA?47
HI?72
IA?54
ID?36
IL?62
IN?50
KS?41
KY?41
LA?40
MA?62
MD?62
ME?58
MI?57
MN?54
MO?49
MS?43
MT?47
NC?50
ND?45
NE?41
NH?54
NJ?57
NM?57
NV?55
NY?62
OH?51
OK?34
OR?57
PA?55
RI?63
SC?45
SD?45
TN?42
TX?44
UT?34
VA?53
VT?67
WA?58
WI?56
WV?43
WY?33

>>> myfile.close()
>>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
>>> import string
>>> state_name = []
>>> data_value = []
>>> counter = 0
>>> x = 0
>>> line = infile.readline()
>>> while True:
????????????? line = infile.readline()
????????????? if not line: break
??????????????counter = counter + 1
????????????? States, OJ = string.split(line)
????????????? XSTATES = str(States)
????????????? XNUM = int(OJ)
????????????? state_name.append(XSTATES)
????????????? data_value.append(XNUM)
?
>>> len(counter)
Traceback (most recent call last):
? File "<pyshell#29>", line 1, in <module>
??? len(counter)
TypeError: object of type 'int' has no len()
>>> counter.count
Traceback (most recent call last):
? File "<pyshell#30>", line 1, in <module>
??? counter.count
AttributeError: 'int' object has no attribute 'count'
>>> len(state_name)
0
>>> list.state_name
Traceback (most recent call last):
? File "<pyshell#32>", line 1, in <module>
??? list.state_name
AttributeError: type object 'list' has no attribute 'state_name' 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140720/6af80c0a/attachment.html>

From fomcl at yahoo.com  Sun Jul 20 21:48:27 2014
From: fomcl at yahoo.com (Albert-Jan Roskam)
Date: Sun, 20 Jul 2014 12:48:27 -0700
Subject: [Tutor] Using module Facebook
Message-ID: <1405885707.57493.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>


-----------------------------
On Sun, Jul 20, 2014 6:16 PM CEST Chris wrote:

>Dear Danny,
>
>thank you for your detailed reply.
>
>On 07/19/2014 03:26 AM, Danny Yoo wrote:
>> This is what piqued my concerns.  As you can see from the transcript,
>> the search shows that there's not a single use of 'iteritems' anywhere
>> in the facebook-sdk, across the entire history of that project.  And
>> yet the error message you're showing has a use of "args.iteritems()".
>> Therefore, there's a discrepancy there that needs to be explained.
>
>I'm not sure, what the error was. I had also installed another facebook
>package, not facebook-sdk. Maybe this was the reason. I've deleted the
>directory, upgraded to Python 2.7 and reinstalled facebook:
>
>git clone "https://github.com/pythonforfacebook/facebook-sdk"
>pip install facebook-sdk
>
>Now, accessing the facebook API is working.

Hi, just wondering: why are you cloning the repo? You pip install from Pypi.  You can also pip install from the repo. 


From dyoo at hashcollision.org  Sun Jul 20 22:17:49 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 20 Jul 2014 13:17:49 -0700
Subject: [Tutor] Using module Facebook
In-Reply-To: <53CBEB54.2060602@arcor.de>
References: <1405712355.82200.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
 <CAGZAPF45ri=sS53EFK_DXXpFU9A2DsdP4khW_4rfpws9OYqG9A@mail.gmail.com>
 <53C9BFA6.9070803@arcor.de>
 <CAGZAPF7E0SvwF_E8zK3iCY7emQ_CvyiwEJDhcsGcE-DBYRdiEw@mail.gmail.com>
 <CAGZAPF4sYvhcqqUZdZr2XRfhKLgv+dAmtj=4ZFGdegHDDay4=g@mail.gmail.com>
 <53CBEB54.2060602@arcor.de>
Message-ID: <CAGZAPF7t3xGaTg9-zG7ogujnwTp4MMdFM+N=aZpdQzZqY0g6gw@mail.gmail.com>

> I'm not sure, what the error was. I had also installed another facebook
> package, not facebook-sdk. Maybe this was the reason.

I would upgrade that "maybe" to an "almost certainly".  :P

You should have mentioned that detail of installing that second
facebook library.  It's actually crucial to explaining the bizarre
behavior we were seeing.  We should revisit the claim made earlier
that facebook-sdk doesn't support Python 2.6.  In retrospect, it
probably does!


Let's summarize the situation, since there was some confusion leading
up to your solution.

----------------

1.  You initially had some difficulty because your script was using
the system-installed version of Python, rather than the
virtualenv-installed one.  You corrected the shebang line to refer to
the virtualenv-installed version.

2.  You installed two different Facebook libraries, and unfortunately
one of them uses the same name as the other, effectively shadowing the
official one from facebook-sdk.

3.  The Facebook library that you were using on accident required Python 2.7.

4.  You upgraded to Python 2.7.  Effectively, this created a fresh
installation with no third-party libraries.

5.  You installed only the single Facebook library from facebook-sdk
into your Python 2.7 installation.

----------------

In light of this, reinstalling Python 2.7 might have been slightly
overkill.  But that being said, it's probably for the best that you're
on Python 2.7, since it's the one that the majority of Python 2 users
are using now.

From dyoo at hashcollision.org  Sun Jul 20 22:31:31 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 20 Jul 2014 13:31:31 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
Message-ID: <CAGZAPF7mmozu-PWGdVE23XU_6bKACshTfeGdUuiUTy1V4w1DJQ@mail.gmail.com>

On Sun, Jul 20, 2014 at 8:40 AM, LN A-go-go
<lnartist at yahoo.com.dmarc.invalid> wrote:
> My apologies Python Gurus for repeating this request for read, write, split
> and append from a text file in notepad.  I worked on it till late last night
> and will again today.  I can't seem to get past trying to write the names to
> one list and the numbers (converted to integers) to the other.  My lists
> come up empty.


That's fine, but please also respond to the replies you're getting
too.  Rather than start a whole new thread, try to continue the thread
by using your email client's "Reply to All" feature.  Also, feel free
to treat this as a conversation: if there's anything about the replies
that use terms you don't understand, ask, and we'll try to clarify.

Looking closely at your revised program, I see that you've added a
file close.  Unfortunately, you closed the wrong file.  :P

Effectively, you've written:

    myfile = open(filename,"r")
    mynewfile = open(newfile,"w")
    ## writing into mynewfile
    myfile.close()

but you needed to have done:

    myfile = open(filename,"r")
    mynewfile = open(newfile,"w")
    ## writing into mynewfile
    mynewfile.close()


It also appears that you are trying to write whole programs at the
interpreter loop.  This can be inconvenient for larger programs.  You
might want to use a text editor or IDE to write the program as a
single file, and then run Python over that program file.

From dyoo at hashcollision.org  Sun Jul 20 22:36:14 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 20 Jul 2014 13:36:14 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <CAGZAPF7mmozu-PWGdVE23XU_6bKACshTfeGdUuiUTy1V4w1DJQ@mail.gmail.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAGZAPF7mmozu-PWGdVE23XU_6bKACshTfeGdUuiUTy1V4w1DJQ@mail.gmail.com>
Message-ID: <CAGZAPF70BpL-rhxVrUTtMeB5mrvNscAt_zc2FGgKNT7j6_-ARQ@mail.gmail.com>

> It also appears that you are trying to write whole programs at the
> interpreter loop.  This can be inconvenient for larger programs.  You
> might want to use a text editor or IDE to write the program as a
> single file, and then run Python over that program file.

See:

    https://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/

for a quick tutorial on using IDLE to write Python programs.  The
tutorial assumes Python 2, which you appear to be using.

From marc.tompkins at gmail.com  Sun Jul 20 22:37:57 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 20 Jul 2014 13:37:57 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
Message-ID: <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>

On Sun, Jul 20, 2014 at 8:40 AM, LN A-go-go
<lnartist at yahoo.com.dmarc.invalid> wrote:

>
> States OJ
> AK 36
> AL 39
> AR 39
> AZ 45
> CA 61
> CO 54
> CT 61
> DC 93
> DE 62
> FL 51
> GA 47
> HI 72
> IA 54
> ID 36
> IL 62
> IN 50
> KS 41
> KY 41
> LA 40
> MA 62
> MD 62
> ME 58
> MI 57
> MN 54
> MO 49
> MS 43
> MT 47
> NC 50
> ND 45
> NE 41
> NH 54
> NJ 57
> NM 57
> NV 55
> NY 62
> OH 51
> OK 34
> OR 57
> PA 55
> RI 63
> SC 45
> SD 45
> TN 42
> TX 44
> UT 34
> VA 53
> VT 67
> WA 58
> WI 56
> WV 43
> WY 33
>
> >>> myfile.close()
> >>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')
> >>> import string
> >>> state_name = []
> >>> data_value = []
> >>> counter = 0
> >>> x = 0
> >>> line = infile.readline()
> >>> while True:
>               line = infile.readline()
>               if not line: break
>               counter = counter + 1
>               States, OJ = string.split(line)
>               XSTATES = str(States)
>               XNUM = int(OJ)
>               state_name.append(XSTATES)
>               data_value.append(XNUM)
>
> >>> len(counter)
> Traceback (most recent call last):
>   File "<pyshell#29>", line 1, in <module>
>     len(counter)
> TypeError: object of type 'int' has no len()
> >>> counter.count
> Traceback (most recent call last):
>   File "<pyshell#30>", line 1, in <module>
>     counter.count
> AttributeError: 'int' object has no attribute 'count'
> >>> len(state_name)
> 0
> >>> list.state_name
> Traceback (most recent call last):
>   File "<pyshell#32>", line 1, in <module>
>     list.state_name
> AttributeError: type object 'list' has no attribute 'state_name'
>

First of all, I would take advantage of the "with" construction, like so:

with open('C:/Python27/egund919/Program1/BOJ_B.txt','r') as infile:
    #do stuff with infile

When the block of code inside of the "with" section finishes, Python
will take care of closing the file for you - even if your program
encountered an error.  MAJOR advantage over doing it yourself.

Second, there's no need to import "string" anymore; all of the
functions defined in that module are native methods of strings.
"line" is a string, so you can just do "line.split()".  split()
returns a list; you can get the first item in that list with
line.split()[0], the second item with line.split()[1], etc.

Third, free your mind from the shackles of counting how many objects
are in a list and using that counter as the index of your loops - this
is not the Python way!  Instead, let Python take care of the counting
and indexing for you.

Fourth (and here I differ from some of the others on this list,
notably Alan G) - I don't like the "while True: / break" paradigm.
Your mileage may vary, but I find it makes it harder to understand
what the program is actually trying to achieve.  In your case, you
read a line from the file, then check whether it contains anything; I
like to move the readline() to the bottom of the loop.

Having said all that, here's my suggested version:

state_name = []
data_value = []
with open('C:/Python27/egund919/Program1/BOJ_B.txt','r') as infile:
    line = infile.readline()  # Doing this twice because you
apparently want to discard the first line...?
    line = infile.readline()
    while line:
        state_name.append(line.split()[0])
        data_value.append(line.split()[1])
        line = infile.readline()
print(state_name)
print(data_value)

From alan.gauld at btinternet.com  Sun Jul 20 23:37:42 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sun, 20 Jul 2014 22:37:42 +0100
Subject: [Tutor] (no subject)
In-Reply-To: <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
Message-ID: <lqhcr6$np5$1@ger.gmane.org>

On 20/07/14 21:37, Marc Tompkins wrote:

> Fourth (and here I differ from some of the others on this list,
> notably Alan G) - I don't like the "while True: / break" paradigm.

FWIW I don't like it either, but it has become a canonical
Python idiom.

In fact in this case I suggested he use a for loop to iterate over
the file and use a dictionary to store the results...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From keithadu at live.com  Sun Jul 20 22:57:24 2014
From: keithadu at live.com (keith papa)
Date: Sun, 20 Jul 2014 16:57:24 -0400
Subject: [Tutor] Is this possible for a newbie?
Message-ID: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>

Am a newbie to programming and I started learning python days ago. I have this idea I want to execute, am a big sport and fantasy fan and I wanted to create something that will make it things a little easy for me. My idea is simple I want to create a program that I can enter name and some information about a player, for example: 

NFL plays:

Jamaal Charles RB : ATT 259 , YDS 1,287 , AVG 5.0, TD 12, REC 70

Tony Romo QB: CMP% 63.9, YDS 3,828 , TD 31, INT 10, Rating 96.7

Dez Bryant WR: REC 93, YDS 1,233, AVG 13.3, LNG 79, TD 13

and other players information.

I want to be able to ask the program which QB is best on my list and it give me the names of all the QB on my list, or ask for WR on my list and it gives me all the WR on my list, and also I want to be able to crossed out name simply by typing the players name.
What do I need to lean in order to accomplish this? string, variable functions?
feel free to ask any questions. 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140720/59dd0439/attachment.html>

From wolfgang.maier at biologie.uni-freiburg.de  Sun Jul 20 21:49:41 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Sun, 20 Jul 2014 21:49:41 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
Message-ID: <53CC1D55.8090009@biologie.uni-freiburg.de>

On 20.07.2014 17:40, LN A-go-go wrote:
>
>  >>> filename = "C:/Python27/egund919/Program1/BOJ.txt"
>  >>> myfile = open(filename,"r")
>  >>> newfile = "C:/Python27/egund919/Program1/BOJ_B.txt"
>  >>> mynewfile = open(newfile,"w")
>  >>> while True:
>   line = myfile.readline()
>   print line
>   mynewfile.write(line)
>   if not line: break
>
> States OJ
> AK 36
> AL 39
> AR 39
> AZ 45
> CA 61

..

>
>  >>> myfile.close()

Closing the file you've read from is good, but not nearly as important 
as closing the file you've been writing to.

>  >>> infile = open('C:/Python27/egund919/Program1/BOJ_B.txt','r')

There's your problem ! You didn't close mynewfile before opening the 
file again for reading. Most likely, what you thought you've written to 
the file is still buffered in memory. The main purpose of closing a file 
after writing is to flush the contents of this buffer to disk.
Try mynewfile.close() just before infile = open ..

Best,
Wolfgang


From wolfgang.maier at biologie.uni-freiburg.de  Sun Jul 20 23:47:25 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Sun, 20 Jul 2014 23:47:25 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
Message-ID: <53CC38ED.40404@biologie.uni-freiburg.de>

On 20.07.2014 22:37, Marc Tompkins wrote:
>
> First of all, I would take advantage of the "with" construction, like so:
>
> with open('C:/Python27/egund919/Program1/BOJ_B.txt','r') as infile:
>      #do stuff with infile
>
> When the block of code inside of the "with" section finishes, Python
> will take care of closing the file for you - even if your program
> encountered an error.  MAJOR advantage over doing it yourself.
>

Yes, definitely, as you have experienced yourself now.

> Second, there's no need to import "string" anymore; all of the
> functions defined in that module are native methods of strings.
> "line" is a string, so you can just do "line.split()".  split()
> returns a list; you can get the first item in that list with
> line.split()[0], the second item with line.split()[1], etc.
>

I fully agree on the string method part. As for the use of 
line.split()[0] and [1], see my comment in the code below.

> Third, free your mind from the shackles of counting how many objects
> are in a list and using that counter as the index of your loops - this
> is not the Python way!  Instead, let Python take care of the counting
> and indexing for you.
>

True (see the earlier suggestion of using enumerate()), but I'm sure 
you'll learn this over time.

> Fourth (and here I differ from some of the others on this list,
> notably Alan G) - I don't like the "while True: / break" paradigm.
> Your mileage may vary, but I find it makes it harder to understand
> what the program is actually trying to achieve.  In your case, you
> read a line from the file, then check whether it contains anything; I
> like to move the readline() to the bottom of the loop.

In my opinion, this is less readable than the original code. I know that 
some people (usually coming from C or other languages with more 
expressive while loops) don't like it, but there's nothing wrong, in 
general, with using while True with break. It's perfectly pythonic.

Direct use of the file object in a for loop has been suggested already 
and THAT's more readable.

>
> Having said all that, here's my suggested version:
>
> state_name = []
> data_value = []
> with open('C:/Python27/egund919/Program1/BOJ_B.txt','r') as infile:
>      line = infile.readline()  # Doing this twice because you
> apparently want to discard the first line...?
>      line = infile.readline()
>      while line:
>          state_name.append(line.split()[0])
>          data_value.append(line.split()[1])

Rewriting the original

            States, OJ = string.split(line)

as

            states, oj = line.split()

is better (and it's remarkable that you used it as a beginner). This 
line unpacks the elements of the list returned by the split method into 
the two variables on the left side.
Besides avoiding repetitive calls to line.split(), it may also help you 
discover problems with your input file format. If there are more than 
two elements in the list, you'll get an error, so you'll know there was 
something in the file you didn't expect. With the line.split()[0] / [1] 
approach, potential other elements in the list (i.e. unexpected line 
content) will be ignored silently.
Once you've learnt that errors in Python are nothing evil, but there to 
help you and once you've read about try/except to catch them, you'll 
appreciate the advantage of the first version.

>          line = infile.readline()

I don't see why repeating infile.readline() three times should be more 
elegant than a nice and clean while True / break.

> print(state_name)
> print(data_value)



From alan.gauld at btinternet.com  Mon Jul 21 01:24:54 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 21 Jul 2014 00:24:54 +0100
Subject: [Tutor] Is this possible for a newbie?
In-Reply-To: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>
References: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>
Message-ID: <lqhj47$3qv$1@ger.gmane.org>

On 20/07/14 21:57, keith papa wrote:

> me. My idea is simple I want to create a program that I can enter name
> and some information about a player, for example:
>
>
> NFL plays:
> Jamaal Charles RB : ATT 259 , YDS 1,287 , AVG 5.0, TD 12, REC 70
> Tony Romo QB: CMP% 63.9, YDS 3,828 , TD 31, INT 10, Rating 96.7
> Dez Bryant WR: REC 93, YDS 1,233, AVG 13.3, LNG 79, TD 13
> and other players information.

Thus far its easy.

> I want to be able to ask the program whichQB is best on my list and it
> give me the names of all the QB on my list,

Really? I'd have thought you wanted only the 'best' one - however you 
define best...

> or ask for WR on my list and it gives me all the WR on my list,

This is easier

> and also I want to be able to crossed out name simply by typing the players name.

I'm not sure what crossed out means in this contexzt?
Is that a technical term in US football(?) or do you
simply mean you want to delete the entry?

> What do I need to lean in order to accomplish this? string, variable
> functions?

You would be best working througfh a general purpose introduction.
Can you program already in another language or are you new to 
programming as well as Python?

Either way there are tutorials on the Python web site that can
help. Once you have completed one of these your project should
be straightforward.

But trying to learn only the minimum needed for your project
will in variable lead to frustration as you keep finding
new things you need to learn, but not in any logical order.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From marc.tompkins at gmail.com  Mon Jul 21 02:34:05 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 20 Jul 2014 17:34:05 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <lqhcr6$np5$1@ger.gmane.org>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
Message-ID: <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>

On Sun, Jul 20, 2014 at 2:37 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:

> In fact in this case I suggested he use a for loop to iterate over
> the file and use a dictionary to store the results...

Ah.  I missed that, as I've only noticed this newer thread.  And I
apologize for imputing motive (a liking for "while True"); I'd just
noticed that you often advise it.  I don't know who _does_ think this
is a desirable pattern; I'd love to hear their argument for it - it
must be really good.

From breamoreboy at yahoo.co.uk  Mon Jul 21 03:12:29 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Mon, 21 Jul 2014 02:12:29 +0100
Subject: [Tutor] (no subject)
In-Reply-To: <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
Message-ID: <lqhpdt$7ul$1@ger.gmane.org>

On 21/07/2014 01:34, Marc Tompkins wrote:
> On Sun, Jul 20, 2014 at 2:37 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
>> In fact in this case I suggested he use a for loop to iterate over
>> the file and use a dictionary to store the results...
>
> Ah.  I missed that, as I've only noticed this newer thread.  And I
> apologize for imputing motive (a liking for "while True"); I'd just
> noticed that you often advise it.  I don't know who _does_ think this
> is a desirable pattern; I'd love to hear their argument for it - it
> must be really good.
>

It works :)

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From steve at pearwood.info  Mon Jul 21 03:49:00 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Mon, 21 Jul 2014 11:49:00 +1000
Subject: [Tutor] Is this possible for a newbie?
In-Reply-To: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>
References: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>
Message-ID: <20140721014900.GM9112@ando>

On Sun, Jul 20, 2014 at 04:57:24PM -0400, keith papa wrote:

> Am a newbie to programming and I started learning python days ago. I 
> have this idea I want to execute, am a big sport and fantasy fan and I 
> wanted to create something that will make it things a little easy for 
> me. My idea is simple I want to create a program that I can enter name 
> and some information about a player, for example:
[...]
> I want to be able to ask the program which QB is best on my list and 
> it give me the names of all the QB on my list, or ask for WR on my 
> list and it gives me all the WR on my list, and also I want to be able 
> to crossed out name simply by typing the players name. What do I need 
> to lean in order to accomplish this? string, variable functions? feel 
> free to ask any questions.  

This sounds more like something for a database than for Python itself.

You can write Python code to talk to the database, and Python has 
excellent libraries for a simple database, such as sqlite. But if you're 
on a Linux system and can install Postgres, I'd just use that directly 
and not worry about Python at all.

https://wiki.python.org/moin/DatabaseInterfaces
https://docs.python.org/2/library/persistence.html
http://www.postgresql.org/docs/7.4/static/tutorial.html


-- 
Steven

From marc.tompkins at gmail.com  Mon Jul 21 04:05:57 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 20 Jul 2014 19:05:57 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <lqhpdt$7ul$1@ger.gmane.org>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
 <lqhpdt$7ul$1@ger.gmane.org>
Message-ID: <CAKK8jXa5gnUs-DY49=Q9ncXOHRMeJsky4DO7zSN2gJo7=tSh+Q@mail.gmail.com>

On Sun, Jul 20, 2014 at 6:12 PM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:

>> Ah.  I missed that, as I've only noticed this newer thread.  And I
>> apologize for imputing motive (a liking for "while True"); I'd just
>> noticed that you often advise it.  I don't know who _does_ think this
>> is a desirable pattern; I'd love to hear their argument for it - it
>> must be really good.
>>
>
> It works :)

So does GOTO.

Seriously, though, how is
1)  Do {this} forever, until something happens that I'll tell you about later

better than
2)  Do {this} until this condition, which I'm telling you about RIGHT
NOW, changes
?

Granted, this can all be clarified with good comments - but the second
approach basically documents itself.

From breamoreboy at yahoo.co.uk  Mon Jul 21 04:14:42 2014
From: breamoreboy at yahoo.co.uk (Mark Lawrence)
Date: Mon, 21 Jul 2014 03:14:42 +0100
Subject: [Tutor] (no subject)
In-Reply-To: <CAKK8jXa5gnUs-DY49=Q9ncXOHRMeJsky4DO7zSN2gJo7=tSh+Q@mail.gmail.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
 <lqhpdt$7ul$1@ger.gmane.org>
 <CAKK8jXa5gnUs-DY49=Q9ncXOHRMeJsky4DO7zSN2gJo7=tSh+Q@mail.gmail.com>
Message-ID: <lqht2i$ibp$1@ger.gmane.org>

On 21/07/2014 03:05, Marc Tompkins wrote:
> On Sun, Jul 20, 2014 at 6:12 PM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>
>>> Ah.  I missed that, as I've only noticed this newer thread.  And I
>>> apologize for imputing motive (a liking for "while True"); I'd just
>>> noticed that you often advise it.  I don't know who _does_ think this
>>> is a desirable pattern; I'd love to hear their argument for it - it
>>> must be really good.
>>>
>>
>> It works :)
>
> So does GOTO.

What is the problem with GOTO?  GOTO is used extremely effectively 
throughout the Python C source code.  I've yet to hear of anybody say 
never use it.

>
> Seriously, though, how is
> 1)  Do {this} forever, until something happens that I'll tell you about later
>
> better than
> 2)  Do {this} until this condition, which I'm telling you about RIGHT
> NOW, changes
> ?
>
> Granted, this can all be clarified with good comments - but the second
> approach basically documents itself.
>

So what, to me this is a trivial issue compared to many other problems 
that can easily be solved in Python that can only be solved in other 
languages by jumping through hoops, with the Factory pattern springing 
instantly to my mind.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



From dyoo at hashcollision.org  Mon Jul 21 04:41:59 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Sun, 20 Jul 2014 19:41:59 -0700
Subject: [Tutor] Is this possible for a newbie?
In-Reply-To: <20140721014900.GM9112@ando>
References: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>
 <20140721014900.GM9112@ando>
Message-ID: <CAGZAPF5r8rnke8fLWt_c17xTVTqY8KM3KAiOTdKRoD1OrE2pOQ@mail.gmail.com>

>> Am a newbie to programming and I started learning python days ago. I
>> have this idea I want to execute, am a big sport and fantasy fan and I
>> wanted to create something that will make it things a little easy for
>> me. My idea is simple I want to create a program that I can enter name
>> and some information about a player, for example:
> [...]

> This sounds more like something for a database than for Python itself.

I agree with Steven; this does sound like a database storage and query
problem.  You can use a general-purpose language like Python to tackle
this problem.  But you may have an easier time if you use a
database-oriented language like SQL to handle the data management.

There's an SQL tutorial in:

     http://sql.learncodethehardway.org/

that might be helpful if you're not already familiar with SQL.

From ben+python at benfinney.id.au  Mon Jul 21 05:08:27 2014
From: ben+python at benfinney.id.au (Ben Finney)
Date: Mon, 21 Jul 2014 13:08:27 +1000
Subject: [Tutor] Ending a loop with a condition not at the top
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
Message-ID: <85wqb7pfx0.fsf_-_@benfinney.id.au>

Marc Tompkins <marc.tompkins at gmail.com> writes:

> And I apologize for imputing motive (a liking for "while True"); I'd
> just noticed that you often advise it. I don't know who _does_ think
> this is a desirable pattern; I'd love to hear their argument for it -
> it must be really good.

It works better than alternatives already available in the language; it
is simpler than alternatives already available in the language. It isn't
particularly ugly (nor is it particularly beautiful, I'll grant you).

And it works well enough, and is simple enough, to be recommended
without caveat to anyone needing a loop to end somewhere other than the
top.

Any alternative structure would need to be *significantly* better than
what already works now. That, in the end, is the strongest argument for
?while True: ? break?.

-- 
 \          ?When [science] permits us to see the far side of some new |
  `\      horizon, we remember those who prepared the way ? seeing for |
_o__)                          them also.? ?Carl Sagan, _Cosmos_, 1980 |
Ben Finney


From ben+python at benfinney.id.au  Mon Jul 21 05:10:34 2014
From: ben+python at benfinney.id.au (Ben Finney)
Date: Mon, 21 Jul 2014 13:10:34 +1000
Subject: [Tutor] Ending a loop with a condition not at the top
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
 <lqhpdt$7ul$1@ger.gmane.org>
 <CAKK8jXa5gnUs-DY49=Q9ncXOHRMeJsky4DO7zSN2gJo7=tSh+Q@mail.gmail.com>
Message-ID: <85silvpfth.fsf_-_@benfinney.id.au>

Marc Tompkins <marc.tompkins at gmail.com> writes:

> Seriously, though, how is
> 1) Do {this} forever, until something happens that I'll tell you about
> later
>
> better than
> 2)  Do {this} until this condition, which I'm telling you about RIGHT
> NOW, changes
> ?

Here's how:

The first of them is already implemented in Python, and works well
enough for the purpose. This is a significant benefit the other lacks.

The second one is not implemented in Python, and there are no successful
proposals (which, by the way, are better discussed at the Python Ideas
forum <URL:https://mail.python.org/mailman/listinfo/python-ideas>) to
implement them in a way that justifies the cost of adding it to the
language.

What are you asking for? If you want someone to agree that a ?while
True: ? break? is not as aesthetically pleasing as it might be ideally:
yes, I agree. It is not perfect. Take that confirmation and be content.

If, on the other hand, you are asking ? as your words imply ? for the
currest state of affairs to be justified: you already have that. The
justification is: it works *now*, well enough that any alternative so
far proposed is not sufficiently better to displace it within Python.

If you want to propose an improvement to Python, feel free to take it up
at the Python Ideas forum. But do your research first on what a change
to the language would mean ? what you're thereby asking the Python
developers and community to accept ? and the burden such proposals need
to meet in order to be accepted.

-- 
 \     ?I got some new underwear the other day. Well, new to me.? ?Emo |
  `\                                                           Philips |
_o__)                                                                  |
Ben Finney


From memilanuk at invalid.com  Mon Jul 21 05:48:21 2014
From: memilanuk at invalid.com (Monte Milanuk)
Date: Mon, 21 Jul 2014 03:48:21 +0000 (UTC)
Subject: [Tutor] Is this possible for a newbie?
References: <COL130-W2948F33D783D7B7C1B7508A8F30@phx.gbl>
 <20140721014900.GM9112@ando>
Message-ID: <slrnlsp3c5.ccg.memilanuk@machin-shin.milanuk.lan>

On 2014-07-21, Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Jul 20, 2014 at 04:57:24PM -0400, keith papa wrote:
>
>> Am a newbie to programming and I started learning python days ago. I 
>
> This sounds more like something for a database than for Python itself.
>
> You can write Python code to talk to the database, and Python has 
> excellent libraries for a simple database, such as sqlite. 

I'd agree up to this point...

> But if you're on a Linux system and can install Postgres, I'd just use that 
> directly 

But this...?  Why in the name of Pete would you suggest a newbie setup
something like postgresql for something this small/simple?  Yes, sqlite
has its limitations but I don't think the OP is likely to run into them
any time soon on a project like this.

Monte


From marc.tompkins at gmail.com  Mon Jul 21 07:21:58 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sun, 20 Jul 2014 22:21:58 -0700
Subject: [Tutor] Ending a loop with a condition not at the top
In-Reply-To: <85silvpfth.fsf_-_@benfinney.id.au>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
 <lqhpdt$7ul$1@ger.gmane.org>
 <CAKK8jXa5gnUs-DY49=Q9ncXOHRMeJsky4DO7zSN2gJo7=tSh+Q@mail.gmail.com>
 <85silvpfth.fsf_-_@benfinney.id.au>
Message-ID: <CAKK8jXaPOGLR9NewPk42nvQwQOoh09eWpC7UUMGR7r=fY2U_Xg@mail.gmail.com>

On Sun, Jul 20, 2014 at 8:10 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Marc Tompkins <marc.tompkins at gmail.com> writes:
>
>> Seriously, though, how is
>> 1) Do {this} forever, until something happens that I'll tell you about
>> later
>>
>> better than
>> 2)  Do {this} until this condition, which I'm telling you about RIGHT
>> NOW, changes
>> ?
>
> Here's how:
>
> The first of them is already implemented in Python, and works well
> enough for the purpose. This is a significant benefit the other lacks.
>
> The second one is not implemented in Python, and there are no successful
> proposals (which, by the way, are better discussed at the Python Ideas
> forum <URL:https://mail.python.org/mailman/listinfo/python-ideas>) to
> implement them in a way that justifies the cost of adding it to the
> language.

Actually, if you read the Python docs - 8.2 for Python 3:
  https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
or 7.2 for Python 2:
  https://docs.python.org/2/reference/compound_stmts.html#the-while-statement
you'll see that it _is_ implemented:
> The while statement is used for repeated execution as long as an expression is true:
>   while_stmt ::=  "while" expression ":" suite
>           ["else" ":" suite]
> This repeatedly tests the expression and, if it is true, executes the first suite;
> if the expression is false (which may be the first time it is tested) the suite of the else clause, if present, is executed and the loop terminates.

So I don't know where you got the idea that I wanted to change the language.

However, I will admit that, until a few minutes ago, I had not read this:
https://docs.python.org/2/faq/design.html#why-can-t-i-use-an-assignment-in-an-expression
which deals with my preferred "while" syntax as an edge case:
>  There?s an alternative way of spelling this that seems attractive but is generally less robust than the ?while True? solution:

One might ask whether the designer(s) of the language are on speaking
terms with whoever wrote that paragraph - but I bow my head to Guido's
(or whoever's) wisdom.

In any case, I wholeheartedly agree with the next paragraph, which states:
>  The best approach is to use iterators, making it possible to loop through objects using the for statement.

From alan.gauld at btinternet.com  Mon Jul 21 09:16:12 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 21 Jul 2014 08:16:12 +0100
Subject: [Tutor] (no subject)
In-Reply-To: <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <lqhcr6$np5$1@ger.gmane.org>
 <CAKK8jXbTPAF3bFgxgStD4+e0gnAryoqwKnTJZsvkKy3j-rY_Wg@mail.gmail.com>
Message-ID: <lqiens$i8$1@ger.gmane.org>

On 21/07/14 01:34, Marc Tompkins wrote:

> noticed that you often advise it.  I don't know who _does_ think this
> is a desirable pattern; I'd love to hear their argument for it - it
> must be really good.


Nope, it doesn't need to be "really good", it just needs to
have enough advantage over the alternatives for people
to prefer it.

In the case of while loops the options are:

1) while True:

while True:
     read input
     if end condition: break
     process loop

2) While test

read input
while test:
    process loop
    read input


The argument against the latter form is simply
that you have to maintain the read input line
in two places.

So far as I can tell, that's it. But it seems
to be enough to make it the default Python while
idiom. Now that doesn't mean that you should not
use form 2 in Python, form 1 is only justified
if you need to repeat the call (or the test).
There are many cases where form 2 would be
better,. and sadly sometimes we see
form 1 being used when it should not.

But even more often we see while loops being
used where they should not. A for loop is
usually a better option if the number of
iterations is known.

Loop choice is one area where Python is not
as expressive as other languages but the
two(*) we have are adequate if not ideal.


(*)And you can extend those somewhat using
generators and itertools.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From joseph.lee22590 at gmail.com  Mon Jul 21 02:18:36 2014
From: joseph.lee22590 at gmail.com (Joseph Lee)
Date: Sun, 20 Jul 2014 17:18:36 -0700
Subject: [Tutor] Is this possible for a newbie?
Message-ID: <53cc5c6f.4498420a.0dfd.fffff845@mx.google.com>

Hi,
Answers are below.


 ----- Original Message -----
From: keith papa <keithadu at live.com
To: "tutor at python.org" <tutor at python.org
Date sent: Sun, 20 Jul 2014 16:57:24 -0400
Subject: [Tutor] Is this possible for a newbie?

Am a newbie to programming and I started learning python days 
ago.  I have this idea I want to execute, am a big sport and 
fantasy fan and I wanted to create something that will make it 
things a little easy for me.  My idea is simple I want to create 
a program that I can enter name and some information about a 
player, for example:

NFL plays:

Jamaal Charles RB : ATT 259 , YDS 1,287 , AVG 5.0, TD 12, REC 70

Tony Romo QB: CMP% 63.9, YDS 3,828 , TD 31, INT 10, Rating 96.7

Dez Bryant WR: REC 93, YDS 1,233, AVG 13.3, LNG 79, TD 13

and other players information.

I want to be able to ask the program which QB is best on my list 
and it give me the names of all the QB on my list, or ask for WR 
on my list and it gives me all the WR on my list, and also I want 
to be able to crossed out name simply by typing the players name.
What do I need to lean in order to accomplish this? string, 
variable functions?
feel free to ask any questions.

JL:
I think learning about tuples and dictionaries might be your 
friends.  There is a data type called tamed tuple that assigns 
names to fields, so you can ask your program to give you needed 
info by sorting by field names.
Hope this helps.
Cheers,
Joseph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: attachment
Type: application/octet-stream
Size: 184 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20140720/fef11eec/attachment-0001.obj>

From lnartist at yahoo.com  Mon Jul 21 01:48:39 2014
From: lnartist at yahoo.com (LN A-go-go)
Date: Sun, 20 Jul 2014 16:48:39 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <53CC38ED.40404@biologie.uni-freiburg.de>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <53CC38ED.40404@biologie.uni-freiburg.de>
Message-ID: <1405900119.88493.YahooMailNeo@web161305.mail.bf1.yahoo.com>

Dear Gurus,
Thank-you thank-you, one more time, thank-you.
I am over that hurdle and have the other: converting the list of characters that was just created by the split - into integers so I can manipulate them.? I was trying to convert to a string, then to integers.? I have been scouring the web for casting integers, converting to strings?and also trying to look up the error messages: I apologize?for the mess - I was trying everything.

Sigh,
Python in the hands of the na?ve

LN.

>>> numlist = data_value
>>> numlist
['36', '39', '39', '45', '61', '54', '61', '93', '62', '51', '47', '72', '54', '36', '62', '50', '41', '41', '40', '62', '62', '58', '57', '54', '49', '43', '47', '50', '45', '41', '54', '57', '57', '55', '62', '51', '34', '57', '55', '63', '45', '45', '42', '44', '34', '53', '67', '58', '56', '43', '33']
>>> print sum(numlist)
Traceback (most recent call last):
? File "<pyshell#38>", line 1, in <module>
??? print sum(numlist)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> orange_drinkers = int(data_value)
Traceback (most recent call last):
? File "<pyshell#39>", line 1, in <module>
??? orange_drinkers = int(data_value)
TypeError: int() argument must be a string or a number, not 'list'
>>> int(data_value)
Traceback (most recent call last):
? File "<pyshell#40>", line 1, in <module>
??? int(data_value)
TypeError: int() argument must be a string or a number, not 'list'
>>> numstring = raw_input(">")
>
>>> type(numlist)
<type 'list'>
>>> b = str(numlist)
>>> c = []
>>> for digit in b:
?c.append (int(digit))
?
Traceback (most recent call last):
? File "<pyshell#47>", line 2, in <module>
??? c.append (int(digit))
ValueError: invalid literal for int() with base 10: '['
>>> i = 0
>>> str(numlist)
"['36', '39', '39', '45', '61', '54', '61', '93', '62', '51', '47', '72', '54', '36', '62', '50', '41', '41', '40', '62', '62', '58', '57', '54', '49', '43', '47', '50', '45', '41', '54', '57', '57', '55', '62', '51', '34', '57', '55', '63', '45', '45', '42', '44', '34', '53', '67', '58', '56', '43', '33']"
>>> int(x[,numlist])
SyntaxError: invalid syntax
>>> int(x[numlist])
Traceback (most recent call last):
? File "<pyshell#51>", line 1, in <module>
??? int(x[numlist])
TypeError: 'int' object has no attribute '__getitem__'
>>> for x in numlist:
?i.append (int(x))
?
Traceback (most recent call last):
? File "<pyshell#54>", line 2, in <module>
??? i.append (int(x))
AttributeError: 'int' object has no attribute 'append'
>>> 




? 


On Sunday, July 20, 2014 6:21 PM, Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de> wrote:
  


On 20.07.2014 22:37, Marc Tompkins wrote:
>
> First of all, I would take advantage of the "with" construction, like so:
>
> with open('C:/Python27/egund919/Program1/BOJ_B.txt','r') as infile:
>? ? ? #do stuff with infile
>
> When the block of code inside of the "with" section finishes, Python
> will take care of closing the file for you - even if your program
> encountered an error.? MAJOR advantage over doing it yourself.
>

Yes, definitely, as you have experienced yourself now.

> Second, there's no need to import "string" anymore; all of the
> functions defined in that module are native methods of strings.
> "line" is a string, so you can just do "line.split()".? split()
> returns a list; you can get the first item in that list with
> line.split()[0], the second item with line.split()[1], etc.
>

I fully agree on the string method part. As for the use of 
line.split()[0] and [1], see my comment in the code below.

> Third, free your mind from the shackles of counting how many objects
> are in a list and using that counter as the index of your loops - this
> is not the Python way!? Instead, let Python take care of the counting
> and indexing for you.
>

True (see the earlier suggestion of using enumerate()), but I'm sure 
you'll learn this over time.

> Fourth (and here I differ from some of the others on this list,
> notably Alan G) - I don't like the "while True: / break" paradigm.
> Your mileage may vary, but I find it makes it harder to understand
> what the program is actually trying to achieve.? In your case, you
> read a line from the file, then check whether it contains anything; I
> like to move the readline() to the bottom of the loop.

In my opinion, this is less readable than the original code. I know that 
some people (usually coming from C or other languages with more 
expressive while loops) don't like it, but there's nothing wrong, in 
general, with using while True with break. It's perfectly pythonic.

Direct use of the file object in a for loop has been suggested already 
and THAT's more readable.

>
> Having said all that, here's my suggested version:
>
> state_name = []
> data_value = []
> with open('C:/Python27/egund919/Program1/BOJ_B.txt','r') as infile:
>? ? ? line = infile.readline()? # Doing this twice because you
> apparently want to discard the first line...?
>? ? ? line = infile.readline()
>? ? ? while line:
>? ? ? ? ? state_name.append(line.split()[0])
>? ? ? ? ? data_value.append(line.split()[1])

Rewriting the original

? ? ? ? ? ? States, OJ = string.split(line)

as

? ? ? ? ? ? states, oj = line.split()

is better (and it's remarkable that you used it as a beginner). This 
line unpacks the elements of the list returned by the split method into 
the two variables on the left side.
Besides avoiding repetitive calls to line.split(), it may also help you 
discover problems with your input file format. If there are more than 
two elements in the list, you'll get an error, so you'll know there was 
something in the file you didn't expect. With the line.split()[0] / [1] 
approach, potential other elements in the list (i.e. unexpected line 
content) will be ignored silently.
Once you've learnt that errors in Python are nothing evil, but there to 
help you and once you've read about try/except to catch them, you'll 
appreciate the advantage of the first version.

>? ? ? ? ? line = infile.readline()

I don't see why repeating infile.readline() three times should be more 
elegant than a nice and clean while True / break.


> print(state_name)
> print(data_value)


_______________________________________________
Tutor maillist? -? Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140720/7fa9062a/attachment.html>

From yarteydegreat2 at gmail.com  Mon Jul 21 08:57:42 2014
From: yarteydegreat2 at gmail.com (=?utf-8?B?eWFydGV5ZGVncmVhdDJAZ21haWwuY29t?=)
Date: Mon, 21 Jul 2014 06:57:42 +0000
Subject: [Tutor] =?utf-8?q?Unhandled_exception?=
Message-ID: <53ccb9f8.ad3fc20a.7312.7cae@mx.google.com>

I just want to know if an unhandled exception is a bug in my programs! 

Degreat

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140721/fd8eb8da/attachment-0001.html>

From wolfgang.maier at biologie.uni-freiburg.de  Mon Jul 21 09:52:44 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Mon, 21 Jul 2014 09:52:44 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <1405900119.88493.YahooMailNeo@web161305.mail.bf1.yahoo.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <53CC38ED.40404@biologie.uni-freiburg.de>
 <1405900119.88493.YahooMailNeo@web161305.mail.bf1.yahoo.com>
Message-ID: <53CCC6CC.9030008@biologie.uni-freiburg.de>

On 21.07.2014 01:48, LN A-go-go wrote:> Dear Gurus,
 > Thank-you thank-you, one more time, thank-you.
 > I am over that hurdle and have the other: converting the list of
 > characters that was just created by the split - into integers so I can
 > manipulate them.  I was trying to convert to a string, then to
 > integers.  I have been scouring the web for casting integers, converting
 > to strings and also trying to look up the error messages: I
 > apologize for the mess - I was trying everything.
 >
 > Sigh,
 > Python in the hands of the na?ve
 >
 > LN.
 >
 >>>> numlist = data_value
 >>>> numlist
 > ['36', '39', '39', '45', '61', '54', '61', '93', '62', '51', '47', '72',
 > '54', '36', '62', '50', '41', '41', '40', '62', '62', '58', '57', '54',
 > '49', '43', '47', '50', '45', '41', '54', '57', '57', '55', '62', '51',
 > '34', '57', '55', '63', '45', '45', '42', '44', '34', '53', '67', '58',
 > '56', '43', '33']
 >>>> print sum(numlist)
 > Traceback (most recent call last):
 >    File "<pyshell#38>", line 1, in <module>
 >      print sum(numlist)
 > TypeError: unsupported operand type(s) for +: 'int' and 'str'
 >>>> orange_drinkers = int(data_value)

First thing you have to do in programming is to state your problem 
correctly: you do not want to convert your list to an integer 
representation.
This is what you are attempting in your last line above: convert the 
data_value list to a single integer, and obviously, that cannot work.

Instead, what you want to do is to convert every element in your list to 
an integer. You already know how to do this in a for loop:

int_list = []
for element in data_value:
     int_list.append(int(element))

However, for simple transformations like this, Python has a very 
powerful construct called list comprehensions (read about them here: 
https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions 
, they're really great), which allow you to replace the for loop with a 
simple:

int_list = [int(element) for element in data_value]

You can even combine the comprehension with sum on one line like this:

print sum([int(element) for element in data_value])

Yet, while all of the above should help you learn Python programming 
patterns, your original code already had the best solution:

data_value = []
..
while True:
     line = infile.readline()
     if not line: break
     ..
     States, OJ = string.split(line)
     XNUM = int(OJ)
     ..
     data_value.append(XNUM)

, i.e. converting each value to an int before adding it to the original 
list.

Best,
Wolfgang


From alan.gauld at btinternet.com  Mon Jul 21 11:38:12 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Mon, 21 Jul 2014 10:38:12 +0100
Subject: [Tutor] Unhandled exception
In-Reply-To: <53ccb9f8.ad3fc20a.7312.7cae@mx.google.com>
References: <53ccb9f8.ad3fc20a.7312.7cae@mx.google.com>
Message-ID: <lqin25$3p0$1@ger.gmane.org>

On 21/07/14 07:57, yarteydegreat2 at gmail.com wrote:
> I just want to know if an unhandled exception is a bug in my programs!

No, its not. Maybe.

Exceptions can happen for all sorts of reasons, for
some you can do something if they happen.
In those cases handling the exception makes sense.

In other cases the exception can't be usefully handled
so there is little point in creating a handler. Just
allow the exception to happen and display the stack
trace.

So if you can reasonably expect an exception to happen
and can do something sensible about it (like trying
to open a non existent file, say) you should handle
it and not doing so would arguably be a bug.

But if you can't do anything sensible with the
exception (an out of memory error for example(*))
you might as well just let it happen.

The final twist is that your client might not like
to see user-hostile error messages. I that case
use a general except clause and log the error
where you can find it but the user gets a
nice friendly message instead.

(*)Of course in critical apps running out of
memory could be seen as a bug. But nonetheless
not catching the exception when it happens is
not the problem. Memory errors usually need to be
prevented not handled after the fact.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From ben+python at benfinney.id.au  Mon Jul 21 13:16:43 2014
From: ben+python at benfinney.id.au (Ben Finney)
Date: Mon, 21 Jul 2014 21:16:43 +1000
Subject: [Tutor] Unhandled exception
References: <53ccb9f8.ad3fc20a.7312.7cae@mx.google.com>
Message-ID: <85oawjotb8.fsf@benfinney.id.au>

"yarteydegreat2 at gmail.com" <yarteydegreat2 at gmail.com> writes:

> I just want to know if an unhandled exception is a bug in my programs! 

That's a good question, thanks for asking.

In some programming languages, exceptions are something to avoid and
reduce where possible. But that's not the case for Python.

In Python, exceptions are a fundamental part of the program flow. When a
function call (or some other part of a program) encounters a
circumstance where ?this is the result? doesn't make sense, the correct
idiom is to raise an exception with rich information about what the
exceptional situation was.

For example, a procedure for ?divide number foo by number bar? should
usually return a numeric result. If one of the values is not a number,
though, no result makes sense; a ValueError exception is raised. If they
*are* both numbers, but the second (the denominator) is zero, there's
still no sensible result to return; instead, it makes more sense to
raise a ZeroDivisionError.

Another example: a procedure for ?get me the next item from this
sequence? should usually return the item as a value. If the sequence
*has* no more items, though, no value makes sense to return; a
StopIteration exception is raised.

An example you are likely familiar with: Your Python program can run at
a text console, or maybe you're writing some Python code at the
interactive Python shell. This usually reads a line of text from your
console, and goes on to process the result as a line of text. If you
want to stop the session, though, you can press the console's
?interrupt? key (Ctrl+C, or Ctrl+Z on some systems). No particular line
of text makes sense as a result, so a KeyboardInterrupt exception is
raised.

In all these cases, the exception is raised because no return value
makes sense, and *something* needs to deal with the fact that the
typical path through the code can't continue. Exceptions are normal :-)

So, in light of all that: If your code is written to expect specific
exceptions, you can catch them (by the type of exception) and handle
them at an appropriate point. If not, they end your program at the top
level reporting that the exception was unhandled.

Whether they are an *error* is a matter of what your intention was. If
you weren't intending the program to encounter that exception, then yes!
But exceptions are a normal part of Python control flow, and often they
are exactly what is needed.

-- 
 \     ?The Things to do are: the things that need doing, that you see |
  `\     need to be done, and that no one else seems to see need to be |
_o__)                   done.? ?Richard Buckminster Fuller, 1970-02-16 |
Ben Finney


From yarteydegreat2 at gmail.com  Mon Jul 21 21:20:41 2014
From: yarteydegreat2 at gmail.com (=?utf-8?B?eWFydGV5ZGVncmVhdDJAZ21haWwuY29t?=)
Date: Mon, 21 Jul 2014 19:20:41 +0000
Subject: [Tutor] =?utf-8?q?Unhandled_exception?=
Message-ID: <53cd6820.e9c8c20a.702f.7f17@mx.google.com>

Thanks, Alan and Ben! I really appreciate your explanations.

Degreat

----- Reply message -----
From: "Ben Finney" <ben+python at benfinney.id.au>
To: <tutor at python.org>
Subject: [Tutor] Unhandled exception
Date: Mon, Jul 21, 2014 11:16


"yarteydegreat2 at gmail.com" <yarteydegreat2 at gmail.com> writes:

> I just want to know if an unhandled exception is a bug in my programs! 

That's a good question, thanks for asking.

In some programming languages, exceptions are something to avoid and
reduce where possible. But that's not the case for Python.

In Python, exceptions are a fundamental part of the program flow. When a
function call (or some other part of a program) encounters a
circumstance where ?this is the result? doesn't make sense, the correct
idiom is to raise an exception with rich information about what the
exceptional situation was.

For example, a procedure for ?divide number foo by number bar? should
usually return a numeric result. If one of the values is not a number,
though, no result makes sense; a ValueError exception is raised. If they
*are* both numbers, but the second (the denominator) is zero, there's
still no sensible result to return; instead, it makes more sense to
raise a ZeroDivisionError.

Another example: a procedure for ?get me the next item from this
sequence? should usually return the item as a value. If the sequence
*has* no more items, though, no value makes sense to return; a
StopIteration exception is raised.

An example you are likely familiar with: Your Python program can run at
a text console, or maybe you're writing some Python code at the
interactive Python shell. This usually reads a line of text from your
console, and goes on to process the result as a line of text. If you
want to stop the session, though, you can press the console's
?interrupt? key (Ctrl+C, or Ctrl+Z on some systems). No particular line
of text makes sense as a result, so a KeyboardInterrupt exception is
raised.

In all these cases, the exception is raised because no return value
makes sense, and *something* needs to deal with the fact that the
typical path through the code can't continue. Exceptions are normal :-)

So, in light of all that: If your code is written to expect specific
exceptions, you can catch them (by the type of exception) and handle
them at an appropriate point. If not, they end your program at the top
level reporting that the exception was unhandled.

Whether they are an *error* is a matter of what your intention was. If
you weren't intending the program to encounter that exception, then yes!
But exceptions are a normal part of Python control flow, and often they
are exactly what is needed.

-- 
 \     ?The Things to do are: the things that need doing, that you see |
  `\     need to be done, and that no one else seems to see need to be |
_o__)                   done.? ?Richard Buckminster Fuller, 1970-02-16 |
Ben Finney

_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140721/bc05b505/attachment.html>

From davea at davea.name  Tue Jul 22 03:14:13 2014
From: davea at davea.name (Dave Angel)
Date: Mon, 21 Jul 2014 20:14:13 -0500 (CDT)
Subject: [Tutor] Unhandled exception
References: <53cd6820.e9c8c20a.702f.7f17@mx.google.com>
Message-ID: <lqkdt5$qj9$1@ger.gmane.org>

"yarteydegreat2 at gmail.com" <yarteydegreat2 at gmail.com> Wrote in message:
> 
> 

I'm glad they were able to help.  But please let me point out a
 few procedural issues, for nex time. 
You started a whole new thread just to say thanks.  You should
 only start one to ask a new question or start a new discussion.  
 Otherwise use reply-list or whatever your program calls it, maybe
 reply-all and remove the recipients other than the list.
 

You sent this message in html, not in text mode. Always tell your
 mail to use text here.

You top-posted, rather than putting your comments after the
 relevant quotation. 

Thanks for listening. 


-- 
DaveA


From jarod_v6 at libero.it  Tue Jul 22 13:10:18 2014
From: jarod_v6 at libero.it (jarod_v6 at libero.it)
Date: Tue, 22 Jul 2014 13:10:18 +0200 (CEST)
Subject: [Tutor] How to show dictionary item non present on file
Message-ID: <253805423.250161406027418296.JavaMail.defaultUser@defaultHost>

Hin there!!!

I have a niave question on dictionary analysis: 
If you have a dictionary like this:
diz
Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}

and you have a list and you want to know which  keys are not present on my 
dictionary the code are simple.
for i in diz.keys():
   ...:     if i in mitico:
   ...:         print "NO"
   ...:     else:
   ...:         print i
   ...:         
NO

But I havethis problem I have a file and I want to know which elements are not 
present on my file from dictionary.
 more data.tmp 
jack	1
pippo	1
luis	1
frate	1
livio	1
frank	1


with open("data.tmp") as p:
    for i in p:
        lines= i.strip("\n").split("\t")
        if not diz.has_key(lines[0]):
   ....:             print i
   ....:             
pippo	1

luis	1

frate	1

livio	1

The output I want is to have :
ralph and 'elenour.. how can I do this?
thanks in advance!


From steve at pearwood.info  Tue Jul 22 13:32:47 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Tue, 22 Jul 2014 21:32:47 +1000
Subject: [Tutor] How to show dictionary item non present on file
In-Reply-To: <253805423.250161406027418296.JavaMail.defaultUser@defaultHost>
References: <253805423.250161406027418296.JavaMail.defaultUser@defaultHost>
Message-ID: <20140722113247.GO9112@ando>

On Tue, Jul 22, 2014 at 01:10:18PM +0200, jarod_v6 at libero.it wrote:

> But I havethis problem I have a file and I want to know which elements are not 
> present on my file from dictionary.
>  more data.tmp 
> jack	1
> pippo	1
> luis	1
> frate	1
> livio	1
> frank	1
> 
> 
> with open("data.tmp") as p:
>     for i in p:
>         lines= i.strip("\n").split("\t")
>         if not diz.has_key(lines[0]):
>    ....:             print i
>    ....:             
> pippo	1
> luis	1
> frate	1
> livio	1
> 
> The output I want is to have :
> ralph and 'elenour.. how can I do this?

You are doing the comparison the wrong way: you are saying:

for each line in the file:
    is the line in the dict?
    if no, print the line


What you want is:

for each key in the dict:
    is the key in the file?
    if no, print the key


It is not easy to try searching the file directly, so we copy the lines 
from the file into a set:

lines = set()
with open("data.tmp") as the_file:
    for line in the_file:
        line = line.strip().split("\t")[0]
        lines.add(line)


Here is a shorter way to do the same thing:

with open("data.tmp") as the_file:
    lines = set([line.strip().split("\t")[0] for line in the_file])


Now you can walk through the dict:

for name in diz:
    if name not in lines:
        print(name) 


Or, if you prefer:

names = set(diz)  # copy the keys from the dict into a set
print(names.difference(lines))


If you want to see the other way around:

print(lines.difference(names))




-- 
Steven

From __peter__ at web.de  Tue Jul 22 13:48:09 2014
From: __peter__ at web.de (Peter Otten)
Date: Tue, 22 Jul 2014 13:48:09 +0200
Subject: [Tutor] How to show dictionary item non present on file
References: <253805423.250161406027418296.JavaMail.defaultUser@defaultHost>
Message-ID: <lqlj1q$6ph$1@ger.gmane.org>

jarod_v6 at libero.it wrote:

> Hin there!!!
> 
> I have a niave question on dictionary analysis:
> If you have a dictionary like this:
> diz
> Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}
> 
> and you have a list and you want to know which  keys are not present on my
> dictionary the code are simple.
> for i in diz.keys():
>    ...:     if i in mitico:
>    ...:         print "NO"
>    ...:     else:
>    ...:         print i
>    ...:
> NO
> 
> But I havethis problem I have a file and I want to know which elements are
> not present on my file from dictionary.
>  more data.tmp
> jack	1
> pippo	1
> luis	1
> frate	1
> livio	1
> frank	1
> 
> 
> with open("data.tmp") as p:
>     for i in p:
>         lines= i.strip("\n").split("\t")
>         if not diz.has_key(lines[0]):
>    ....:             print i
>    ....:
> pippo	1
> 
> luis	1
> 
> frate	1
> 
> livio	1
> 
> The output I want is to have :
> ralph and 'elenour.. how can I do this?
> thanks in advance!

You have the logic backwards. You have to iterate over the names in the dict 
and look them up in the file:

>>> diz = {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}
>>> def find_name(name):
...     with open("data.tmp") as f:
...             for line in f:
...                     if name == line.split("\t")[0]:
...                             return True
...     return False
... 
>>> for name in diz:
...     if not find_name(name):
...             print name
... 
ralph
elenour

However, this is very inefficient as you have to read the file len(diz) 
times. It is better to store the names in a data structure suited for fast 
lookup first and then to use that instead of the file. Python's dict and set 
types are such data structures, so as we don't care about an associated 
value let's use a set:

>>> with open("data.tmp") as f:
...     names_in_file = {line.split("\t")[0] for line in f}
... 
>>> for name in diz:
...     if not name in names_in_file:
...             print name
... 
ralph
elenour

Digging a bit deeper you'll find that you can get these names with set 
arithmetic:

>>> set(diz) - names_in_file
set(['ralph', 'elenour'])

or even:

>>> diz.viewkeys() - names_in_file
set(['elenour', 'ralph'])




From edannewitz at rdschool.org  Wed Jul 23 01:10:02 2014
From: edannewitz at rdschool.org (Eric Dannewitz)
Date: Tue, 22 Jul 2014 16:10:02 -0700 (PDT)
Subject: [Tutor] Getting a directory listing with Python to MySQL
In-Reply-To: <2029058402.610320.1406070571950.JavaMail.zimbra@rdschool.org>
Message-ID: <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>

Hello list, I'm new. I've done a few things in Python, but this one is posing problems. 

What I want to do is be able to parse a directory, say /Volumes/Stuff/Files/, and all the directories that might be in there, and be able to pick out file name, size, date modified, etc, and send that to a MySQL database. Any ideas? Sounds like it should be easy but...... 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140722/0a8c664b/attachment.html>

From dyoo at hashcollision.org  Wed Jul 23 03:14:55 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Tue, 22 Jul 2014 18:14:55 -0700
Subject: [Tutor] Getting a directory listing with Python to MySQL
In-Reply-To: <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
References: <2029058402.610320.1406070571950.JavaMail.zimbra@rdschool.org>
 <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
Message-ID: <CAGZAPF7Xi1ks5tk2c6E3X+o-e8nx9JNZq1kiEuceMQxaYAi9oQ@mail.gmail.com>

> What I want to do is be able to parse a directory, say
/Volumes/Stuff/Files/, and all the directories that might be in there, and
be able to pick out file name, size, date modified, etc,

Hi Eric,

You might find the following helpful:
http://www.diveintopython.net/file_handling/os_module.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140722/1011b814/attachment.html>

From steve at pearwood.info  Wed Jul 23 03:31:48 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Wed, 23 Jul 2014 11:31:48 +1000
Subject: [Tutor] Getting a directory listing with Python to MySQL
In-Reply-To: <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
References: <2029058402.610320.1406070571950.JavaMail.zimbra@rdschool.org>
 <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
Message-ID: <20140723013146.GQ9112@ando>

On Tue, Jul 22, 2014 at 04:10:02PM -0700, Eric Dannewitz wrote:
> Hello list, I'm new. I've done a few things in Python, but this one is posing problems. 
> 
> What I want to do is be able to parse a directory, say 
> /Volumes/Stuff/Files/, and all the directories that might be in there, 
> and be able to pick out file name, size, date modified, etc, and send 
> that to a MySQL database. Any ideas? Sounds like it should be easy 
> but......

os.listdir(path) returns all the entries under path (apart from '.' and 
'..'). You can then test whether they are files, directories or links 
with os.path.isdir, os.path.isfile, os.path.islink. (Remember that under 
Linux and Unix, there things other than files and links that can live in 
directories, e.g. named pipes.)

But rather than manually iterate through the contents of the directory, 
os.walk already does that for you. Something like this ought to get you 
started:

files = []
for dirpath, dirnames, filenames in os.walk(start_path):
    pathnames = [os.path.join(dirpath, name) for name in filenames]
    files.extend(pathnames)


That gets you a list of all the files under start_path. To check their 
size, dates, etc. use the os.stat and os.lstat functions (os.stat 
follows symbolic links, os.lstat does not). The stat module has a bunch 
of symbolic constants which may be helpful for interpreting the results.




-- 
Steven

From edannewitz at rdschool.org  Wed Jul 23 03:32:43 2014
From: edannewitz at rdschool.org (Eric Dannewitz)
Date: Tue, 22 Jul 2014 18:32:43 -0700 (PDT)
Subject: [Tutor] Getting a directory listing with Python to MySQL
In-Reply-To: <CAGZAPF7Xi1ks5tk2c6E3X+o-e8nx9JNZq1kiEuceMQxaYAi9oQ@mail.gmail.com>
References: <2029058402.610320.1406070571950.JavaMail.zimbra@rdschool.org>
 <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
 <CAGZAPF7Xi1ks5tk2c6E3X+o-e8nx9JNZq1kiEuceMQxaYAi9oQ@mail.gmail.com>
Message-ID: <1073549999.618930.1406079163039.JavaMail.zimbra@rdschool.org>

That's close. I have been playing from glob and os.walk but I'm at a loss how to get the size, creation and modified date while running it. 

----- Original Message -----

From: "Danny Yoo" <dyoo at hashcollision.org> 
To: "Eric Dannewitz" <edannewitz at rdschool.org> 
Cc: "Python Tutor Mailing List" <tutor at python.org> 
Sent: Tuesday, July 22, 2014 6:14:55 PM 
Subject: Re: [Tutor] Getting a directory listing with Python to MySQL 




> What I want to do is be able to parse a directory, say /Volumes/Stuff/Files/, and all the directories that might be in there, and be able to pick out file name, size, date modified, etc, 

Hi Eric, 

You might find the following helpful: http://www.diveintopython.net/file_handling/os_module.html 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140722/cbaaa832/attachment-0001.html>

From lnartist at yahoo.com  Wed Jul 23 03:36:51 2014
From: lnartist at yahoo.com (LN A-go-go)
Date: Tue, 22 Jul 2014 18:36:51 -0700
Subject: [Tutor] (no subject)
In-Reply-To: <53CCC6CC.9030008@biologie.uni-freiburg.de>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <53CC38ED.40404@biologie.uni-freiburg.de>
 <1405900119.88493.YahooMailNeo@web161305.mail.bf1.yahoo.com>
 <53CCC6CC.9030008@biologie.uni-freiburg.de>
Message-ID: <1406079411.81532.YahooMailNeo@web161301.mail.bf1.yahoo.com>

Hi again and thank-you Wolfgang and company.? I wish I?could give you snickers bars or something!? I was able to get through the road_blocks with your help.? I have been working the last few days, I am sorry to say, unsuccessfully, to calculate the mean (that's easy), split the data into sub-groups or secondary means - which are the break values between 4 classes.? Create data-sets with incursive values.? I can do it with brute force (copy and paste) but need to rise to the pythonic way and use a while loop and a nested if-else structure.? My attempts have been lame enough that I don't even want to put them here.
int_list
[36, 39, 39, 45, 61, 54, 61, 93, 62, 51, 47, 72, 54, 36, 62, 50, 41, 41, 40, 62, 62, 58, 57, 54, 49, 43, 47, 50, 45, 41, 54, 57, 57, 55, 62, 51, 34, 57, 55, 63, 45, 45, 42, 44, 34, 53, 67, 58, 56, 43, 33]
>>> int_list.sort()
>>> int_list
[33, 34, 34, 36, 36, 39, 39, 40, 41, 41, 41, 42, 43, 43, 44, 45, 45, 45, 45, 47, 47, 49, 50, 50, 51, 51, 53, 54, 54, 54, 54, 55, 55, 56, 57, 57, 57, 57, 58, 58, 61, 61, 62, 62, 62, 62, 62, 63, 67, 72, 93]
>>> flo_list = [float(integral) for integral in int_list]
>>> flo_list
[33.0, 34.0, 34.0, 36.0, 36.0, 39.0, 39.0, 40.0, 41.0, 41.0, 41.0, 42.0, 43.0, 43.0, 44.0, 45.0, 45.0, 45.0, 45.0, 47.0, 47.0, 49.0, 50.0, 50.0, 51.0, 51.0, 53.0, 54.0, 54.0, 54.0, 54.0, 55.0, 55.0, 56.0, 57.0, 57.0, 57.0, 57.0, 58.0, 58.0, 61.0, 61.0, 62.0, 62.0, 62.0, 62.0, 62.0, 63.0, 67.0, 72.0, 93.0]
>>> sum(flo_list)
2617.0
>>> totalnum = sum(flo_list)
>>> len(flo_list)
51
>>> mean = sum(flo_list)/len(flo_list)
>>> mean
51.31372549019608

Thank-you again,

LN 


On Monday, July 21, 2014 2:55 AM, Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de> wrote:
  


On 21.07.2014 01:48, LN A-go-go wrote:> Dear Gurus,
> Thank-you thank-you, one more time, thank-you.
> I am over that hurdle and have the other: converting the list of
> characters that was just created by the split - into integers so I can
> manipulate them.? I was trying to convert to a string, then to
> integers.? I have been scouring the web for casting integers, converting
> to strings and also trying to look up the error messages: I
> apologize for the mess - I was trying everything.
>
> Sigh,
> Python in the hands of the na?ve
>
> LN.
>
>>>> numlist = data_value
>>>> numlist
> ['36', '39', '39', '45', '61', '54', '61', '93', '62', '51', '47', '72',
> '54', '36', '62', '50', '41', '41', '40', '62', '62', '58', '57', '54',
> '49', '43', '47', '50', '45', '41', '54', '57', '57', '55', '62', '51',
> '34', '57', '55', '63', '45', '45', '42', '44', '34', '53', '67', '58',
> '56', '43', '33']
>>>> print sum(numlist)
> Traceback (most recent call last):
>? ? File "<pyshell#38>", line 1, in <module>
>? ? ? print sum(numlist)
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>>> orange_drinkers = int(data_value)

First thing you have to do in programming is to state your problem 
correctly: you do not want to convert your list to an integer 
representation.
This is what you are attempting in your last line above: convert the 
data_value list to a single integer, and obviously, that cannot work.

Instead, what you want to do is to convert every element in your list to 
an integer. You already know how to do this in a for loop:

int_list = []
for element in data_value:
? ?  int_list.append(int(element))

However, for simple transformations like this, Python has a very 
powerful construct called list comprehensions (read about them here: 
https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
, they're really great), which allow you to replace the for loop with a 
simple:

int_list = [int(element) for element in data_value]

You can even combine the comprehension with sum on one line like this:

print sum([int(element) for element in data_value])

Yet, while all of the above should help you learn Python programming 
patterns, your original code already had the best solution:

data_value = []
..
while True:
? ?  line = infile.readline()
? ?  if not line: break
? ?  ..
? ?  States, OJ = string.split(line)
? ?  XNUM = int(OJ)
? ?  ..
? ?  data_value.append(XNUM)

, i.e. converting each value to an int before adding it to the original 
list.

Best,
Wolfgang

_______________________________________________
Tutor maillist? -? Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140722/8d6db70d/attachment.html>

From jarod_v6 at libero.it  Wed Jul 23 09:25:54 2014
From: jarod_v6 at libero.it (jarod_v6 at libero.it)
Date: Wed, 23 Jul 2014 09:25:54 +0200 (CEST)
Subject: [Tutor] R: Tutor Digest, Vol 125, Issue 71
Message-ID: <228978299.463901406100354631.JavaMail.defaultUser@defaultHost>

Thanks so much!!

>----Messaggio originale----
>Da: tutor-request at python.org
>Data: 23/07/2014 8.10
>A: <tutor at python.org>
>Ogg: Tutor Digest, Vol 125, Issue 71
>
>Send Tutor mailing list submissions to
>	tutor at python.org
>
>To subscribe or unsubscribe via the World Wide Web, visit
>	https://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. How to show dictionary item non present on file
>      (jarod_v6 at libero.it)
>   2. Re: How to show dictionary item non present on file
>      (Steven D'Aprano)
>   3. Re: How to show dictionary item non present on file (Peter Otten)
>   4. Getting a directory listing with Python to MySQL (Eric Dannewitz)
>   5. Re: Getting a directory listing with Python to MySQL (Danny Yoo)
>   6. Re: Getting a directory listing with Python to MySQL
>      (Steven D'Aprano)
>   7. Re: Getting a directory listing with Python to MySQL
>      (Eric Dannewitz)
>
>
>----------------------------------------------------------------------
>
>Message: 1
>Date: Tue, 22 Jul 2014 13:10:18 +0200 (CEST)
>From: "jarod_v6 at libero.it" <jarod_v6 at libero.it>
>To: tutor at python.org
>Subject: [Tutor] How to show dictionary item non present on file
>Message-ID:
>	<253805423.250161406027418296.JavaMail.defaultUser at defaultHost>
>Content-Type: text/plain;charset="UTF-8"
>
>Hin there!!!
>
>I have a niave question on dictionary analysis: 
>If you have a dictionary like this:
>diz
>Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}
>
>and you have a list and you want to know which  keys are not present on my 
>dictionary the code are simple.
>for i in diz.keys():
>   ...:     if i in mitico:
>   ...:         print "NO"
>   ...:     else:
>   ...:         print i
>   ...:         
>NO
>
>But I havethis problem I have a file and I want to know which elements are 
not 
>present on my file from dictionary.
> more data.tmp 
>jack	1
>pippo	1
>luis	1
>frate	1
>livio	1
>frank	1
>
>
>with open("data.tmp") as p:
>    for i in p:
>        lines= i.strip("\n").split("\t")
>        if not diz.has_key(lines[0]):
>   ....:             print i
>   ....:             
>pippo	1
>
>luis	1
>
>frate	1
>
>livio	1
>
>The output I want is to have :
>ralph and 'elenour.. how can I do this?
>thanks in advance!
>
>
>
>------------------------------
>
>Message: 2
>Date: Tue, 22 Jul 2014 21:32:47 +1000
>From: Steven D'Aprano <steve at pearwood.info>
>To: tutor at python.org
>Subject: Re: [Tutor] How to show dictionary item non present on file
>Message-ID: <20140722113247.GO9112 at ando>
>Content-Type: text/plain; charset=us-ascii
>
>On Tue, Jul 22, 2014 at 01:10:18PM +0200, jarod_v6 at libero.it wrote:
>
>> But I havethis problem I have a file and I want to know which elements are 
not 
>> present on my file from dictionary.
>>  more data.tmp 
>> jack	1
>> pippo	1
>> luis	1
>> frate	1
>> livio	1
>> frank	1
>> 
>> 
>> with open("data.tmp") as p:
>>     for i in p:
>>         lines= i.strip("\n").split("\t")
>>         if not diz.has_key(lines[0]):
>>    ....:             print i
>>    ....:             
>> pippo	1
>> luis	1
>> frate	1
>> livio	1
>> 
>> The output I want is to have :
>> ralph and 'elenour.. how can I do this?
>
>You are doing the comparison the wrong way: you are saying:
>
>for each line in the file:
>    is the line in the dict?
>    if no, print the line
>
>
>What you want is:
>
>for each key in the dict:
>    is the key in the file?
>    if no, print the key
>
>
>It is not easy to try searching the file directly, so we copy the lines 
>from the file into a set:
>
>lines = set()
>with open("data.tmp") as the_file:
>    for line in the_file:
>        line = line.strip().split("\t")[0]
>        lines.add(line)
>
>
>Here is a shorter way to do the same thing:
>
>with open("data.tmp") as the_file:
>    lines = set([line.strip().split("\t")[0] for line in the_file])
>
>
>Now you can walk through the dict:
>
>for name in diz:
>    if name not in lines:
>        print(name) 
>
>
>Or, if you prefer:
>
>names = set(diz)  # copy the keys from the dict into a set
>print(names.difference(lines))
>
>
>If you want to see the other way around:
>
>print(lines.difference(names))
>
>
>
>
>-- 
>Steven
>
>
>------------------------------
>
>Message: 3
>Date: Tue, 22 Jul 2014 13:48:09 +0200
>From: Peter Otten <__peter__ at web.de>
>To: tutor at python.org
>Subject: Re: [Tutor] How to show dictionary item non present on file
>Message-ID: <lqlj1q$6ph$1 at ger.gmane.org>
>Content-Type: text/plain; charset="ISO-8859-1"
>
>jarod_v6 at libero.it wrote:
>
>> Hin there!!!
>> 
>> I have a niave question on dictionary analysis:
>> If you have a dictionary like this:
>> diz
>> Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}
>> 
>> and you have a list and you want to know which  keys are not present on my
>> dictionary the code are simple.
>> for i in diz.keys():
>>    ...:     if i in mitico:
>>    ...:         print "NO"
>>    ...:     else:
>>    ...:         print i
>>    ...:
>> NO
>> 
>> But I havethis problem I have a file and I want to know which elements are
>> not present on my file from dictionary.
>>  more data.tmp
>> jack	1
>> pippo	1
>> luis	1
>> frate	1
>> livio	1
>> frank	1
>> 
>> 
>> with open("data.tmp") as p:
>>     for i in p:
>>         lines= i.strip("\n").split("\t")
>>         if not diz.has_key(lines[0]):
>>    ....:             print i
>>    ....:
>> pippo	1
>> 
>> luis	1
>> 
>> frate	1
>> 
>> livio	1
>> 
>> The output I want is to have :
>> ralph and 'elenour.. how can I do this?
>> thanks in advance!
>
>You have the logic backwards. You have to iterate over the names in the dict 
>and look them up in the file:
>
>>>> diz = {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}
>>>> def find_name(name):
>...     with open("data.tmp") as f:
>...             for line in f:
>...                     if name == line.split("\t")[0]:
>...                             return True
>...     return False
>... 
>>>> for name in diz:
>...     if not find_name(name):
>...             print name
>... 
>ralph
>elenour
>
>However, this is very inefficient as you have to read the file len(diz) 
>times. It is better to store the names in a data structure suited for fast 
>lookup first and then to use that instead of the file. Python's dict and set 
>types are such data structures, so as we don't care about an associated 
>value let's use a set:
>
>>>> with open("data.tmp") as f:
>...     names_in_file = {line.split("\t")[0] for line in f}
>... 
>>>> for name in diz:
>...     if not name in names_in_file:
>...             print name
>... 
>ralph
>elenour
>
>Digging a bit deeper you'll find that you can get these names with set 
>arithmetic:
>
>>>> set(diz) - names_in_file
>set(['ralph', 'elenour'])
>
>or even:
>
>>>> diz.viewkeys() - names_in_file
>set(['elenour', 'ralph'])
>
>
>
>
>
>------------------------------
>
>Message: 4
>Date: Tue, 22 Jul 2014 16:10:02 -0700 (PDT)
>From: Eric Dannewitz <edannewitz at rdschool.org>
>To: tutor at python.org
>Subject: [Tutor] Getting a directory listing with Python to MySQL
>Message-ID:
>	<156945655.610335.1406070602162.JavaMail.zimbra at rdschool.org>
>Content-Type: text/plain; charset="utf-8"
>
>Hello list, I'm new. I've done a few things in Python, but this one is posing 
problems. 
>
>What I want to do is be able to parse a directory, say /Volumes/Stuff/Files/, 
and all the directories that might be in there, and be able to pick out file 
name, size, date modified, etc, and send that to a MySQL database. Any ideas? 
Sounds like it should be easy but...... 
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140722/0a8c664b/attachment-0001.html>
>
>------------------------------
>
>Message: 5
>Date: Tue, 22 Jul 2014 18:14:55 -0700
>From: Danny Yoo <dyoo at hashcollision.org>
>To: Eric Dannewitz <edannewitz at rdschool.org>
>Cc: Python Tutor Mailing List <tutor at python.org>
>Subject: Re: [Tutor] Getting a directory listing with Python to MySQL
>Message-ID:
>	<CAGZAPF7Xi1ks5tk2c6E3X+o-e8nx9JNZq1kiEuceMQxaYAi9oQ at mail.gmail.com>
>Content-Type: text/plain; charset="utf-8"
>
>> What I want to do is be able to parse a directory, say
>/Volumes/Stuff/Files/, and all the directories that might be in there, and
>be able to pick out file name, size, date modified, etc,
>
>Hi Eric,
>
>You might find the following helpful:
>http://www.diveintopython.net/file_handling/os_module.html
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140722/1011b814/attachment-0001.html>
>
>------------------------------
>
>Message: 6
>Date: Wed, 23 Jul 2014 11:31:48 +1000
>From: Steven D'Aprano <steve at pearwood.info>
>To: tutor at python.org
>Subject: Re: [Tutor] Getting a directory listing with Python to MySQL
>Message-ID: <20140723013146.GQ9112 at ando>
>Content-Type: text/plain; charset=us-ascii
>
>On Tue, Jul 22, 2014 at 04:10:02PM -0700, Eric Dannewitz wrote:
>> Hello list, I'm new. I've done a few things in Python, but this one is 
posing problems. 
>> 
>> What I want to do is be able to parse a directory, say 
>> /Volumes/Stuff/Files/, and all the directories that might be in there, 
>> and be able to pick out file name, size, date modified, etc, and send 
>> that to a MySQL database. Any ideas? Sounds like it should be easy 
>> but......
>
>os.listdir(path) returns all the entries under path (apart from '.' and 
>'..'). You can then test whether they are files, directories or links 
>with os.path.isdir, os.path.isfile, os.path.islink. (Remember that under 
>Linux and Unix, there things other than files and links that can live in 
>directories, e.g. named pipes.)
>
>But rather than manually iterate through the contents of the directory, 
>os.walk already does that for you. Something like this ought to get you 
>started:
>
>files = []
>for dirpath, dirnames, filenames in os.walk(start_path):
>    pathnames = [os.path.join(dirpath, name) for name in filenames]
>    files.extend(pathnames)
>
>
>That gets you a list of all the files under start_path. To check their 
>size, dates, etc. use the os.stat and os.lstat functions (os.stat 
>follows symbolic links, os.lstat does not). The stat module has a bunch 
>of symbolic constants which may be helpful for interpreting the results.
>
>
>
>
>-- 
>Steven
>
>
>------------------------------
>
>Message: 7
>Date: Tue, 22 Jul 2014 18:32:43 -0700 (PDT)
>From: Eric Dannewitz <edannewitz at rdschool.org>
>To: Python Tutor Mailing List <tutor at python.org>
>Subject: Re: [Tutor] Getting a directory listing with Python to MySQL
>Message-ID:
>	<1073549999.618930.1406079163039.JavaMail.zimbra at rdschool.org>
>Content-Type: text/plain; charset="utf-8"
>
>That's close. I have been playing from glob and os.walk but I'm at a loss how 
to get the size, creation and modified date while running it. 
>
>----- Original Message -----
>
>From: "Danny Yoo" <dyoo at hashcollision.org> 
>To: "Eric Dannewitz" <edannewitz at rdschool.org> 
>Cc: "Python Tutor Mailing List" <tutor at python.org> 
>Sent: Tuesday, July 22, 2014 6:14:55 PM 
>Subject: Re: [Tutor] Getting a directory listing with Python to MySQL 
>
>
>
>
>> What I want to do is be able to parse a directory, say 
/Volumes/Stuff/Files/, and all the directories that might be in there, and be 
able to pick out file name, size, date modified, etc, 
>
>Hi Eric, 
>
>You might find the following helpful: http://www.diveintopython.
net/file_handling/os_module.html 
>
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: <http://mail.python.
org/pipermail/tutor/attachments/20140722/cbaaa832/attachment.html>
>
>------------------------------
>
>Subject: Digest Footer
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>https://mail.python.org/mailman/listinfo/tutor
>
>
>------------------------------
>
>End of Tutor Digest, Vol 125, Issue 71
>**************************************
>



From wolfgang.maier at biologie.uni-freiburg.de  Wed Jul 23 10:18:29 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Wed, 23 Jul 2014 10:18:29 +0200
Subject: [Tutor] (no subject)
In-Reply-To: <1406079411.81532.YahooMailNeo@web161301.mail.bf1.yahoo.com>
References: <1405870848.96424.YahooMailNeo@web161302.mail.bf1.yahoo.com>
 <CAKK8jXZpe=pBi8k4KQ60zXd92MbtjKaTxkBjxSzrNa8jtYmDJg@mail.gmail.com>
 <53CC38ED.40404@biologie.uni-freiburg.de>
 <1405900119.88493.YahooMailNeo@web161305.mail.bf1.yahoo.com>
 <53CCC6CC.9030008@biologie.uni-freiburg.de>
 <1406079411.81532.YahooMailNeo@web161301.mail.bf1.yahoo.com>
Message-ID: <53CF6FD5.1070307@biologie.uni-freiburg.de>

On 07/23/2014 03:36 AM, LN A-go-go wrote:
> Hi again and thank-you Wolfgang and company.  I wish I could give you
> snickers bars or something!  I was able to get through the road_blocks
> with your help.  I have been working the last few days, I am sorry to
> say, unsuccessfully, to calculate the mean (that's easy), split the data
> into sub-groups or secondary means - which are the break values between
> 4 classes.  Create data-sets with incursive values.  I can do it with
> brute force (copy and paste) but need to rise to the pythonic way and
> use a while loop and a nested if-else structure.  My attempts have been
> lame enough that I don't even want to put them here.

Before addressing your question, I guess it's time that you start 
following the etiquette on this list:
1) start a new thread when you ask a new question
2) give the thread a telling subject line
3) show your attempts (even if you think they are lame)
4) show only the relevant part of your code (makes it easier for 
evereybody to read your post, but often sitting down and writing a 
streamlined version of what you have done before posting also helps you 
to understand what the actual problem is)

Finally and as suggested by others, it is really time that you start 
writing programs instead of just typing individual commands in the 
interactive interpreter. Use IDLE or any text editor for that.

I'll be following point 1 and 2 from the list above and answer your 
question in a separate thread.

Best,
Wolfgang


From wolfgang.maier at biologie.uni-freiburg.de  Wed Jul 23 11:28:15 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Wed, 23 Jul 2014 11:28:15 +0200
Subject: [Tutor] binning data and calculating means of classes
Message-ID: <53CF802F.1030601@biologie.uni-freiburg.de>

On 07/23/2014 03:36 AM, LN A-go-go wrote:
 >
 > with your help.  I have been working the last few days, I am sorry to
 > say, unsuccessfully, to calculate the mean (that's easy), split the data
 > into sub-groups or secondary means - which are the break values between
 > 4 classes.  Create data-sets with incursive values.  I can do it with
 > brute force (copy and paste) but need to rise to the pythonic way and
 > use a while loop and a nested if-else structure.  My attempts have been
 > lame enough that I don't even want to put them here.

A while loop with an if inside is indeed a very plausible solution, so 
it would be interesting to see your attempts.

 > int_list
 > [36, 39, 39, 45, 61, 54, 61, 93, 62, 51, 47, 72, 54, 36, 62, 50, 41, 41,
 > 40, 62, 62, 58, 57, 54, 49, 43, 47, 50, 45, 41, 54, 57, 57, 55, 62, 51,
 > 34, 57, 55, 63, 45, 45, 42, 44, 34, 53, 67, 58, 56, 43, 33]
 >>>> int_list.sort()
 >>>> int_list
 > [33, 34, 34, 36, 36, 39, 39, 40, 41, 41, 41, 42, 43, 43, 44, 45, 45, 45,
 > 45, 47, 47, 49, 50, 50, 51, 51, 53, 54, 54, 54, 54, 55, 55, 56, 57, 57,
 > 57, 57, 58, 58, 61, 61, 62, 62, 62, 62, 62, 63, 67, 72, 93]
 >>>> flo_list = [float(integral) for integral in int_list]

While this last line shows that you've started using list 
comprehensions, which is a good thing, converting your data to floating 
point is not a good idea. It is completely unnecessary and (though 
probably not relevant here) can compromise the accuracy of calculations 
due to inherent rounding errors.
I guess you are doing this to prevent subsequent rounding of the result 
of sum(int_list)/len(int_list).
This is a Python2-specific issue and, personally, I think that as a 
beginner you should use Python3, where (among other things) this is not 
a problem.
If you want to stick to Python2 for whatever reason then do:

from __future__ import division

after which integer divisions return a float if required just as in Python3.

 >>> sum(int_list)/len(int_list)
51.31372549019608

 >>>> flo_list
 > [33.0, 34.0, 34.0, 36.0, 36.0, 39.0, 39.0, 40.0, 41.0, 41.0, 41.0, 42.0,
 > 43.0, 43.0, 44.0, 45.0, 45.0, 45.0, 45.0, 47.0, 47.0, 49.0, 50.0, 50.0,
 > 51.0, 51.0, 53.0, 54.0, 54.0, 54.0, 54.0, 55.0, 55.0, 56.0, 57.0, 57.0,
 > 57.0, 57.0, 58.0, 58.0, 61.0, 61.0, 62.0, 62.0, 62.0, 62.0, 62.0, 63.0,
 > 67.0, 72.0, 93.0]
 >>>> sum(flo_list)
 > 2617.0
 >>>>  totalnum = sum(flo_list)

stop generating references if you're not going to use them later!
Confuses you and others.

 >>>> len(flo_list)
 > 51
 >>>> mean = sum(flo_list)/len(flo_list)
 >>>> mean
 > 51.31372549019608

So, you know how to calculate the total mean. For the means of 
subsamples what you have to do is to apply that same logic to subsamples 
of the data, which you have to generate.
Without going through the lists of values several times, however, I 
cannot think of any simple implementation of this, which does not 
involve plenty of novel concepts.
One fairly simple approach would be through a while loop as you 
suggested, but as said before, for loops are often more elegant in 
Python. I guess the following code is roughly what you had in mind ?

breakpoints = [your_list_of breakpoints]
large_value_buffer = []
int_list_iter = iter(int_list) # see comment below
for breakpoint in breakpoints:
	sublist = large_value_buffer
	for value in int_list_iter:
		if value < breakpoint:
			sublist.append(value)
			if large_value_buffer:
				large_value_buffer = []
		else:
			if sublist:
				print(sum(sublist)/len(sublist))
				large_value_buffer.append(value)
			break

Essentially, you should know all elements of this small program except 
the iter(int_list). Essentially, this gives you a one-time iterator, 
which cannot be reused or reset, to use in the inner for loop. This 
prevents starting from the beginning of the list every time.

Since this is probably too complicated for you to work it out by 
yourself at this stage, I decided to give you the complete code, but 
make sure you understand what it does, especially think about what the 
large_value_buffer is doing.

One problem with this code is that it silently skips empty bins. Maybe 
that's something for you to work on ?

Best,
Wolfgang


From wolfgang.maier at biologie.uni-freiburg.de  Wed Jul 23 11:34:30 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Wed, 23 Jul 2014 11:34:30 +0200
Subject: [Tutor] binning data and calculating means of classes
In-Reply-To: <53CF802F.1030601@biologie.uni-freiburg.de>
References: <53CF802F.1030601@biologie.uni-freiburg.de>
Message-ID: <lqnvh5$c69$2@ger.gmane.org>

On 07/23/2014 11:28 AM, Wolfgang Maier wrote:
>
> breakpoints = [your_list_of breakpoints]
> large_value_buffer = []
> int_list_iter = iter(int_list) # see comment below
> for breakpoint in breakpoints:
>      sublist = large_value_buffer
>      for value in int_list_iter:
>          if value < breakpoint:
>              sublist.append(value)
>              if large_value_buffer:
>                  large_value_buffer = []
>          else:
>              if sublist:
>                  print(sum(sublist)/len(sublist))
>                  large_value_buffer.append(value)

oops, the last line above needs outdenting by one level.

>              break
>



From dyoo at hashcollision.org  Wed Jul 23 18:22:28 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Wed, 23 Jul 2014 09:22:28 -0700
Subject: [Tutor] Getting a directory listing with Python to MySQL
In-Reply-To: <1073549999.618930.1406079163039.JavaMail.zimbra@rdschool.org>
References: <2029058402.610320.1406070571950.JavaMail.zimbra@rdschool.org>
 <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
 <CAGZAPF7Xi1ks5tk2c6E3X+o-e8nx9JNZq1kiEuceMQxaYAi9oQ@mail.gmail.com>
 <1073549999.618930.1406079163039.JavaMail.zimbra@rdschool.org>
Message-ID: <CAGZAPF6R6oD4vCNaCOmBihk1OJqg_09CZ3JkBurM4Mz8y5W5Cg@mail.gmail.com>

On Jul 22, 2014 11:10 PM, "Eric Dannewitz" <edannewitz at rdschool.org> wrote:
>
> That's close. I have been playing from glob and os.walk but I'm at a loss
how to get the size, creation and modified date while running it.

Steven mentioned a few functions in his reply; check those ones out.  The
'os' module is a bit large, but I'm pretty sure what you're looking for is
there.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140723/e77e79da/attachment.html>

From ch2009 at arcor.de  Wed Jul 23 17:49:00 2014
From: ch2009 at arcor.de (Chris)
Date: Wed, 23 Jul 2014 17:49:00 +0200
Subject: [Tutor] Using module Facebook
In-Reply-To: <1405885707.57493.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
References: <1405885707.57493.BPMail_high_noncarrier@web163802.mail.gq1.yahoo.com>
Message-ID: <53CFD96C.2080004@arcor.de>

On 07/20/2014 09:48 PM, Albert-Jan Roskam wrote:
> Hi, just wondering: why are you cloning the repo? You pip install
> from Pypi.  You can also pip install from the repo.

I didn't know that this is possible directly.

-- 
Christian

From jitu.icfai at gmail.com  Thu Jul 24 13:35:24 2014
From: jitu.icfai at gmail.com (jitendra gupta)
Date: Thu, 24 Jul 2014 17:05:24 +0530
Subject: [Tutor] Error Handling in python
Message-ID: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>

Hi All

My shell script is not throwing any error when I am having  some error in
Python code.

~~~~~~~~ test.py ~~~~~~
def main():
    print "Test"
    #some case error need to be thrown
    raise Exception("Here is error")

if __name__ == "__main__"
    main()
~~~~~~
~~~~~~~~ second.py ~~~~~~
def main():
    print "Second function is called"


if __name__ == "__main__"
    main()
~~~~~~

~~~~~ shellTest.sh ~~~~~~~
python test.py
python second.py
~~~~~~~~~~~~~~~~~~~~~~~

In this case, I dont want to run my second.py
Even I am throwing error from my test.py, but still second.py is getting
executed, which i dont want,


Thanks & Regards
Jitendra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140724/df5a3f3c/attachment.html>

From kwpolska at gmail.com  Thu Jul 24 13:53:14 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Thu, 24 Jul 2014 13:53:14 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
Message-ID: <CAMw+j7+T942aSr3fDb2Aa0fbM394+cCwh=kP+_FEMWWCCW1VGA@mail.gmail.com>

On Thu, Jul 24, 2014 at 1:35 PM, jitendra gupta <jitu.icfai at gmail.com> wrote:
> Hi All
>
> My shell script is not throwing any error when I am having  some error in
> Python code.
>
> In this case, I dont want to run my second.py
> Even I am throwing error from my test.py, but still second.py is getting
> executed, which i dont want,

You must expilicitly ask your shell to do exit if something fails.  Like this:

~~~~~ shellTest.sh ~~~~~~~
#!/bin/bash
set -e
python test.py
python second.py
~~~~~~~~~~~~~~~~~~~~~~~

I explicitly set the shell to /bin/bash on the shebang line, and then
set the -e option to fail when a command exits with a non-zero status.

You should always have a shebang line in your shell files, and execute
them as ./shellTest.sh  (after chmod +x shellTest.sh); moreover, one
for Python files is recommended, like this: #!/usr/bin/env python

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From wolfgang.maier at biologie.uni-freiburg.de  Thu Jul 24 14:01:40 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Thu, 24 Jul 2014 14:01:40 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
Message-ID: <53D0F5A4.6070902@biologie.uni-freiburg.de>

On 24.07.2014 13:35, jitendra gupta wrote:
> Hi All
>
> My shell script is not throwing any error when I am having  some error
> in Python code.
>
> ~~~~~~~~ test.py ~~~~~~
> def main():
>      print "Test"
>      #some case error need to be thrown
>      raise Exception("Here is error")
>
> if __name__ == "__main__"
>      main()
> ~~~~~~
> ~~~~~~~~ second.py ~~~~~~
> def main():
>      print "Second function is called"
>
>
> if __name__ == "__main__"
>      main()
> ~~~~~~
>
> ~~~~~ shellTest.sh ~~~~~~~
> python test.py
> python second.py
> ~~~~~~~~~~~~~~~~~~~~~~~
>
> In this case, I dont want to run my second.py
> Even I am throwing error from my test.py, but still second.py is getting
> executed, which i dont want,
>

Your shell script calls runs the two Python scripts separately, that is, 
it first starts a Python interpreter telling it to run test.py .
When that is done (with whatever outcome !), it starts the interpreter a 
second time telling it to run second.py now.
The exception stops the execution of test.py, of course, and causes the 
interpreter to return, but your shell script is responsible for checking 
the exit status of the first script if it wants to run the second call 
only conditionally.

Try something like this (assuming bash):

python test.py
if [ $? = 0 ]; then
     python second.py
fi

as your shell script.

By the way, both Python scripts you posted contain a syntax error, but I 
leave spotting it up to you.

Best,
Wolfgang

From steve at pearwood.info  Thu Jul 24 14:08:05 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Thu, 24 Jul 2014 22:08:05 +1000
Subject: [Tutor] Error Handling in python
In-Reply-To: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
Message-ID: <20140724120805.GT9112@ando>

On Thu, Jul 24, 2014 at 05:05:24PM +0530, jitendra gupta wrote:
> Hi All
> 
> My shell script is not throwing any error when I am having  some error in
> Python code.

This is a question about the shell, not about Python. I'm not an expert 
on shell scripting, but I'll try to give an answer.


> ~~~~~ shellTest.sh ~~~~~~~
> python test.py
> python second.py


One fix is to check the return code of the first python process:

[steve at ando ~]$ python -c pass
[steve at ando ~]$ echo $?
0
[steve at ando ~]$ python -c "raise Exception"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
Exception
[steve at ando ~]$ echo $?
1


Remember that to the shell, 0 means "no error" and anything else is an 
error. So your shell script could look like this:

python test.py
if [ "$?" -eq 0 ]
then
  python second.py
fi



Another way (probably better) is to tell the shell to automatically exit 
if any command fails:


set -e
python test.py
python second.py



Hope this helps,


-- 
Steven

From kwpolska at gmail.com  Thu Jul 24 14:09:54 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Thu, 24 Jul 2014 14:09:54 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <53D0F5A4.6070902@biologie.uni-freiburg.de>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
Message-ID: <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>

On Thu, Jul 24, 2014 at 2:01 PM, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
> Try something like this (assuming bash):
>
> python test.py
> if [ $? = 0 ]; then
>     python second.py
> fi
>
> as your shell script.

The [ ] and = should be doubled.  But all this is not needed, all you need is:

python test.py && python second.py

However, you need to explicitly stack all the commands you want to
execute this way ? so, if there are more things, `set -e` might also
be of use. (you would need an even uglier tree for `if`s.)

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From wolfgang.maier at biologie.uni-freiburg.de  Thu Jul 24 14:14:19 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Thu, 24 Jul 2014 14:14:19 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
 <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
Message-ID: <53D0F89B.8080003@biologie.uni-freiburg.de>

On 24.07.2014 14:09, Chris ?Kwpolska? Warrick wrote:
> On Thu, Jul 24, 2014 at 2:01 PM, Wolfgang Maier
> <wolfgang.maier at biologie.uni-freiburg.de> wrote:
>> Try something like this (assuming bash):
>>
>> python test.py
>> if [ $? = 0 ]; then
>>      python second.py
>> fi
>>
>> as your shell script.
>
> The [ ] and = should be doubled.

?? why that ?

But all this is not needed, all you need is:
>
> python test.py && python second.py

I agree, that's far more elegant in this case.

>
> However, you need to explicitly stack all the commands you want to
> execute this way ? so, if there are more things, `set -e` might also
> be of use. (you would need an even uglier tree for `if`s.)
>

From kwpolska at gmail.com  Thu Jul 24 14:19:19 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Thu, 24 Jul 2014 14:19:19 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <53D0F89B.8080003@biologie.uni-freiburg.de>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
 <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
 <53D0F89B.8080003@biologie.uni-freiburg.de>
Message-ID: <CAMw+j7J_dBFpHr=y0PJmGVUMHsrmsQPvXneajJ8e_2onWdZVyQ@mail.gmail.com>

On Thu, Jul 24, 2014 at 2:14 PM, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
> On 24.07.2014 14:09, Chris ?Kwpolska? Warrick wrote:
>>
>> On Thu, Jul 24, 2014 at 2:01 PM, Wolfgang Maier
>> <wolfgang.maier at biologie.uni-freiburg.de> wrote:
>>>
>>> Try something like this (assuming bash):
>>>
>>> python test.py
>>> if [ $? = 0 ]; then
>>>      python second.py
>>> fi
>>>
>>> as your shell script.
>>
>>
>> The [ ] and = should be doubled.
>
>
> ?? why that ?

Double brackets can do more:

http://stackoverflow.com/questions/2188199/how-to-use-double-or-single-bracket-parentheses-curly-braces

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From wolfgang.maier at biologie.uni-freiburg.de  Thu Jul 24 14:23:49 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Thu, 24 Jul 2014 14:23:49 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <CAMw+j7J_dBFpHr=y0PJmGVUMHsrmsQPvXneajJ8e_2onWdZVyQ@mail.gmail.com>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
 <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
 <53D0F89B.8080003@biologie.uni-freiburg.de>
 <CAMw+j7J_dBFpHr=y0PJmGVUMHsrmsQPvXneajJ8e_2onWdZVyQ@mail.gmail.com>
Message-ID: <53D0FAD5.2080108@biologie.uni-freiburg.de>

On 24.07.2014 14:19, Chris ?Kwpolska? Warrick wrote:
>
>>>> python test.py
>>>> if [ $? = 0 ]; then
>>>>       python second.py
>>>> fi
>>>>
>>>> as your shell script.
>>>
>>>
>>> The [ ] and = should be doubled.
>>
>>
>> ?? why that ?
>
> Double brackets can do more:
>
> http://stackoverflow.com/questions/2188199/how-to-use-double-or-single-bracket-parentheses-curly-braces
>

But more is not required here. What am I missing ?


From kwpolska at gmail.com  Thu Jul 24 14:37:11 2014
From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=)
Date: Thu, 24 Jul 2014 14:37:11 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <53D0FAD5.2080108@biologie.uni-freiburg.de>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
 <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
 <53D0F89B.8080003@biologie.uni-freiburg.de>
 <CAMw+j7J_dBFpHr=y0PJmGVUMHsrmsQPvXneajJ8e_2onWdZVyQ@mail.gmail.com>
 <53D0FAD5.2080108@biologie.uni-freiburg.de>
Message-ID: <CAMw+j7J141Tf-qQ5muPfcm5a4zdnmqPB+RvahmcbY4=eGXF7RQ@mail.gmail.com>

On Thu, Jul 24, 2014 at 2:23 PM, Wolfgang Maier
<wolfgang.maier at biologie.uni-freiburg.de> wrote:
> On 24.07.2014 14:19, Chris ?Kwpolska? Warrick wrote:
>>
>>
>>>>> python test.py
>>>>> if [ $? = 0 ]; then
>>>>>       python second.py
>>>>> fi
>>>>>
>>>>> as your shell script.
>>>>
>>>>
>>>>
>>>> The [ ] and = should be doubled.
>>>
>>>
>>>
>>> ?? why that ?
>>
>>
>> Double brackets can do more:
>>
>>
>> http://stackoverflow.com/questions/2188199/how-to-use-double-or-single-bracket-parentheses-curly-braces
>>
>
> But more is not required here. What am I missing ?

It?s recommended to switch to the [[ syntax anyways, some people
consider [ deprecated.  Also, [ is actually /bin/[ while [[ lives in
your shell (and is therefore faster).

About the equals sign, == is the preferred syntax, and = is also
considered deprecated (zsh explicitly says so, bash says ?only for
POSIX compatibility?.

-- 
Chris ?Kwpolska? Warrick <http://chriswarrick.com/>
PGP: 5EAAEA16
stop html mail | always bottom-post | only UTF-8 makes sense

From wolfgang.maier at biologie.uni-freiburg.de  Thu Jul 24 14:40:44 2014
From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier)
Date: Thu, 24 Jul 2014 14:40:44 +0200
Subject: [Tutor] Error Handling in python
In-Reply-To: <CAMw+j7J141Tf-qQ5muPfcm5a4zdnmqPB+RvahmcbY4=eGXF7RQ@mail.gmail.com>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
 <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
 <53D0F89B.8080003@biologie.uni-freiburg.de>
 <CAMw+j7J_dBFpHr=y0PJmGVUMHsrmsQPvXneajJ8e_2onWdZVyQ@mail.gmail.com>
 <53D0FAD5.2080108@biologie.uni-freiburg.de>
 <CAMw+j7J141Tf-qQ5muPfcm5a4zdnmqPB+RvahmcbY4=eGXF7RQ@mail.gmail.com>
Message-ID: <53D0FECC.4060705@biologie.uni-freiburg.de>

On 24.07.2014 14:37, Chris ?Kwpolska? Warrick wrote:
>
> It?s recommended to switch to the [[ syntax anyways, some people
> consider [ deprecated.  Also, [ is actually /bin/[ while [[ lives in
> your shell (and is therefore faster).
>
> About the equals sign, == is the preferred syntax, and = is also
> considered deprecated (zsh explicitly says so, bash says ?only for
> POSIX compatibility?.
>

I see. There is always something to learn, thanks (even if it's not 
Python-related as Steven points out correctly) :)


From allahondoum1991 at gmail.com  Thu Jul 24 11:09:19 2014
From: allahondoum1991 at gmail.com (Allahondoum Mbaibarem)
Date: Thu, 24 Jul 2014 09:09:19 +0000
Subject: [Tutor] Inquiry
Message-ID: <CAA6c=jub1329EfnLEj51R9vccCi=8MGa=w5Hw6xFi1oOqqZ13A@mail.gmail.com>

Please I would like to know about the Security and the Reliability of
Python. Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140724/30f5fe5f/attachment.html>

From allahondoum1991 at gmail.com  Thu Jul 24 12:11:41 2014
From: allahondoum1991 at gmail.com (Allahondoum Mbaibarem)
Date: Thu, 24 Jul 2014 10:11:41 +0000
Subject: [Tutor] Security and Reliability of Python
Message-ID: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>

I'm new at python and I would like to have knowledge about the Security and
the Reliability factor of Python thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140724/244ff379/attachment.html>

From glester at avant.ca  Fri Jul 25 00:50:30 2014
From: glester at avant.ca (Glenn Lester)
Date: Thu, 24 Jul 2014 17:50:30 -0500
Subject: [Tutor] Read a file, Load a dictionary
Message-ID: <CAAJkYqfR7u2HFNgchhf3XkDMiAKP7PD+2F_P_VjFuoGxdumW3A@mail.gmail.com>

I have been looking around for a way to read a comma delimited csv file and
then load it into a dictionary. So far any of my usual sources don't deal
with such simple stuff.

My current code is


# create a dictionary (dict) to store the order # and Remark
    testVariables = {}

# Read the file and load the dict
    input_file = open('test1Comma.csv', 'rU')
    for line in input_file:


I'm stuck on the code that comes next. what line of code loads the dict?

my csv file has 2 lines shown below.

AUTO-TEST-0021,REMARK 1
AUTO-TEST-0022,REMARK 2

Thanks in advance for the help.
-- 
<http://www.avant.ca/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140724/016d7925/attachment.html>

From emile at fenx.com  Fri Jul 25 01:05:17 2014
From: emile at fenx.com (Emile van Sebille)
Date: Thu, 24 Jul 2014 16:05:17 -0700
Subject: [Tutor] Security and Reliability of Python
In-Reply-To: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
References: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
Message-ID: <lqs3ff$l5v$1@ger.gmane.org>

On 7/24/2014 3:11 AM, Allahondoum Mbaibarem wrote:

> I'm new at python and I would like to have knowledge about the Security
> and the Reliability factor of Python thank you.

That's a pretty open-ended question.  It's as secure and reliable as 
what you write.  For most of us, it's as secure and reliable as we need 
it to be.

:)

Emile



From emile at fenx.com  Fri Jul 25 01:09:46 2014
From: emile at fenx.com (Emile van Sebille)
Date: Thu, 24 Jul 2014 16:09:46 -0700
Subject: [Tutor] Read a file, Load a dictionary
In-Reply-To: <CAAJkYqfR7u2HFNgchhf3XkDMiAKP7PD+2F_P_VjFuoGxdumW3A@mail.gmail.com>
References: <CAAJkYqfR7u2HFNgchhf3XkDMiAKP7PD+2F_P_VjFuoGxdumW3A@mail.gmail.com>
Message-ID: <lqs3nt$q6u$1@ger.gmane.org>

On 7/24/2014 3:50 PM, Glenn Lester wrote:
>
> I have been looking around for a way to read a comma delimited csv file

start with the csv module.

     http://www.python.org/doc/current/lib/module-csv.html

DESCRIPTION
     This module provides classes that assist in the reading and writing
     of Comma Separated Value (CSV) files...


> and then load it into a dictionary.


Emile



From davea at davea.name  Fri Jul 25 01:13:37 2014
From: davea at davea.name (Dave Angel)
Date: Thu, 24 Jul 2014 19:13:37 -0400 (EDT)
Subject: [Tutor] Read a file, Load a dictionary
References: <CAAJkYqfR7u2HFNgchhf3XkDMiAKP7PD+2F_P_VjFuoGxdumW3A@mail.gmail.com>
Message-ID: <lqs3ug$sde$1@ger.gmane.org>

Glenn Lester <glester at avant.ca> Wrote in message:

> 
?????????

You forgot to make your message a text one, and also omitted your
 Python version.  So I'll respond from memory,  assuming you're
 using version 3.5

The csv reader can make a dictionary from each line of the csv
 file. So you can readily make a list of dicts.


 https://docs.python.org/3.5/library/csv.html

-- 
DaveA


From davea at davea.name  Fri Jul 25 01:18:38 2014
From: davea at davea.name (Dave Angel)
Date: Thu, 24 Jul 2014 19:18:38 -0400 (EDT)
Subject: [Tutor] Security and Reliability of Python
References: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
Message-ID: <lqs47t$veg$1@ger.gmane.org>

Allahondoum Mbaibarem <allahondoum1991 at gmail.com> Wrote in message:
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

Post here using text messages,  not html.

Wait 24 hours, not one, before slamming us with a duplicate query.
  And when refining an existing thread,  use reply-list, not a new
 message with a different subject line.

Any further responses, please use the original thread.

-- 
DaveA


From davea at davea.name  Fri Jul 25 01:22:43 2014
From: davea at davea.name (Dave Angel)
Date: Thu, 24 Jul 2014 19:22:43 -0400 (EDT)
Subject: [Tutor] Inquiry
References: <CAA6c=jub1329EfnLEj51R9vccCi=8MGa=w5Hw6xFi1oOqqZ13A@mail.gmail.com>
Message-ID: <lqs4fh$veg$2@ger.gmane.org>

Allahondoum Mbaibarem <allahondoum1991 at gmail.com> Wrote in message:
>
> 
(use text messages here)

Python is no more secure than the code written in it.

It is very reliable,  according to the experience of thousands of
 users. Much of that comes from it being open-source; many eyes
 catch the bugs faster than anything proprietary.
 

Compared to what?


-- 
DaveA


From dyoo at hashcollision.org  Fri Jul 25 01:50:13 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 24 Jul 2014 16:50:13 -0700
Subject: [Tutor] Inquiry
In-Reply-To: <CAA6c=jub1329EfnLEj51R9vccCi=8MGa=w5Hw6xFi1oOqqZ13A@mail.gmail.com>
References: <CAA6c=jub1329EfnLEj51R9vccCi=8MGa=w5Hw6xFi1oOqqZ13A@mail.gmail.com>
Message-ID: <CAGZAPF7OycCx2gFqHHoOHswWL+2n9+e4exRbZRkDvVDgVaR6FA@mail.gmail.com>

On Jul 24, 2014 3:21 PM, "Allahondoum Mbaibarem" <allahondoum1991 at gmail.com>
wrote:
>
> Please I would like to know about the Security and the Reliability of
Python.

This is somewhat outside the domain of python-tutor discussion.  You may
want to contact the folks at:

http://www.pythonsecurity.org

instead.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140724/57da7e23/attachment.html>

From codemonkey at inbox.com  Fri Jul 25 03:58:44 2014
From: codemonkey at inbox.com (Deb Wyatt)
Date: Thu, 24 Jul 2014 17:58:44 -0800
Subject: [Tutor] Read a file, Load a dictionary
In-Reply-To: <lqs3ug$sde$1@ger.gmane.org>
References: <caajkyqfr7u2hfngchhf3xkdmiakp7pd+2f_p_vjfuogxdumw3a@mail.gmail.com>
Message-ID: <5800B3EDA58.0000014Bcodemonkey@inbox.com>

 assuming you're
>  using version 3.5
> 

How do you get version 3.5?  Python.org shows 3.41 as being the latest.

Deb in WA, USA

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!



From davea at davea.name  Fri Jul 25 04:25:59 2014
From: davea at davea.name (Dave Angel)
Date: Thu, 24 Jul 2014 22:25:59 -0400 (EDT)
Subject: [Tutor] Read a file, Load a dictionary
References: <caajkyqfr7u2hfngchhf3xkdmiakp7pd+2f_p_vjfuogxdumw3a@mail.gmail.com>
 <5800B3EDA58.0000014Bcodemonkey@inbox.com>
Message-ID: <lqsf75$ki5$1@ger.gmane.org>

Deb Wyatt <codemonkey at inbox.com> Wrote in message:
>  assuming you're
>>  using version 3.5
>> 
> 
> How do you get version 3.5?  Python.org shows 3.41 as being the latest.
> 
> 

I could as easily figured 2.6.  My point is that people need to
 specify what version they're asking about. 

3.5 is a dev version.  Not for production nor for learning python 
 one gets it by fetching from the repository and doing their own
 compile. 


-- 
DaveA


From steve at pearwood.info  Fri Jul 25 05:00:10 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 25 Jul 2014 13:00:10 +1000
Subject: [Tutor] Read a file, Load a dictionary
In-Reply-To: <lqsf75$ki5$1@ger.gmane.org>
References: <caajkyqfr7u2hfngchhf3xkdmiakp7pd+2f_p_vjfuogxdumw3a@mail.gmail.com>
 <5800B3EDA58.0000014Bcodemonkey@inbox.com> <lqsf75$ki5$1@ger.gmane.org>
Message-ID: <20140725030009.GW9112@ando>

On Thu, Jul 24, 2014 at 10:25:59PM -0400, Dave Angel wrote:
> Deb Wyatt <codemonkey at inbox.com> Wrote in message:
> >>  assuming you're  using version 3.5
> > 
> > How do you get version 3.5?  Python.org shows 3.41 as being the latest.
> 
> I could as easily figured 2.6.  My point is that people need to
>  specify what version they're asking about. 

Does the version number make much of a difference in this case? 

> 3.5 is a dev version.  Not for production nor for learning python 
>  one gets it by fetching from the repository and doing their own
>  compile. 

Do you figure that many beginners to Python are doing that?

-- 
Steven


From steve at pearwood.info  Fri Jul 25 05:18:54 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 25 Jul 2014 13:18:54 +1000
Subject: [Tutor] Security and Reliability of Python
In-Reply-To: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
References: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
Message-ID: <20140725031854.GX9112@ando>

On Thu, Jul 24, 2014 at 10:11:41AM +0000, Allahondoum Mbaibarem wrote:

> I'm new at python and I would like to have knowledge about the Security and
> the Reliability factor of Python thank you.

Python is very reliable. The language has been around for over 20 years, 
and is in use in tens of thousands if not more sites. Python is actively 
maintained, so when problems are reported, they are dealt with promptly.

But of course it is a programming language, which means the reliablity 
of code you write depends on *your* skill at programming. If you write 
buggy code, Python cannot save you from your own errors.

However, unlike low-level languages like C, you should not be able to 
cause a core dump or operating-system crash from Python code. (If you 
ever do find one of those, except for the ctypes module which is 
special, it is a bug in Python and should be reported immediately. But 
you won't: I've been using Python for over 15 years and have never 
managed to cause a core dump from Python code.)

Likewise, in Python you cannot have dangling pointer errors, buffer 
overflows, or any of those similar critical errors which lead to 
security failures. The worst you can have is an uncaught exception, 
which causes the Python process to write a traceback to standard error 
and exit.

Python is only as secure as the code *you* write. If you write code 
where you accept text from untrusted people over the Internet and then 
execute it as code using eval() or exec(), then your code is vulnerable 
to code injection attacks. The solution to this is simple: don't use 
eval() or exec() on untrusted data. There is hardly ever a need to use 
eval() or exec() in your own code. In 15 years, I've only used them a 
handful of times, and then mostly for experiments.


-- 
Steven

From dyoo at hashcollision.org  Fri Jul 25 06:46:58 2014
From: dyoo at hashcollision.org (Danny Yoo)
Date: Thu, 24 Jul 2014 21:46:58 -0700
Subject: [Tutor] Security and Reliability of Python
In-Reply-To: <20140725031854.GX9112@ando>
References: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
 <20140725031854.GX9112@ando>
Message-ID: <CAGZAPF7z9_bkic5gj-OninnmpRu39S1W0-7jV=rSZaonGH3O7Q@mail.gmail.com>

> Python is only as secure as the code *you* write. If you write code
> where you accept text from untrusted people over the Internet and then
> execute it as code using eval() or exec(), then your code is vulnerable
> to code injection attacks. The solution to this is simple: don't use
> eval() or exec() on untrusted data. There is hardly ever a need to use
> eval() or exec() in your own code. In 15 years, I've only used them a
> handful of times, and then mostly for experiments.


And we have to fight the good fight.  There are people out there who
think that eval() is fine to teach to beginners.  I do not understand
why.  As a concrete example that I came across today:

    https://plus.google.com/111222510165686226339/posts/jQrn9vkGxHA

Such teaching makes me very sad.  We have to really fight this hard to
keep people from writing dangerous code.  It's a bit frustrating
because the teacher there obviously knows enough to be dangerous, yet
not enough to be respectfully cautious.

From alan.gauld at btinternet.com  Fri Jul 25 08:15:38 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 25 Jul 2014 07:15:38 +0100
Subject: [Tutor] Read a file, Load a dictionary
In-Reply-To: <20140725030009.GW9112@ando>
References: <caajkyqfr7u2hfngchhf3xkdmiakp7pd+2f_p_vjfuogxdumw3a@mail.gmail.com>
 <5800B3EDA58.0000014Bcodemonkey@inbox.com> <lqsf75$ki5$1@ger.gmane.org>
 <20140725030009.GW9112@ando>
Message-ID: <lqssma$uei$1@ger.gmane.org>

On 25/07/14 04:00, Steven D'Aprano wrote:

>> 3.5 is a dev version.  Not for production nor for learning python
>>   one gets it by fetching from the repository and doing their own
>>   compile.
>
> Do you figure that many beginners to Python are doing that?

I think Dave was being a bit tongue in cheek.
He was responding to the lack of information in the OPs post
by picking an extreme example. At least that's how I read it.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From steve at pearwood.info  Fri Jul 25 09:36:10 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 25 Jul 2014 17:36:10 +1000
Subject: [Tutor] Read a file, Load a dictionary
In-Reply-To: <lqssma$uei$1@ger.gmane.org>
References: <caajkyqfr7u2hfngchhf3xkdmiakp7pd+2f_p_vjfuogxdumw3a@mail.gmail.com>
 <5800B3EDA58.0000014Bcodemonkey@inbox.com> <lqsf75$ki5$1@ger.gmane.org>
 <20140725030009.GW9112@ando> <lqssma$uei$1@ger.gmane.org>
Message-ID: <20140725073609.GY9112@ando>

On Fri, Jul 25, 2014 at 07:15:38AM +0100, Alan Gauld wrote:
> On 25/07/14 04:00, Steven D'Aprano wrote:
> 
> >>3.5 is a dev version.  Not for production nor for learning python
> >>  one gets it by fetching from the repository and doing their own
> >>  compile.
> >
> >Do you figure that many beginners to Python are doing that?
> 
> I think Dave was being a bit tongue in cheek.
> He was responding to the lack of information in the OPs post
> by picking an extreme example. At least that's how I read it.

:-)

Of course he was. And I was responding equally tongue in cheek. 

Sometimes the version number or operating system is as irrelevant to the 
question as is the manufacturer of their computer's memory, the brand of 
the hard drive, or the colour of their mouse. "More information" is not 
always useful, sometimes it just gets in the way, and if the answer we 
give does not depend on X then I don't think there's any good reason to 
insist that people tell us X and get snarky if they don't.

There's nothing wrong with answering "We need more information", and it 
seems to me that specifically making the point that the OP didn't report 
something of little or no relevence to the question up-front is rather 
passive-aggressive. No offence intended to Dave, who is usually very 
helpful but occasionally acts like an old grump shouting "You young'uns 
get off my lawn!" :-)

(As I've been known to do myself, from time to time, most recently 
with my snark about Twitter, so I do sympathise with him.)


-- 
Steven

From jitu.icfai at gmail.com  Fri Jul 25 09:34:17 2014
From: jitu.icfai at gmail.com (jitendra gupta)
Date: Fri, 25 Jul 2014 13:04:17 +0530
Subject: [Tutor] Error Handling in python
In-Reply-To: <53D0FECC.4060705@biologie.uni-freiburg.de>
References: <CAM6SjUK2r51WcyrQsr+rdU+Ug96cvuFXr_SyFF=sedGOws-SBA@mail.gmail.com>
 <53D0F5A4.6070902@biologie.uni-freiburg.de>
 <CAMw+j7LkkX_5Mu_Vx_SyqMq7gxPrEN2RUHW3EtaVLe1ASEbHoQ@mail.gmail.com>
 <53D0F89B.8080003@biologie.uni-freiburg.de>
 <CAMw+j7J_dBFpHr=y0PJmGVUMHsrmsQPvXneajJ8e_2onWdZVyQ@mail.gmail.com>
 <53D0FAD5.2080108@biologie.uni-freiburg.de>
 <CAMw+j7J141Tf-qQ5muPfcm5a4zdnmqPB+RvahmcbY4=eGXF7RQ@mail.gmail.com>
 <53D0FECC.4060705@biologie.uni-freiburg.de>
Message-ID: <CAM6SjU+QLKtvF43CWypG1Wgu=ezmV5pMvOjo1x-SfOxLBBfoAg@mail.gmail.com>

@All Thanks a lot,

Yes "set -e" It work fine. This is what I am looking for but I got some
extra things to learn :) .

Thanks you again

Thanks
Jitendra


On Thu, Jul 24, 2014 at 6:10 PM, Wolfgang Maier <
wolfgang.maier at biologie.uni-freiburg.de> wrote:

> On 24.07.2014 14:37, Chris ?Kwpolska? Warrick wrote:
>
>>
>> It?s recommended to switch to the [[ syntax anyways, some people
>> consider [ deprecated.  Also, [ is actually /bin/[ while [[ lives in
>> your shell (and is therefore faster).
>>
>> About the equals sign, == is the preferred syntax, and = is also
>> considered deprecated (zsh explicitly says so, bash says ?only for
>> POSIX compatibility?.
>>
>>
> I see. There is always something to learn, thanks (even if it's not
> Python-related as Steven points out correctly) :)
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140725/8d183965/attachment.html>

From steve at pearwood.info  Fri Jul 25 11:20:00 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 25 Jul 2014 19:20:00 +1000
Subject: [Tutor] Getting a directory listing with Python to MySQL
In-Reply-To: <1073549999.618930.1406079163039.JavaMail.zimbra@rdschool.org>
References: <2029058402.610320.1406070571950.JavaMail.zimbra@rdschool.org>
 <156945655.610335.1406070602162.JavaMail.zimbra@rdschool.org>
 <CAGZAPF7Xi1ks5tk2c6E3X+o-e8nx9JNZq1kiEuceMQxaYAi9oQ@mail.gmail.com>
 <1073549999.618930.1406079163039.JavaMail.zimbra@rdschool.org>
Message-ID: <20140725092000.GZ9112@ando>

On Tue, Jul 22, 2014 at 06:32:43PM -0700, Eric Dannewitz wrote:

> That's close. I have been playing from glob and os.walk but I'm at a 
> loss how to get the size, creation and modified date while running it.

Did you look at the functions in os.path as suggested? Here are the 
docs:  https://docs.python.org/2/library/os.path.html

Here's an example:

py> filename = '/tmp/rubbish'
py> with open(filename, 'w') as fp:
...     x = fp.write('hello world')
...
py> import os
py> os.path.getsize(filename)
11
py> os.path.getmtime(filename)
1406277914.0


To convert the timestamp into a datetime object and human-readable 
string:

py> import datetime
py> d = datetime.datetime.fromtimestamp(os.path.getmtime(filename))
py> d
datetime.datetime(2014, 7, 25, 18, 45, 14)
py>
py> d.strftime('%Y-%m-%d %H:%M:%S')
'2014-07-25 18:45:14'


By the way, "creation date" is not supported on all operating systems 
or file systems. The following is a little technical, but the executive 
summary is this:

    Python supports three file timestamps, atime, ctime and mtime.
    atime and mtime mean the same thing on every common system, but
    ctime does not: it may be creation time, or last change time.


This is where it starts getting complicated...

On Linux, Unix, Mac OS X, and other POSIX systems, three timestamps are 
normally recorded:

    atime: the last access (read or write) time
    ctime: the metadata change time, **not** creation time
    mtime: the last modification time

Metadata change time means when the file permissions or ownership 
changes. Some POSIX systems can record the birth or creation time as 
well, or the time of last backup, depending on the file system. BSD and 
recent versions of Cygwin also support btime (birth or creation time), 
but there's no easy way to get that information from Python.

On Windows, three or four timestamps are recorded, depending on the file 
system being used:

Windows using FAT file system (Windows 95, 98, most USB sticks):
    atime: the last access time
    ctime: the creation time
    mtime: the last modification time

Windows using NTFS file system (Windows NT, XP and newer):
    atime: the last access time
    ctime: the creation or birth time
    mtime: the last modification time
    plus the last metadata change time.

Only mtime is consistently recorded by all common file and operating 
systems. Although atime is also recorded, some systems allow you to turn 
it off so it is no longer updated.

In Python, you can use os.path.getatime, getctime and getmtime functions 
to return the atime (access), mtime (modification) and ctime (either 
creation or change) time.

Oh, one last thing: be aware that the different timestamps have 
different resolutions. For example, on FAT file systems (like many USB 
sticks), the access time has a resolution of a full day! So getatime() 
on a file on a USB stick will probably tell you only what *day* it was 
last accessed, not the actual time.



-- 
Steven

From davea at davea.name  Fri Jul 25 11:46:41 2014
From: davea at davea.name (Dave Angel)
Date: Fri, 25 Jul 2014 05:46:41 -0400 (EDT)
Subject: [Tutor] Security and Reliability of Python
References: <CAA6c=jufXH_yM+TG2Wx0BG-kBp9LTez-12_+ByS2-6V1gBri0w@mail.gmail.com>
 <20140725031854.GX9112@ando>
 <CAGZAPF7z9_bkic5gj-OninnmpRu39S1W0-7jV=rSZaonGH3O7Q@mail.gmail.com>
Message-ID: <lqt91f$nvv$1@ger.gmane.org>

Danny Yoo <dyoo at hashcollision.org> Wrote in message:
> > Python is only as secure as the code *you* write. If you write code
>> where you accept text from untrusted people over the Internet and then
>> execute it as code using eval() or exec(), then your code is vulnerable
>> to code injection attacks. The solution to this is simple: don't use
>> eval() or exec() on untrusted data. There is hardly ever a need to use
>> eval() or exec() in your own code. In 15 years, I've only used them a
>> handful of times, and then mostly for experiments.
> 
> 
> And we have to fight the good fight.  There are people out there who
> think that eval() is fine to teach to beginners.  I do not understand
> why.  As a concrete example that I came across today:
> 
>     https://plus.google.com/111222510165686226339/posts/jQrn9vkGxHA
> 
> Such teaching makes me very sad.  We have to really fight this hard to
> keep people from writing dangerous code.  It's a bit frustrating
> because the teacher there obviously knows enough to be dangerous, yet
> not enough to be respectfully cautious.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 
> 

I tried to leave the following comment on that site, but cannot
 figure how to use Google+ from a tablet.  I left it somewhere, 
 but apparently not on that page.

Why not introduce ast.literal-eval () ?
It's a whole lot safer than eval ()
-- 
DaveA


From jdcast at stanford.edu  Fri Jul 25 20:30:50 2014
From: jdcast at stanford.edu (John Cast)
Date: Fri, 25 Jul 2014 11:30:50 -0700
Subject: [Tutor] How to Create Webpage with Python
In-Reply-To: <lq40fe$7c3$1@ger.gmane.org>
References: <CAHdK22-pH+5BLEW6=B5NPxnd42Xf-418b5zCqKM3ysFwJCpsAg@mail.gmail.com>
 <lpkeut$ja5$1@ger.gmane.org>
 <CAHdK22-3ypHWG0a4j5UcErtJkiTFDUevmXgwZVVsMcQMSGskrg@mail.gmail.com>
 <CAMw+j7K3PyLjE3=vQEZ8LwR1aO2uJSb7wsT6nejHas+tcLsKNg@mail.gmail.com>
 <ce973d35eaed62ec314b893fddcde413@sonic.net>
 <CAMw+j7+gObksHU0H0V=zPdOopjO2f3Tr5un1KvmCt1LxtRx-2w@mail.gmail.com>
 <CAHdK228WkfuVFVz3w6nMkVi9v_gGFMNTJ_cmjvn+8u6owfMBAw@mail.gmail.com>
 <CAGZAPF7A01vFAHH7TS1nisLmV7mWHG3NdhSWeBtZ_uDPhdcZ-g@mail.gmail.com>
 <CAMw+j7JZC+N3b_R-RBPRB7_VjZd44CB1nq34iWxhigtEXOM6UQ@mail.gmail.com>
 <CAGZAPF44ygRo1kphNBthrnVrG4xJJgbp8yt--XENcgDHvw3BQg@mail.gmail.com>
 <CAGZAPF4o=wUcCk-xFucdQ59ZL6b847EjJb3=rFYS4Q_tJ2Z-Aw@mail.gmail.com>
 <CAHdK22_-xx+MdKvxj25B7yjkmYirZOeECngYFBC8C2GOvXMLfg@mail.gmail.com>
 <CAMw+j7LawVZLpPvbMgAE-8VcaAWtBbRMfAqEabFz2mhFiAJizQ@mail.gmail.com>
 <CAHdK22-t_YkLjZ4z=U1bef899MzZLkS_CAsNY_xohdd8D82D9A@mail.gmail.com>
 <lq40fe$7c3$1@ger.gmane.org>
Message-ID: <CAHdK22-LDY0+Zh-HswXHMpf0tvHWOZmc4hkDy+yiNc0erqcJSg@mail.gmail.com>

Hey everyone,

So against all of your better judgement I went ahead and implemented my
server through the simpleHTTPServer in python and used win32com to hook up
to excel to widen the existing excel columns and then call "SaveAs()" into
.htm format (basically programmatically doing the "save as webpage format
in excel" that you can do by hand) and then opening the server up in the
directory that I save these output HTML files.
This is a side project at work and the people that gave it to were quite
pleased with how it looked.  However, their enthusiasm led them to want
even more functionality.  This functionality includes making a couple of
graphs for each sheet in the excel workbook and serving these graphs up as
well as being able to store/edit comments for each row of each sheet in the
workbook once it's served up (each row of each sheet is basically a work
task with some information for it found in the columns).

Now the tricky part...
This script will eventually be used to routinely pull down information
found on some website (which it can already do), probably in a cron job.
 Doing this will find the most recent information for each excel sheet.  I
have to be able to keep track of this information over time and update the
graphs for each sheet accordingly (some rows may be deleted, some rows may
have edited comments (always last column) and some rows maybe completely
new, maybe even whole sheets will be gone or added as well). All of the
information in the excel sheets is text.  I would be counting text
occurrences for the graphs.

Since I cheated and used win32com to access excel and have it do the dirty
work of saving the excel workbook into HTML format I don't really have
direct access to the HTML creation and don't have a good way of storing
data pertaining to each sheet (i.e. graph information and comments for each
row of each sheet).  So I am thinking I am going to have to backtrack in my
work and take a new approach.

Here come my questions/ideas and I'd like to hear all of your thoughts on
them if you have time:

1) What are your ideas on how best to accomplish all of this given where I
have stated my project is at?

2) My current idea is to investigate some kind of database, probably mysql
so that I can store the information for each excel sheet.  Is this
smart/easy/possible/efficient?  I am guessing it might be possible to store
each excel sheet (or instead maybe the two graphs for each sheet and the
row/comment relations so as to only keep around what I really need) under a
name identifier as separate entities in the mysql database.  Is this
smart/easy/possible/efficient to do?

3) I am guessing I have to go back and redo how I generate my HTML.  Right
now I generate an index.html file that simply displays some text and then
has a hyperlink to the excel generated webpage version of the original
excel workbook.  The index.html is generated in python by printing it to a
new index.html file every time the script is run.  I would like to keep the
look of how excel generates each sheet into HTML (basically it just looks
like the exact excel sheet but on the web) while displaying two graphs for
each each sheet.  I was thinking I could simply insert the links for the
graphs into the index.html page or insert the links for the graphs into
their respective sheet's HTML page or simply display the graphs directly on
their respective sheet's HTML page.  What sounds reasonable/easiest here?

4) I need to somehow allows the comment cell in each row to be interactive
in the sense that it needs to be editable when it is displayed as well as
be persistent (stored).  I am at a bit of a loss as where to begin with
this.

5) Will I need to switch to a new server? e.g. Django, apache?  Or can I
keep doing things in the simpleHTTPServer within python?

Mind you that other than this project I have very little experience with
any of this.  That said I am looking for a fair balance of efficiency and
ease to accomplish all of this.  My time frame is about 3 weeks.

I welcome any help/tips/opinions that you all can offer.

Thanks


On Tue, Jul 15, 2014 at 12:46 PM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> On 15/07/14 17:48, John Cast wrote:
>
>  1) How does one automate the save as webpage from python?
>>
>
> It is possible using COM objects and the pywin32 library.
> However that's rarely the best way to approach things.
> But if you insist...
>
> Here is a short example of opening a FileOpen dialog...
>
> import win32com.client as com
> filepath = r"D:\Whatever\You\want"
> fileopen = 1  # change to whatever code you need of 1-4
> app = com.Dispatch("Excel.Ap[plication")
> app.Visible = True
> fd - app.FileDialog(fileopen)
> fd.InitialFileName = filepath
> fd.Title = "Open a file"
> if fd.Show() == -1:
>    fd.Execute()
>
> I'll let you use your imagination (and the MSDN web site?) to
> work out how to do a SaveAs dialog and populate it with the
> right values.
>
> The last 2 lines check if the user actually hit the Open or OK
> button and then tell Excel to open the file.
>
> There are other direct commands so you preobably can saveAs
> directly if you search the docs.
>
>
>  2) What is the most straightforward way to adjust the column widths of
>> the existing excel sheets?
>>
>
> Again its possible by using COM to drive the workbook objects.
> But again its not the best way to address this.
>
>
>  Any hints/guidance/answers are greatly appreciated.
>>
>
> OK, Use another approach!
>
> Use xlrd to read the data out and insert it into an HTML page.
> Use the one output by Excel as a template (although you can probably
> delete most of it as unnecessary cruft produced by Microsoft.(
>
> That gives you control over the look independent of anything
> the users of Excel may do.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140725/d9578015/attachment.html>

From alan.gauld at btinternet.com  Tue Jul 29 17:41:08 2014
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 29 Jul 2014 16:41:08 +0100
Subject: [Tutor] Read a file, Load a dictionary
In-Reply-To: <5800B3EDA58.0000014Bcodemonkey@inbox.com>
References: <caajkyqfr7u2hfngchhf3xkdmiakp7pd+2f_p_vjfuogxdumw3a@mail.gmail.com>
 <5800B3EDA58.0000014Bcodemonkey@inbox.com>
Message-ID: <lr8fak$o5$1@ger.gmane.org>

On 25/07/14 02:58, Deb Wyatt wrote:
>   assuming you're
>>   using version 3.5
>>
>
> How do you get version 3.5?  Python.org shows 3.41 as being the latest.

You download the source code and build from scratch.
Its not really recommended for normal use yet - its still
in development.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


From toll at naver.com  Wed Jul 30 01:13:37 2014
From: toll at naver.com (=?UTF-8?B?7J2066qF6rWQ?=)
Date: Wed, 30 Jul 2014 08:13:37 +0900 (KST)
Subject: [Tutor] =?utf-8?q?Comparing_two_different_text_file?=
In-Reply-To: <b538c938d5f91e47b498e0dd924e8@cweb22.nm.nhnsystem.com>
References: <b538c938d5f91e47b498e0dd924e8@cweb22.nm.nhnsystem.com>
Message-ID: <b4cf6b3b18288f874550b4d61a319bfd@cweb22.nm.nhnsystem.com>

Hello 
I'd like to make new list from 'first.txt' which is not overlapped 'second.txt'.
I tried several times but I couldn't find right answer.
output was '[]'
 
First, Import two different text file and read as a list.
If  'first.txt' has same value as second.txt', don't append to new list.
'first.txt' has many same values.
'second.txt is like standard list.
 
Thanks.
 
 
 
#!/usr/bin/env python
list1 = []
list2 = []
list3 = []
list4 = []
#imports list from first text file
inf1 = open('first.txt')
for line in inf1.readlines(): 
    list1.append(line)
    list1 = line[:-1].split('\n')
#imports list from first text file
inf2 = open('second.txt')
for line in inf2.readlines():
    list2.append(line)
    list2 = line[:-1].split('\n')
#append items of list1
for a in list1:
    if a not in list1:
        list3.append(a)
#append items list1 don't have
for b in list3:    
    if b not in list2:
        list4.append(b)
ouf = open('new.txt', 'w')
ouf.writelines(list4)
 






 
  
  
 
 
  
  
 

  #first.txt

  
  #second.txt 

  
  SS18SSX1

  SS18SSX1

  SS18SSX2

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1EWSR1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1EWSR1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  PAX3FOXO1

  PAX3FOXO1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1WT1

  EWSR1WT1

  EWSR1WT1

  PAX7FOXO1

  PAX7FOXO1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1FLI1

  EWSR1ERG

  EWSR1ERG

  TMPRSS2ERG

  TMPRSS2ERG

  TMPRSS2ERG

  TMPRSS2ERG

  
  EVCCRMP1

  FAM162AFTH1

  KIF3AFTL

  ENC1GNAS

  SOD1CXCL9

  TCF3ZNF384

  HMGB2PTMA

  STXBP5FAM126A

  NEMFPARM1

  PICK1SPINT2

  CD74NPIPB7

  SS18SSX2

  PYGBACAA1

  INS-IGF2GSK3B

  CSH2Unknown

  DEGS1DMPK

  PDLIM7PRRX1

  DIDO1LOC100507351

  GOLIM4PMPCB

  IGFBP7C12orf23

  AZGP1P1DDIT4

  EMILIN1RPL3

  UnknownARPC5L

  DPF2SART1

  MPHOSPH10AES

  PMPCARILPL1

  UBA1LASP1

  XPNPEP1CHI3L1

  ELNTXNDC5

  SEC31ALRCH4

  HIST1H3FHNRNPM

  ANKLE2HLA-B

  AGXT2L2GPI

  AK293147TNNT3

  CITED4BIN2

  PSIP1MYL6

  BCAMPES1

  NUP98PRRX2

  ALPPPTPRU

  NUP188POLR2A

  ETV5LOC284889

  PAX3FOXO1

  DDX42MT1F

  C7orf50FLNA

  ETV6RUNX1

  PIK3R2BC040735

  RPL28GLB1

  CTTNMYC

  ZHX2DDX52

  NEAT1CSF3R

  PLXNB2CSNK1E

  ATP5A1NEFL

  KIF3BSMC2

  RMI2SPATA20

  CSH1RRBP1

  EIF2AK1DBNL

  EIF3BPOLA2

  RPL21ELF3

  MED24MED24

  CELSR1MOB3A

  C14orf2SLTM

  CAPN13FKBP11

  TAF15NR4A3

  ADD1bK250D10.C22.8

  BTF3GGA1

  LAMP1PSD

  ADCY5GLIS1

  RPL14ZNF167

  SYPCPB1

  ZIM2PRR14

  SCARB2CYP19A1

  CDKL5DGCR8

  DRG1C1orf144

  EEF1E1DSC2

  RPS6KB1PCNXL2

  USF1MLLT6

  NDRG1ATP2A2

  H19TCEA3

  AP2A1NECAB3

  BCRABL1

  IL6LOC541472

  RAD9APPP1CA

  FUSATF1

  GSDMBMIR3134

  CDH11USP6

  FBXO34SSRP1

  MLLGMPS

  EIF3CLMED24

  PSMD8HDLBP

  COL3A1CLU

  MLLGMPS

  CNBPUSP6

  PPP6R2INTS3

  ITGB1BP1CPSF3

  DHCR24Unknown

  MDC1Unknown

  ANXA2SPRR2A

  VPS13DPITPNB

  ABCC10PGBD5

  POU6F1QSOX1

  ZNF79EVL

  TMX2PICALM

  IGFBP3SLC2A3

  MPHOSPH10AES

  UPF3BUnknown

  B2MPCBP1

  RBBP6CEP350

  CRYL1ATPAF1

  EPHA5MALAT1

  AESMPHOSPH10

  MYADMSPIDR

  AK128525MALAT1

  MLLGAS7

  CD3EORAI2

  PNPLA7APOE

  TGFBITGFBI

  FUSMARS

  TUBB4BITPRIP

  DAZAP2BOLA2

  MPHOSPH10AES

  TTC21BFKBP8

  LTBRWDTC1

  STXBP5FAM126A

  JUPECHS1

  MYH9RAPGEF1

  BRPF3N4BP2L2

  EZRINSR
  
  

  


 
 
 
 
 







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140730/a528a781/attachment.html>

From marc.tompkins at gmail.com  Wed Jul 30 02:19:00 2014
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Tue, 29 Jul 2014 17:19:00 -0700
Subject: [Tutor] Comparing two different text file
In-Reply-To: <b4cf6b3b18288f874550b4d61a319bfd@cweb22.nm.nhnsystem.com>
References: <b538c938d5f91e47b498e0dd924e8@cweb22.nm.nhnsystem.com>
 <b4cf6b3b18288f874550b4d61a319bfd@cweb22.nm.nhnsystem.com>
Message-ID: <CAKK8jXYaJWmy67ZXmDGrosJ0bFd-qwzGtf2JU8Jy_EdT9K=J9A@mail.gmail.com>

On Tue, Jul 29, 2014 at 4:13 PM, ??? <toll at naver.com> wrote:

> inf1 = open('first.txt')
> for line in inf1.readlines():
>     list1.append(line)
So far, so good...

>     list1 = line[:-1].split('\n')
...but then you do this, which wipes out list1.


> for a in list1:
>     if a not in list1:

Even if you hadn't already wiped out list1, this would be a problem.
These two lines essentially say "if a is both in AND not in list1..."

There might be other issues, but fixing those will get you started.

Also:  don't be afraid to add print() all over the place so you can
see what's happening!

From steve at pearwood.info  Wed Jul 30 02:34:03 2014
From: steve at pearwood.info (Steven D'Aprano)
Date: Wed, 30 Jul 2014 10:34:03 +1000
Subject: [Tutor] Comparing two different text file
In-Reply-To: <b4cf6b3b18288f874550b4d61a319bfd@cweb22.nm.nhnsystem.com>
References: <b538c938d5f91e47b498e0dd924e8@cweb22.nm.nhnsystem.com>
 <b4cf6b3b18288f874550b4d61a319bfd@cweb22.nm.nhnsystem.com>
Message-ID: <20140730003403.GN9112@ando>

On Wed, Jul 30, 2014 at 08:13:37AM +0900, ??? wrote:

> #!/usr/bin/env python
> list1 = []
> list2 = []
> list3 = []
> list4 = []
> #imports list from first text file
> inf1 = open('first.txt')
> for line in inf1.readlines(): 
>     list1.append(line)
>     list1 = line[:-1].split('\n')

Try this:

infile = open('first.txt')
list1 = infile.readlines()
infile.close()

The readlines() method already returns a list of all the lines in the 
file, so there's no need to iterate over the lines a second time just to 
put them into a list.

Now do the same for 'second.txt' to get the lines from it. No need to 
have separate "infile1" and "infile2" variables, you can re-use the 
variable. (But don't forget to close the files after you've read them.)

So now you have two lists, list1 and list2, containing the lines from 
the two files.

> #append items of list1
> for a in list1:
>     if a not in list1:
>         list3.append(a)

That cannot possibly do anything. You are testing each line of list1, to 
see if it *isn't* from list1. Of course it will be from list1.

I *think* that what you want is to make a copy of list1 and put it in 
list3:

list3 = []
for line in list1:
    list3.append(line)

But wait! There's an easier way: list slicing.

https://docs.python.org/2/tutorial/introduction.html#lists

So you ought to be able to make a copy of list1 in a single line.

Then you can walk over each line of list2, check whether or not that 
line is in list1 (NOT list2!!!), and append to list3:

for line in list2:
    if line not in list1:
        list3.append(line)


P.S. no need to show us dozens and dozens of lines of data. Just show us 
a few examples, say three or five, not fifty or a hundred.



-- 
Steven

From ugajin at talktalk.net  Thu Jul 31 10:51:45 2014
From: ugajin at talktalk.net (ugajin at talktalk.net)
Date: Thu, 31 Jul 2014 04:51:45 -0400
Subject: [Tutor] accessing code for built in min()
Message-ID: <8D17AB3C6E3B399-CF0-14024@webmail-vfrr09.sis.aol.com>

How do I look at the code for a python built in function e.g. min()?

Thanks

I am running 2.7.8 on OSX

From raulcumplido at gmail.com  Thu Jul 31 11:15:52 2014
From: raulcumplido at gmail.com (=?UTF-8?Q?Ra=C3=BAl_Cumplido?=)
Date: Thu, 31 Jul 2014 10:15:52 +0100
Subject: [Tutor] accessing code for built in min()
In-Reply-To: <8D17AB3C6E3B399-CF0-14024@webmail-vfrr09.sis.aol.com>
References: <8D17AB3C6E3B399-CF0-14024@webmail-vfrr09.sis.aol.com>
Message-ID: <CAD1Rbrr=+BM2wDNB3vxzbWPpZ9PTf==XO2RBZ+q9Y0uHJ640Mw@mail.gmail.com>

Are you asking for the source code? For the CPython implementation, PyPy,
IronPython, Jhyton?

For the CPython implementation you can go to the repository:
http://hg.python.org/cpython/branches


Builtin implementations in C (for 2.7 version) are in the file:
http://hg.python.org/cpython/file/818989a48e96/Python/bltinmodule.c

If you want to take a look on the min builtin:
http://hg.python.org/cpython/file/818989a48e96/Python/bltinmodule.c#l1435

Thanks,
Ra?l


On Thu, Jul 31, 2014 at 9:51 AM, <ugajin at talktalk.net> wrote:

> How do I look at the code for a python built in function e.g. min()?
>
> Thanks
>
> I am running 2.7.8 on OSX
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140731/cff56326/attachment.html>

From ugajin at talktalk.net  Thu Jul 31 12:39:20 2014
From: ugajin at talktalk.net (ugajin at talktalk.net)
Date: Thu, 31 Jul 2014 06:39:20 -0400
Subject: [Tutor] accessing code for built in min()
In-Reply-To: <CAD1Rbrr=+BM2wDNB3vxzbWPpZ9PTf==XO2RBZ+q9Y0uHJ640Mw@mail.gmail.com>
Message-ID: <8D17AC2CDDC1D49-CF0-14199@webmail-vfrr09.sis.aol.com>

Thanks Ra?l,

T'was the latter two. 

-u

 

 

 

-----Original Message-----
From: Ra?l Cumplido <raulcumplido at gmail.com>
To: ugajin at talktalk.net
CC: tutor <Tutor at python.org>
Sent: Thu, 31 Jul 2014 10:36
Subject: Re: [Tutor] accessing code for built in min()


Are you asking for the source code? For the CPython implementation, PyPy, IronPython, Jhyton?


For the CPython implementation you can go to the repository:
http://hg.python.org/cpython/branches




Builtin implementations in C (for 2.7 version) are in the file:

http://hg.python.org/cpython/file/818989a48e96/Python/bltinmodule.c



If you want to take a look on the min builtin:
http://hg.python.org/cpython/file/818989a48e96/Python/bltinmodule.c#l1435



Thanks,
Ra?l




On Thu, Jul 31, 2014 at 9:51 AM,  <ugajin at talktalk.net> wrote:

How do I look at the code for a python built in function e.g. min()?

Thanks

I am running 2.7.8 on OSX
_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140731/7f1ca02a/attachment.html>

From illusiontechniques at gmail.com  Thu Jul 31 21:53:48 2014
From: illusiontechniques at gmail.com (C Smith)
Date: Thu, 31 Jul 2014 15:53:48 -0400
Subject: [Tutor] Using subprocess on a series of files with spaces
Message-ID: <CAL2Y8-TTGGRHsJ=O7opoWNjsDViabT+ivfDTDHBqBjyxUGYBmQ@mail.gmail.com>

I am on OSX, which needs to escape spaces in filenames with a backslash.
There are multiple files within one directory that all have the same
structure, one or more characters with zero or more spaces in the
filename, like this:
3 Song Title XYZ.flac.
I want to use Python to call ffmpeg to convert each file to an .mp3.
So far this is what I was trying to use:
import os, subprocess
track = 1
for filename in os.listdir('myDir'):
    subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
    track += 1


I am about to use re.sub to just replace all the '/s' with '\\/s', but
is there a simpler/more pythonic way to do this?

From emile at fenx.com  Thu Jul 31 22:04:57 2014
From: emile at fenx.com (Emile van Sebille)
Date: Thu, 31 Jul 2014 13:04:57 -0700
Subject: [Tutor] Using subprocess on a series of files with spaces
In-Reply-To: <CAL2Y8-TTGGRHsJ=O7opoWNjsDViabT+ivfDTDHBqBjyxUGYBmQ@mail.gmail.com>
References: <CAL2Y8-TTGGRHsJ=O7opoWNjsDViabT+ivfDTDHBqBjyxUGYBmQ@mail.gmail.com>
Message-ID: <lre7hb$nbi$1@ger.gmane.org>

On 7/31/2014 12:53 PM, C Smith wrote:
> I am on OSX, which needs to escape spaces in filenames with a backslash.
> There are multiple files within one directory that all have the same
> structure, one or more characters with zero or more spaces in the
> filename, like this:
> 3 Song Title XYZ.flac.
> I want to use Python to call ffmpeg to convert each file to an .mp3.
> So far this is what I was trying to use:
> import os, subprocess
> track = 1
> for filename in os.listdir('myDir'):
>      subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
>      track += 1

You might try using '"%s"' % filename so that the name is within quotes 
for the shell environment.

Emile



From illusiontechniques at gmail.com  Thu Jul 31 23:53:26 2014
From: illusiontechniques at gmail.com (C Smith)
Date: Thu, 31 Jul 2014 17:53:26 -0400
Subject: [Tutor] Using subprocess on a series of files with spaces
In-Reply-To: <53DAA8BF.9020603@salesinq.com>
References: <CAL2Y8-TTGGRHsJ=O7opoWNjsDViabT+ivfDTDHBqBjyxUGYBmQ@mail.gmail.com>
 <lre7hb$nbi$1@ger.gmane.org>
 <CAL2Y8-QdRS=qWabwJ_WDh7HLo17zBasuRVBXiy4YAy2Vq-f39g@mail.gmail.com>
 <53DAA8BF.9020603@salesinq.com>
Message-ID: <CAL2Y8-R3Vo+X+028svxkuuBfXVZeFUQmJ9DGoTom_s_HnZBcpg@mail.gmail.com>

>Change:


>subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])

>to:

>subprocess.call(['ffmpeg', '-i', '"%s"' % filename, str(track)+'.mp3'])

I still get the same errors, the filenames are passed to the shell
without escaping the spaces.

>Why not using ffmpeg without jumping into Python. It's well documented, check Google.

I guess you mean that the ability to change multiple files with ffmpeg
is possible. I hadn't considered that but I would rather do it with
Python, just for the practice.

On Thu, Jul 31, 2014 at 4:36 PM, Emile <emile at salesinq.com> wrote:
> On 7/31/2014 1:19 PM, C Smith wrote:
>>
>> I get
>> TypeError: unsupported operand type(s) for %: 'int' and 'str
>> I am not understanding the use of the list inside the subprocess.call().
>> I tried all of the following
>> subprocess.call(['ffmpeg', '-i', '%s', str(track)+'.mp3']) % filename
>> --gives type error stated above
>> subprocess.call(['ffmpeg', '-i', '%s', str(track)+'.mp3'] % filename)
>> --same
>> subprocess.call(['ffmpeg', '-i', '%s', str(track)+'.mp3' % filename])
>> -- TypeError: not all arguments converted during string formatting
>> and tried all three with the triple quotes, just to be sure.
>>
>> On Thu, Jul 31, 2014 at 4:04 PM, Emile van Sebille <emile at fenx.com> wrote:
>>>
>>> You might try using '"%s"' % filename so that the name is within quotes
>>> for the shell environment.
>
>
> Change:
>
>
> subprocess.call(['ffmpeg', '-i', filename, str(track)+'.mp3'])
>
> to:
>
> subprocess.call(['ffmpeg', '-i', '"%s"' % filename, str(track)+'.mp3'])
>
> Emile
>
>
>

From BMCKINLEY at mawss.com  Thu Jul 31 17:13:23 2014
From: BMCKINLEY at mawss.com (McKinley, Brett D.)
Date: Thu, 31 Jul 2014 15:13:23 +0000
Subject: [Tutor] Need help with python script
Message-ID: <943FD0A7C6E2C346A4658BE83E1B1BFF49787C2E@MAWSSEXCH3.mawss.com>

I would like to see if someone can help me with a python script.  I'm trying to export a file geodatabase feature class to csv file.  This is what I have so far:

import arcpy
import os
import csv
import domainvalues


def export_to_csv(dataset, output, dialect):
    """Output the data to a CSV file"""
    # create the output writer
    out_writer = csv.writer(open(output, 'wb'), dialect=dialect)
    # return the list of field names and field values
    header, rows = domainvalues.header_and_iterator(dataset)

    # write the field names and values to the csv file
    out_writer.writerow(map(domainvalues._encodeHeader, header))
    for row in rows:
        out_writer.writerow(map(domainvalues._encode, row))

if __name__ == "__main__":
    # Get parameters
    dataset_name = arcpy.GetParameterAsText(0)
    output_file = arcpy.GetParameterAsText(1)
    delim = arcpy.GetParameterAsText(2).lower()
    dialect = 'excel'
    if delim == 'comma':
        pass
    else:
        dialect = 'excel-tab'
    try:
        export_to_csv(dataset_name, output_file, dialect)
    except Exception as err:
        arcpy.AddError('Error: {0}'.format(err))


I would like for the script to export only certain fields and also export only the newest records.  As for now, it's exporting everything.

Thanks
Brett McKinley


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140731/97156129/attachment.html>