Re: [Tutor] Lists

2011-06-10 Thread eizetov
Vincent, you should also try to avoid naming your lists a 'list'. There's a  
couple dozen words in Python that are reserved 'for system use':



import keyword
print(keyword.kwlist)

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 
'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 
'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 
'return', 'try', 'while', 'with', 'yield']

'List' is actually not listed here, however, using it as a variable name is  
still bad:



list('spam')

['s', 'p', 'a', 'm']

list = '42'
list('spam')

Traceback (most recent call last):
File "", line 1, in 
list('spam')
TypeError: 'str' object is not callable

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


Re: [Tutor] Lists

2011-06-10 Thread Steven D'Aprano

Piotr Kamiński wrote:


Could you please refrain from presenting your *religious* convictions in
this list: the notions you believe in as well as the ones that you believe
are false?

This is a *technical* list, as I understand it, solely dedicated to the
technical side of teaching the *Python* programming language and
*programming* in general. I would like to keep it this way ...


followed by FIFTY TWO lines of pseudo-philosophical waffling about his 
own religious beliefs.


That's really funny. You made me laugh :)

Piotr, I'm sorry that your religious faith is so fragile that it can't 
bear to be exposed to even the *existence* of contrary opinions, but 
that's not my problem.




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


Re: [Tutor] Lists

2011-06-10 Thread Piotr Kamiński

Dnia 10-06-2011 o 22:00:46 Corey Richardson  napisał(a):


On 06/10/2011 03:12 PM, Piotr Kamiński wrote:

Could you please refrain from presenting your *religious* convictions
in this list: the notions you believe in as well as the ones that you
believe are false?

This is a *technical* list, as I understand it, solely dedicated to
the technical side of teaching the *Python* programming language and
*programming* in general. I would like to keep it this way and I
believe there are many persons or at least a number of people
constituting a minority (or, likely, a silent majority) sharing my
views in this respect.

What is more, I am profoundly convinced that there are many other
mailing lists and/or sites on the Internet, specifically dedicated to
debating various religious, worldview and philosophical issues.



You should have stopped here. Or, even better, just not written at all.
It's the internet, does someone else's world religious really matter so
much that you write a lengthy response to the whole list (which should
be focused on python, as you mentioned)?


I know it's the Internet and I also use my right to express my opinions  
about somebody's short (or lengthy) views that I think of as *unfounded  
and offensive*. You obviously cannot imagine - living in a  
non-totalitarian, non-(post)communist country - that someone else's "world  
religious" really matters so much that one writes a lengthy response (is  
the property of being lengthy, a crime or too much of a burden on  
someone's (uninterested in religious, social and political philosophy and  
practice?) mind?).


Please note that very short, catchy, one-sentence-long or so phrases  
*unsupported with* any thorough, *factual arguments* are commonly used to  
create groundless *impressions* in their receivers/consumers and,  
effectively, manipulate people into thinking and behaving in a way that a  
given person or a group of people want.


For your information, such a piece of information creating some false  
impressions instead of giving true, supported with solid arguments  
information is technically known as a *factoid* (  
http://en.wikipedia.org/wiki/Factoid ): "...The word is defined by the  
Compact Oxford English Dictionary as "an item of **unreliable  
information** that is **repeated so often** that it becomes **accepted as  
fact**". - the double stars were added by me. So you can see that a "good"  
factoid is almost never "lengthy" so that *most* people listening/watching  
to it get the point conveyed and do not get bored too quickly "or  
something"...


I am aware of the above facts, so I am loudly protesting against Steven's  
verbal and conceptual behaviour. You don't have to agree with me. I  
realise that I use "big" words but that's something to get used to, if you  
want to talk precisely about the discussed matters.


If you are a teenager or an adult uninterested in talking/reading about  
religion or politics, you can of course skip the thread or my posts. There  
is no obligation to read them and my intent was not to *unconditionally*  
close, or to demand doing so, Steven's or somebody else's mouth and not to  
talk about Christianity at all.


I have said what I have had to say on this topic; I will not comment on  
the the thread any more.


Good luck with learning and teaching Python and the basics of programming,  
everybody.





---

[...]

That is my outlook on religious and ideological matters. I have
wanted it to be known, so I have mentioned it *once* (Steven provoked
my response). I do not intend to remind you repeatedly how I despise
the genocidal totalitarian Left (e.g. that starved to death *5 - 6
million people* in Ukraine in 1932 - 1933 (
http://en.wikipedia.org/wiki/Holodomor )) or pseudo liberal leftist
denominations. If I ever feel a need for that, I can easily find a
dedicated Internet forum and express my views in this thematic scope.
I am quite sure nobody needs my repeated ideological propaganda *in
this mailing list*; let me know if I am wrong...



A wise man once said,


"A wise man" also once said "repeatedly". That strictly means more than  
once, and also exactly speaking: in different threads and on different  
dates...





Could you please refrain from presenting your *religious* convictions
in this list: the notions you believe in as well as the ones that you
believe are false?


Could be applied to government too.

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


Re: [Tutor] Printing RAW string

2011-06-10 Thread Jeremy G Clark
print(repr(s))

_

How i can print the string in raw...as it is

s="hello world\n"
print s

Output:
helloworld

But i want it to be "hello world\n"

I know it can be done by adding a 'r' prefix but is there any other way because 
the string will be taken in during input!

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


Re: [Tutor] Great List!!!mtu...@python.org

2011-06-10 Thread Kaustubh Pratap chand
Great place this is.i am also new and i have started to love this place as 
it can help me in learning python fast
- Original Message -
From: Larry Flynton
Sent: 06/10/11 04:44 PM
To: tutor@python.org
Subject: [Tutor] Great List!!!mtu...@python.org

 I just joined the list a little bit ago, and I must say while learning python 
it has proved to be a resource second to none. I myself am not from a 
traditional computer science background, more or less financial/economics, & 
discrete mathematics. I have had courses on MySQL, Visual Basic, matlab,etc 
Plus, I do know more about computers than most people. But, I have began to 
program in python and learning the ropes, and playing around with IPython(which 
is def. great!!!). I was reading about creating functions/etc in one's 
library and I followed several examples in books(dive into python+python for 
Unix/Linux System Administration).

 But in general I wanted to do some data mining with resource retrieval from 
the internet. I found and have played with beautiful soup, scrapy, and urllib3. 
I want to be able to retrieve the data and then put it in a MySQL(pyworkbench 
is what I have), and I was curious of perspectives to look at functions, to 
help build a multi-faceted library to undertake this task. As well as a couple 
pointers on the ways one can import python to pyworkbench(I also have 
SQLAlchemy). I have found the mailing list to be great, and have enjoyed the 
reading. However, as the books were insightful, and without a doubt helpful 
found this to be beyond their realm, and this list appeared to be the best 
resource. Thanks in advance!!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Printing RAW string

2011-06-10 Thread Kaustubh Pratap chand
How i can print the string in raw...as it is

 s="hello world\n"
 print s

 Output:
 helloworld

 But i want it to be "hello world\n"

 I know it can be done by adding a 'r' prefix but is there any other way 
because the string will be taken in during input!

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


[Tutor] Great List!!!mtu...@python.org

2011-06-10 Thread Larry Flynton
I just joined the list a little bit ago, and I must say while learning python 
it has proved to be a resource second to none. I myself am not from a 
traditional computer science background, more or less financial/economics, & 
discrete mathematics.  I have had courses on MySQL, Visual Basic, 
matlab,etc Plus, I do know more about computers than most people. But, I 
have began to program in python and learning the ropes, and playing around with 
IPython(which is def. great!!!). I was reading about creating functions/etc 
in one's library and I followed several examples in books(dive into 
python+python for Unix/Linux System Administration). 

But in general I wanted to do some data mining with resource retrieval from the 
internet. I found and have played with beautiful soup, scrapy, and urllib3.  I 
want to be able to retrieve the data and then put it in a MySQL(pyworkbench is 
what I have), and I was curious of perspectives to look at functions, to help 
build a multi-faceted library to undertake this task.  As well as a couple 
pointers on the ways one can import python to pyworkbench(I also have 
SQLAlchemy).  I have found the mailing list to be great, and have enjoyed the 
reading. However, as the books were insightful, and without a doubt helpful 
found this to be beyond their realm, and this list appeared to be the best 
resource. Thanks in advance!!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] if statement

2011-06-10 Thread Jeremy G Clark
Sorry, jumping in on this thread a couple days late...

Steven's suggestion is how I figured out a similar problem recently.  If you're 
executing the code through a windows command line, you might be getting the 
carriage-return character returned to the program (this behavior doesn't happen 
in IDLE).  Remove it by using rstrip like so:

password = input("Enter your password: ").rstrip('\r')

Jeremy

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


Re: [Tutor] Lists

2011-06-10 Thread Corey Richardson
On 06/10/2011 03:12 PM, Piotr Kamiński wrote:
> Could you please refrain from presenting your *religious* convictions
> in this list: the notions you believe in as well as the ones that you
> believe are false?
> 
> This is a *technical* list, as I understand it, solely dedicated to
> the technical side of teaching the *Python* programming language and 
> *programming* in general. I would like to keep it this way and I
> believe there are many persons or at least a number of people
> constituting a minority (or, likely, a silent majority) sharing my
> views in this respect.
> 
> What is more, I am profoundly convinced that there are many other
> mailing lists and/or sites on the Internet, specifically dedicated to
> debating various religious, worldview and philosophical issues.
> 

You should have stopped here. Or, even better, just not written at all.
It's the internet, does someone else's world religious really matter so
much that you write a lengthy response to the whole list (which should
be focused on python, as you mentioned)?

> ---
> 
> [...]
> 
> That is my outlook on religious and ideological matters. I have
> wanted it to be known, so I have mentioned it *once* (Steven provoked
> my response). I do not intend to remind you repeatedly how I despise
> the genocidal totalitarian Left (e.g. that starved to death *5 - 6
> million people* in Ukraine in 1932 - 1933 (
> http://en.wikipedia.org/wiki/Holodomor )) or pseudo liberal leftist
> denominations. If I ever feel a need for that, I can easily find a
> dedicated Internet forum and express my views in this thematic scope.
> I am quite sure nobody needs my repeated ideological propaganda *in
> this mailing list*; let me know if I am wrong...
> 

A wise man once said,

> Could you please refrain from presenting your *religious* convictions
> in this list: the notions you believe in as well as the ones that you
> believe are false?

Could be applied to government too.
-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

2011-06-10 Thread James Reynolds
Honestly no idea.

At work I use 2.6 / 2.7. At home it's 3.2 / 2.7.

I've never actually tried doing this at home, so I don't know.

They have a mail list though, I would post there to find out.

2011/6/10 Válas Péter 

>
>
> 2011. június 10. 15:51 James Reynolds írta, :
>
>
>> Regarding Excel, you can write your output directly to an Excel file from
>> python using the Python-Excel module. Just install all three packages. I use
>> them all the time.
>>
>>
>> Do they work with Py3K?
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Lists

2011-06-10 Thread Piotr Kamiński

Dnia 10-06-2011 o 12:25:34 Steven D'Aprano 
napisał(a):


Vincent Balmori wrote:
I'm stuck on two problems from the Absolute Beginners book. The first  
is simple. I am trying to print all the words in the list in random  
order without repeats, but it always shows None for some reason.

 #Program prints list of words in random order with no repeats
 import random
 #List of words
 list = ["first", "second", "third", "fourth","fifth"]
 #Randomize word order
 order = random.shuffle(list)


...



sondad = {
 "Vincent": "Ramon",
 "Ramon": "Lolo",
 "Hermes": "Zeus",
 "Apollo": "Zeus",
 "Zeus": "Cronus",
 "Cronus": "Uranus",
 "Jesus": "God the Demiurge, the false God",
 "God the Demiurge, the false God":
 "God the Monad, the One, The Absolute, Bythos, Aion teleos",

...


Could you please refrain from presenting your *religious* convictions in
this list: the notions you believe in as well as the ones that you believe
are false?

This is a *technical* list, as I understand it, solely dedicated to the
technical side of teaching the *Python* programming language and
*programming* in general. I would like to keep it this way and I believe
there are many persons or at least a number of people constituting a
minority (or, likely, a silent majority) sharing my views in this respect.

What is more, I am profoundly convinced that there are many other mailing
lists and/or sites on the Internet, specifically dedicated to debating
various religious, worldview and philosophical issues.


---

As an aside, I have noticed that you tend to simply criticise Christianity
as being unscientific and "false" and you do not bother to mention the
religion or the philosophical or scientific belief system that you believe
in.

That seems to be quite a simplistic, unsophisticated form of ideological
*intolerance* characteristic at best of a religious/philosophical zealot.

As I have said I do not know the name of your belief system, however
before you start to bash a belief system (and criticise it without giving
any reason and without *constructively* suggesting your alternative),
please first take due care to become familiar with e.g. Karl Popper's
(http://en.wikipedia.org/wiki/Karl_Popper) views on: Marxism, Darwinism
and Christianity.

Notice that he gives reasons (the theory of *falsifiability*) why he
thinks Marxist historical materialism and its idea of the progress of
humanity is *unscientific*. That does not put the ideas of
*"progressiveness"* of the New Left in a good light, does it? Especially
when compared with Popper's views on Christianity. That must seem scary
and blasphemous for leftists to distinguish the similarities between
(Neo)marxism and Christianity... Thus that is why some philosophers see
the varied (neo)marxist movements as denominations of the
*non-traditional* Marxist *religion*, in a way similar to the diverse
denominations of Christianity.

The similarity between the two religions ends at this point, since their
goals differ completely. A lot more can be said about them. I will not
elaborate on the subject, as I realise that I am as likely to convince a
leftist of Christianity's truthfulness (and vice versa, i.e. a Christian
of leftism's truthfulness), as one is likely to convince a Muslim of
Christianity's truthfulness (and vice versa, i.e. a Christian of Islam's
truthfulness).

Lastly, I believe that a young person looking for non-simplistic
intellectual answers has to *consciously* discover them evaluating on
his/her own the Christian, Marxist, etc. religions and/or ideologies.

As to my person, I am a Christian and I also highly value, the few that
exist, patriotic, politically independence-oriented representatives of
anticommunist, antitotalitarian (i.e. the people that are against both the  
German

*national* __socialism__ and the Soviet *international* __socialism__)
Left who are not "useful idiots", easily indoctrinated by the Neosoviets
and other totalitarian Left.

That is my outlook on religious and ideological matters. I have wanted it
to be known, so I have mentioned it *once* (Steven provoked my response).
I do not intend to remind you repeatedly how I despise the genocidal
totalitarian Left (e.g. that starved to death *5 - 6 million people* in  
Ukraine in 1932 - 1933 ( http://en.wikipedia.org/wiki/Holodomor )) or  
pseudo liberal leftist denominations. If I ever feel a need for that, I  
can easily find a dedicated Internet forum and express

my views in this thematic scope. I am quite sure nobody needs my repeated
ideological propaganda *in this mailing list*; let me know if I am wrong...

One last thought, Steven, you might also find useful the section (of the
Wikipedia article on Karl Popper) on the paradox of tolerance and on the
subject of unlimited tolerance, as it seems particularly relevant to you
in the light of your visible ideological intolerance.


Piotr
___
Tutor maillist  -  Tutor@python.org
T

Re: [Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

2011-06-10 Thread Válas Péter
2011. június 10. 15:51 James Reynolds írta, :

>
> Regarding Excel, you can write your output directly to an Excel file from
> python using the Python-Excel module. Just install all three packages. I use
> them all the time.
>
>
> Do they work with Py3K?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Excited about python

2011-06-10 Thread python
> For a handy reference, you can't beat "Python Essential  Reference" by David 
Beazley (along with the online documentation, of course!).  I think this
book 
is obligatory if you are going to be working with Python a lot.  I own
all 
four editions :)

> But you wanted something more in depth with algorithms, etc.  The O'Reilly 
book "Programming Python" by Mark Lutz is a classic and is probably a
good bet 
for you.  Core Python by Wesley Chun is also good, and I've seen him on
this 
list from time to time.

+1 on all of Chris's recommendations with a special +1 for Mark Lutz's
book.

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


Re: [Tutor] Excited about python

2011-06-10 Thread Chris Fuller

For a handy reference, you can't beat "Python Essential  Reference" by David 
Beazley (along with the online documentation, of course!).  I think this book 
is obligatory if you are going to be working with Python a lot.  I own all 
four editions :)

But you wanted something more in depth with algorithms, etc.  The O'Reilly 
book "Programming Python" by Mark Lutz is a classic and is probably a good bet 
for you.  Core Python by Wesley Chun is also good, and I've seen him on this 
list from time to time.

Also, check out the Python wiki:
http://wiki.python.org/moin/PythonBooks

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


Re: [Tutor] telnet connection question

2011-06-10 Thread Alan Gauld


"Rayon"  wrote


Is there any way that I can use python telnetlib to connect to a 
telnet

session.
Send commands and get back data without closing the connection.


Yes, thats what it's for.

I need the response to be faster and the login process is taking up 
too much

time.


Faster than what?
Is it fast if you do it manually?
The library can only talk to the same telnet server at
the far end that your local telnet client talks to. If its
a slow link or server then login (and most other things!)
will be slow. What makes you think its the library at fault?

If you are seeing big differences between manual
and auto login then there might be an issue.
In that case send us the timings for each method
and the code you are using to login. (with login
details obscured if necessary!)


I was thinking I could use a queue to pass in data
but I am not sure how i would get it out.


Of course you can use a queue to pass in data,
but that has nothing to do with telnet. As to getting it out.
Out of what? The queue or the telnet session?

We need more detail to be able to give specific answers.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


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


Re: [Tutor] Excited about python

2011-06-10 Thread Nikunj Badjatya
"a byte of python " from Swaroop CH.






On Fri, Jun 10, 2011 at 8:08 PM, Kaustubh Pratap chand <
warr...@programmer.net> wrote:

>
> Thanks I liked the tutorial very much.
>
>
>
>  - Original Message -
>
> From: Patty
>
> Sent: 06/10/11 10:21 AM
>
> To: Kaustubh Pratap chand, tutor@python.org
>
> Subject: Re: [Tutor] Excited about python
>
>
>
>  - Original Message -
>  *From:* Kaustubh Pratap chand 
>  *To:* tutor@python.org
>  *Sent:* Friday, June 10, 2011 5:41 AM
>  *Subject:* [Tutor] Excited about python
>
> Hello,
> I just joined this mailing list so that i can boost up my learning of
> python.I come from a C background so python looks a little strange to me but
> it is easier to learn then any other languages around.Yet,i have not been
> able to find any cool books on python for peoples who are already
> programmers.The ones which i found which i found were quite boring and
> exhaustive.
>
> Can you recommend a book for a person like me which comes with a C
> background and the book covers all essential algoithmic methods and
> examples?
>
> Thank you.
>
>
> --
>
>
>  ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>  Hello Kaustubh:
>
>  I am also a C programmer and the first thing I read about Python was "A
> Quick, Painless Tutorial on the Python Language" by Prof. Norman Matloff of
> UC-Davis.
>  Here is the link to his page -- I didn't realize he had created other
> tutorials regarding Python, and will have to look at those myself.
>
>  http://heather.cs.ucdavis.edu/~matloff/python.html
>
>  Here is the specific link to the tutorial I mentioned:
> http://heather.cs.ucdavis.edu/~matloff/Python/PythonIntro.pdf
>
>  In addition, I wasn't satisfied after learning on my own and took an
> online course.
>
>  I also like Beginning Python - From Novice to Professional by Magnus
> Hetland.  I have other books as well, such as Python Programming for the
> Absolute Beginner by Michael Dawson, but I like Hetland's style more and
> have a book being shipped to me by Hetland called Python Algorithms.
>
>  Good Luck
>
>  Patty
>
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing an XML document using ElementTree

2011-06-10 Thread Sithembewena Lloyd Dube
Hi Stefan,

Thanks for the code review :) Only just noticed this.

On Wed, May 25, 2011 at 3:10 PM, Stefan Behnel  wrote:

> Sithembewena Lloyd Dube, 25.05.2011 14:40:
>
>  Thanks for all your suggestions. I read up on gzip and urllib and also
>> learned in the process that I could use urllib2 as its the latest form of
>> that library.
>>
>> Herewith my solution: I don't know how elegant it is, but it works just
>> fine.
>>
>> def get_contests():
>>  url = '
>>
>> http://xml.matchbook.com/xmlfeed/feed?sport-id=&vendor=TEST&sport-name=&short-name=Po
>> '
>>  req = urllib2.Request(url)
>>  req.add_header('accept-encoding','gzip/deflate')
>>  opener = urllib2.build_opener()
>>  response = opener.open(req)
>>
>
> This is ok.
>
>
>
>   compressed_data = response.read()
>>  compressed_stream = StringIO.StringIO(compressed_data)
>>  gzipper = gzip.GzipFile(fileobj=compressed_stream)
>>  data = gzipper.read()
>>
>
> This should be simplifiable to
>
>   uncompressed_stream = gzip.GzipFile(fileobj=response)
>
>
>
>   current_path = os.path.realpath(MEDIA_ROOT + '/xml-files/d.xml')
>>  data_file = open(current_path, 'w')
>>  data_file.write(data)
>>  data_file.close()
>>  xml_data = ET.parse(open(current_path, 'r'))
>>
>
> And this subsequently becomes
>
>   xml_data = ET.parse(uncompressed_stream)
>
>
>
>   contest_list = []
>>  for contest_parent_node in xml_data.getiterator('contest'):
>>
>
> Take a look at ET.iterparse().
>
>
>
>contest = Contest()
>>   for contest_child_node in contest_parent_node:
>>if (contest_child_node.tag == "name" and
>> contest_child_node.text is not None and contest_child_node.text != ""):
>> contest.name = contest_child_node.text
>>if (contest_child_node.tag == "league" and
>> contest_child_node.text is not None and contest_child_node.text != ""):
>>contest.league = contest_child_node.text
>>if (contest_child_node.tag == "acro" and
>> contest_child_node.text is not None and contest_child_node.text != ""):
>>contest.acro = contest_child_node.text
>>if (contest_child_node.tag == "time" and
>> contest_child_node.text is not None and contest_child_node.text != ""):
>>contest.time = contest_child_node.text
>>if (contest_child_node.tag == "home" and
>> contest_child_node.text is not None and contest_child_node.text != ""):
>>contest.home = contest_child_node.text
>>if (contest_child_node.tag == "away" and
>> contest_child_node.text is not None and contest_child_node.text != ""):
>>contest.away = contest_child_node.text
>>
>
> This is screaming for a simplification, such as
>
>   for child in contest_parent_node:
>   if child.tag in ('name', 'league', ...): # etc.
>   if child.text:
>   setattr(context, child.tag, child.text)
>
>
>
> Stefan
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



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


Re: [Tutor] Excited about python

2011-06-10 Thread Kaustubh Pratap chand
Thanks I liked the tutorial very much.
- Original Message -
From: Patty
Sent: 06/10/11 10:21 AM
To: Kaustubh Pratap chand, tutor@python.org
Subject: Re: [Tutor] Excited about python

 - Original Message -
 *From:* warr...@programmer.net 
 *To:* tutor@python.org 
 *Sent:* Friday, June 10, 2011 5:41 AM
 *Subject:* [Tutor] Excited about python
Hello,
 I just joined this mailing list so that i can boost up my learning of python.I 
come from a C background so python looks a little strange to me but it is 
easier to learn then any other languages around.Yet,i have not been able to 
find any cool books on python for peoples who are already programmers.The ones 
which i found which i found were quite boring and exhaustive.

 Can you recommend a book for a person like me which comes with a C background 
and the book covers all essential algoithmic methods and examples?

 Thank you.
-

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

I am also a C programmer and the first thing I read about Python was "A Quick, 
Painless Tutorial on the Python Language" by Prof. Norman Matloff of UC-Davis.
Here is the link to his page -- I didn't realize he had created other tutorials 
regarding Python, and will have to look at those myself. 

http://heather.cs.ucdavis.edu/~matloff/python.html 

Here is the specific link to the tutorial I mentioned: 
http://heather.cs.ucdavis.edu/~matloff/Python/PythonIntro.pdf 

In addition, I wasn't satisfied after learning on my own and took an online 
course. 

I also like Beginning Python - From Novice to Professional by Magnus Hetland. I 
have other books as well, such as Python Programming for the Absolute Beginner 
by Michael Dawson, but I like Hetland's style more and have a book being 
shipped to me by Hetland called Python Algorithms. 

Good Luck

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


Re: [Tutor] Excited about python

2011-06-10 Thread Michiel Overtoom

On Jun 10, 2011, at 15:53, Ashwini Oruganti wrote:

> You can also try "Learning Python"

I also came from a C/C++ background, but I found the standard tutorial 
sufficient.

  http://docs.python.org/tutorial/

Greetings,

> On Fri, Jun 10, 2011 at 6:11 PM, Kaustubh Pratap chand 
>  wrote:
> Hello,
> I just joined this mailing list so that i can boost up my learning of 
> python.I come from a C background so python looks a little strange to me but 
> it is easier to learn then any other languages around.Yet,i have not been 
> able to find any cool books on python for peoples who are already 
> programmers.The ones which i found which i found were quite boring and 
> exhaustive.
> 
> Can you recommend a book for a person like me which comes with a C background 
> and the book covers all essential algoithmic methods and examples?
> 
> Thank you.

-- 
"Freedom: To ask nothing. To expect nothing. To depend on nothing." - Ayn Rand

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


Re: [Tutor] Excited about python

2011-06-10 Thread Patty

  - Original Message - 
  From: Kaustubh Pratap chand 
  To: tutor@python.org 
  Sent: Friday, June 10, 2011 5:41 AM
  Subject: [Tutor] Excited about python


  Hello,
  I just joined this mailing list so that i can boost up my learning of 
python.I come from a C background so python looks a little strange to me but it 
is easier to learn then any other languages around.Yet,i have not been able to 
find any cool books on python for peoples who are already programmers.The ones 
which i found which i found were quite boring and exhaustive.

  Can you recommend a book for a person like me which comes with a C background 
and the book covers all essential algoithmic methods and examples?

  Thank you.



--


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

  Hello Kaustubh:

  I am also a C programmer and the first thing I read about Python was "A  
Quick, Painless Tutorial on the Python Language" by Prof. Norman Matloff of 
UC-Davis.
  Here is the link to his page -- I didn't realize he had created other 
tutorials regarding Python, and will have to look at those myself.  

  http://heather.cs.ucdavis.edu/~matloff/python.html

  Here is the specific link to the tutorial I mentioned:  
http://heather.cs.ucdavis.edu/~matloff/Python/PythonIntro.pdf

  In addition, I wasn't satisfied after learning on my own and took an online 
course.  

  I also like Beginning Python - From Novice to Professional by Magnus Hetland. 
 I have other books as well, such as Python Programming for the Absolute 
Beginner by Michael Dawson, but I like Hetland's style more and have a book 
being shipped to me by Hetland called Python Algorithms.  

  Good Luck

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


Re: [Tutor] Excited about python

2011-06-10 Thread Ashwini Oruganti
You can also try "Learning
Python"





On Fri, Jun 10, 2011 at 6:11 PM, Kaustubh Pratap chand <
warr...@programmer.net> wrote:

> Hello,
> I just joined this mailing list so that i can boost up my learning of
> python.I come from a C background so python looks a little strange to me but
> it is easier to learn then any other languages around.Yet,i have not been
> able to find any cool books on python for peoples who are already
> programmers.The ones which i found which i found were quite boring and
> exhaustive.
>
> Can you recommend a book for a person like me which comes with a C
> background and the book covers all essential algoithmic methods and
> examples?
>
> Thank you.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

2011-06-10 Thread James Reynolds
>
> 3) Open the .txt file in Excel, remove the few lines I don't need (ie
> single quotes, etc)


Regarding Excel, you can write your output directly to an Excel file from
python using the Python-Excel module. Just install all three packages. I use
them all the time.

Here is something that I wrote just yesterday which writes data to sheets
one and three in an existing notebook.

from xlrd import open_workbook
> from xlutils.copy import copy
> from xlwt import easyxf


def insert_excel(self, exfile, insert_list):
> book = open_workbook(exfile, formatting_info = True)
> copy_book = copy(book)
> copy_sheet = copy_book.get_sheet(0)
> copy_sheet_two = copy_book.get_sheet(2)
> plain = easyxf('')
> allp = len(insert_list)
> for row, listx in enumerate(insert_list):
> listx = self.formater(listx)
> print row +1, ' of ', allp
> if len(listx) > 250:
> first_list = listx[0:250]
> second_list = listx[250:]
> for i, cell in enumerate(first_list):
> copy_sheet.write(row+2, i, cell, plain)
> for i, cell in enumerate(second_list):
> try:
> copy_sheet_two.write(row+2, i, cell, plain)
> except ValueError:
> break
> else:
> for i, cell in enumerate(listx):
> copy_sheet.write(row+2, i, cell, plain)
> copy_book.save(exfile)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Excited about python

2011-06-10 Thread jon vs. python
Dive into Python: http://diveintopython.org/ is what you're looking for.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Excited about python

2011-06-10 Thread Flynn, Stephen (L & P - IT)
Python manuals from http://www.python.org/doc/

 



From: tutor-bounces+steve.flynn=capita.co...@python.org
[mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of
Kaustubh Pratap chand
Sent: Friday, June 10, 2011 1:41 PM
To: tutor@python.org
Subject: [Tutor] Excited about python

 

Hello,
I just joined this mailing list so that i can boost up my learning of
python.I come from a C background so python looks a little strange to me
but it is easier to learn then any other languages around.Yet,i have not
been able to find any cool books on python for peoples who are already
programmers.The ones which i found which i found were quite boring and
exhaustive.

Can you recommend a book for a person like me which comes with a C
background and the book covers all essential algoithmic methods and
examples?

Thank you.

This email has been scanned for all viruses by the MessageLabs SkyScan
service.


This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Excited about python

2011-06-10 Thread Kaustubh Pratap chand
Hello,
 I just joined this mailing list so that i can boost up my learning of python.I 
come from a C background so python looks a little strange to me but it is 
easier to learn then any other languages around.Yet,i have not been able to 
find any cool books on python for peoples who are already programmers.The ones 
which i found which i found were quite boring and exhaustive.

 Can you recommend a book for a person like me which comes with a C background 
and the book covers all essential algoithmic methods and examples?

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


Re: [Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

2011-06-10 Thread Válas Péter
2011/6/10 B G 

>
> path = "...\\Leukemia_Project"
> i = 0
> for (files) in os.walk(path):
> print(files)
> print("\n")
> i += 1
>

Continuing my thoughts:
I ran your loop, and got several tuples, each representing a directory. All
the tuples have the same structure: 0th element is the name of the
directory, followed by a list of subdirs (possibly empty) and a list of
files (possibly empty). I find no reason to maipulate this by Excel. Try
instead:

def clean(f):
any processing, removing here

path = ".../Leukemia_Project"
dirlists = []
for (files) in os.walk(path):
print(files)
dirlists.append(clean(files))
print("\n")

Then go on with next step. You will enjoy your work more than with
printing-marking-copying-pasting-saving-opening-processing-saving-reopening...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] telnet connection question

2011-06-10 Thread Steven D'Aprano

Rayon wrote:
HI All, 


Is there any way that I can use python telnetlib to connect to a telnet
session. 


It would be a pretty rubbish telnet library if it didn't let you make 
telnet connections.


I don't understand why you are asking this question, since you have 
successfully made connections and are complaining that they are too slow.



Send commands and get back data without closing the connection. 


It would be a pretty rubbish telnet library if you couldn't send telnet 
commands. What makes you think it might not?




I need the response to be faster and the login process is taking up too much
time. 


Then get a faster link.

Seriously, this is a silly question. It's like saying "I need a longer 
piece of string". Okay, fine. How long would you like? Why is the piece 
you have too short? We can't answer those questions.


How are you logging in? How much time are you talking about? How fast is 
your link?




I was thinking I could use a queue to pass in data but I am not sure how i
would get it out. 


What data do you need to pass in, and why do you think a queue will help 
you?




--
Steven

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


Re: [Tutor] Lists

2011-06-10 Thread Steven D'Aprano

Vincent Balmori wrote:
I'm stuck on two problems from the Absolute Beginners book. The first is simple. 
I am trying to print all the words in the list in random order without repeats, 
but it always shows None for some reason.


#Program prints list of words in random order with no repeats

import random

#List of words

list = ["first", "second", "third", "fourth","fifth"]

#Randomize word order

order = random.shuffle(list)



shuffle() does not return a new list, it shuffles in place, and returns 
None. So order will always be assigned the value None.


What you want is to make a copy of your word list, and shuffle that.

words = ["first", "second", "third", "fourth","fifth"]
shuffled = words[:]  # make a copy using slice notation [:]
random.shuffle(shuffled)


The other question is: "Improve the program by adding a choice that lets the 
user enter a name and get back a grandfather. You should still only use one list 
of son-father pairs. Make sure to include several generations in list so a match 
can be found." The only thing I have done is adding choice 5 with its basic elif 
block and adding another name in each of the three sequences in the list, but I 
am completely stuck otherwise.


#User can enter name of male and name of his father will show
#Allow user to add, replace, and delete son-father pairs.
#Also have the user enter a name to get back a grandfather

#Setting values
sondad = {"Vincent": "Ramon": "Lolo","Jesus": "God": "Unknown", "Simba": 
"Mufasa": "Lion"}


That can't work, you will get a syntax error. Each pair of key:value 
must be separated by a comma, not a colon, and you can't have key:key:value.


Since you can't do son:father:grandfather, you need another strategy. 
Fortunately there is a simple one: father is the son of grandfather. So 
your dict becomes:


sondad = {
"Vincent": "Ramon",
"Ramon": "Lolo",
"Hermes": "Zeus",
"Apollo": "Zeus",
"Zeus": "Cronus",
"Cronus": "Uranus",
"Jesus": "God the Demiurge, the false God",
"God the Demiurge, the false God":
"God the Monad, the One, The Absolute, Bythos, Aion teleos",
"Simba": "Mufasa",
"Mufasa": "Lion",
"Bart Simpson": "Homer Simpson",
"Homer Simpson": "Abe Simpson",
}


Try that and see how you go.



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


[Tutor] Lists

2011-06-10 Thread Vincent Balmori
I'm stuck on two problems from the Absolute Beginners book. The first is 
simple. 
I am trying to print all the words in the list in random order without repeats, 
but it always shows None for some reason.

#Program prints list of words in random order with no repeats

import random

#List of words

list = ["first", "second", "third", "fourth","fifth"]

#Randomize word order

order = random.shuffle(list)

#Print words in random order
print(order)

input("\n\nPress the Enter to exit")


The other question is: "Improve the program by adding a choice that lets the 
user enter a name and get back a grandfather. You should still only use one 
list 
of son-father pairs. Make sure to include several generations in list so a 
match 
can be found." The only thing I have done is adding choice 5 with its basic 
elif 
block and adding another name in each of the three sequences in the list, but I 
am completely stuck otherwise.

#User can enter name of male and name of his father will show
#Allow user to add, replace, and delete son-father pairs.
#Also have the user enter a name to get back a grandfather

#Setting values
sondad = {"Vincent": "Ramon": "Lolo","Jesus": "God": "Unknown", "Simba": 
"Mufasa": "Lion"}

choice = None
while choice != "0":

print(
"""
Who's Your Daddy?!

0 - Quit
1 - Look Up Pair
2 - Add a Pair
3 - Replace a Pair
4 - Delete a Pair
5 - Look up a Grandfather

"""
)

choice = input("Choice: ")
print()

# exit
if choice == "0":
print("Good-bye.")

# look up pair
elif choice == "1":
choice = input("Which pair do you want to look up?: ")
if choice in sondad:
dad = sondad[choice]
print("\n", choice,"is son to:", dad)
else:
print("\nSorry, I don't know", choice)

# add a father
elif choice == "2":
choice = input("Who is the son you want to add?: ")
if choice not in sondad:
dad = input("\nWho's the father?: ")
sondad[choice] = dad
print("\n", dad, "has been added.")
else:
print("\nThat pair already exists!  Try replacing them.")

# replace a father
elif choice == "3":
choice = input("Which son do you want to replace a father?: ")
if choice in sondad:
dad = input("Who's the father?: ")
sondad[choice] = dad
print("\n", choice, "has been replaced.")
else:
print("\nThey don't exist! Try adding them.")
   
# delete a pair
elif choice == "4":
choice = input("Which pair do you want to delete?: ")
if choice in sondad:
del sondad[choice]
print("\nOkay, I deleted", choice)
else:
print("\nI can't do that!", choice, "don't exist.")

# look up grandfather:
elif choice == "5":
choice = input("Who's grandfather are you looking up?: ")
if choice in sondad:
dad = sondad[choice]
print("\n", choice,"is grandson to:", dad)
else:
print("\nSorry, I don't know", choice)
   
# some unknown choice
else:
print("\nSorry, but", choice, "isn't a valid choice.")
  
input("\n\nPress the enter key to exit.")___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

2011-06-10 Thread Válas Péter
A few hints to make it more efficient:

2011/6/10 B G 

> 1) Create a script that gives me a list of all the filenames in the folder:
> I managed to do the following:
> path = "...\\Leukemia_Project"
>
Use / in path instead of \\, it will work in all environments, not just
Windows.  One of the advantages of Python is that most of its code is
platform independent; it would be a pity to throw this benefit away, and you
don't know where and for what purpose will you use your scripts later.

i = 0
>
What do you use i for? Is it necessary?


> for (files) in os.walk(path):
> print(files)
> print("\n")
> i += 1
> 2) I manually copy and paste the resulting list from the IDLE interpreter
> into a .txt file
> 3) Open the .txt file in Excel, remove the few lines I don't need (ie
> single quotes, etc)
>
I would not do this unless it is much easier than programming it or I am
forced to do so with a machine gun. :-)
Instead of print and copy and paste and save, you should write the whole
stuff into a file. Processing it in Excel may be worth if you cannot exactly
specify the things you want to remove. If they are well specified, do it in
Python. As far as i understand, you have a great amount of data, and this is
what programming is for. :-)


> 4) Write another python script to print the result from step 3 in a new txt
> file, where each filename has its own row (pretty easy to do b/c all
> separated by the tab in the original txt file)
>
Once you preprocessed  the filelist, it can be aither another script or the
same. It depends on whether you always run them together, or some of them is
needed alone.

As Alan wrote, IDLE is no interpreter. Personally, I find more comfortable
to write my scripts in Notepad++ and run at command prompt, because IDLE
does not provide line numbers :-((, and I suspect that it makes a great load
for the computer (on my weak machine it often looses socket and won't start
any more).


2011/6/10 Alan Gauld 

> If the script take a filename as an input parameter you can likely do
>
> python myfile.py *.*
>
> from the OS command prompt.
>
Using Windows you may omit python, too. myfile.py is enough for a well
educated Windows. :-)

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