Re: [Tutor] learning python from scratch

2019-02-07 Thread Alan Gauld via Tutor
On 06/02/2019 21:22, Michael Munn wrote:
> dear fellow programmeers, this is michael. I have a question for Python.
> I'm a beginner Pythonist. I havee been learning the history and it's use
> for past years. My main focus this year is to learn it's code and begin
> coding.

Can you program in any other language?
If so the official tutorial on python.org is a
good starting point.

If you have never programmed before there are
several tutorials (including mine, see below).
There is a list of them on the Python web site,
here:

https://wiki.python.org/moin/BeginnersGuide/NonProgrammers


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] learning python from scratch

2019-02-06 Thread Michael Munn
dear fellow programmeers, this is michael. I have a question for Python.
I'm a beginner Pythonist. I havee been learning the history and it's use
for past years. My main focus this year is to learn it's code and begin
coding.
Where can I find resource for this?
All comment  are greatly appreciate it
Best regards
Michael Munn

Michael Munn
Member: Virginia Association of Blind students
 National Federation of the Blind of   Virginia   www.nfbv.org
Member: Maryland Association of Blind Students
National Federation of the Blind of  Maryland www.nfbmd.org
Students of: Hadley Institute of the Blind
www.hadley.edu
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning python scripts for practical linux activities.

2015-01-15 Thread Emile van Sebille

On 1/15/2015 6:07 AM, dw wrote:

Hello,
I'm new the the group and new to programming in Python.
I would like to find a source, book etc of Python learning projects.
Projects that are useful for standard Linux activities like bulk
renaming files, managing repository packages.
Maybe python scripts that incorporate "LAME" for modifying audio files.
Anything of that nature.
As I learn Python, I would like to create Python utilities.
I'm hoping there is some learning material that might lead me in that
direction.
Sincere thanks
d



Check out http://it-ebooks.info/book/172/

Emile


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


Re: [Tutor] Learning python scripts for practical linux activities.

2015-01-15 Thread Alan Gauld

On 15/01/15 14:07, dw wrote:


I would like to find a source, book etc of Python learning projects.
Projects that are useful for standard Linux activities like bulk
renaming files, managing repository packages.
Maybe python scripts that incorporate "LAME" for modifying audio files.
Anything of that nature.


That's kind of the point of my new book "Python Projects"
If you go to Amazon the free preview covers the first chapter
(intro to Python) plus a section of chapter 1 which includes
interacting with the OS.

Other topics included are reading different file formats, Database 
access(dbm,shelve,SQL) UI design(CLI, argparse,cmd and GUI with Tkinter) 
Web dev (with Flask) and testing/debugging.


Its targeted at those who have done a basic intro to python and
want to go further and start their own projects.

Have a look at the preview it might suit you.

Sorry for the shameless plug but it does look like a fit.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


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


[Tutor] Learning python scripts for practical linux activities.

2015-01-15 Thread dw
Hello,
I'm new the the group and new to programming in Python.
I would like to find a source, book etc of Python learning projects.
Projects that are useful for standard Linux activities like bulk
renaming files, managing repository packages.
Maybe python scripts that incorporate "LAME" for modifying audio files.
Anything of that nature.
As I learn Python, I would like to create Python utilities.
I'm hoping there is some learning material that might lead me in that
direction.
Sincere thanks
d
-- 
 bw...@fastmail.net

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


[Tutor] Learning Python with Programming Collective Intelligence

2013-07-10 Thread bluepresley
Hello,

I discovered this list while doing research about the book Programming
Collective Intelligence by Toby Segaran. In the archives, a few of the
members wanted to create a group to discuss the code and algorithms
further. Those threads were a few years old, and unfortunately I'm just now
discovering the book.

I'm learning Python (as quickly as possible) so I can better understand the
algorithms in this book.  If that group is still out there, the I'd like
some more information about it. If not, I'd like to start digging in with
some questions, but wanted to make sure this was the right list before I
started.

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


Re: [Tutor] Learning Python through automating web application testing.

2012-12-15 Thread wrw
On Dec 7, 2012, at 5:46 PM, marcusw4...@hotmail.co.uk  
wrote:

> Hello all,
> 
> I'm new to posting on mailing lists so hopefully I've picked the correct one 
> for my question(s).
> 
> A little about my programming experience first.
> 

[byte]

> Because of this fear I've never admitted I've got a ready made project just 
> waiting for me to tackle...
> 
> Until now!
> 
> I would like to learn to automate the testing of a http(s) web 
> site/applications but feel slightly overwhelmed by this task so would like to 
> ask for some initial guidance. 
> 

Wow (!) welcome the wonderful world of Python.  I have several comments - but 
let me start (with apologies) by encouraging you to think about another initial 
project.  Others may well disagree with me (and I'd welcome that), but from my 
point of view, your choice (although by starting small can probably be done 
with relatively little of YOUR python code to call libraries), does require a 
deeper understanding of several parallel (pun intended) aspects of programming 
for web, ssh, sockets, python, your OS, and your chosen python libraries than 
you may realize.

Just to mention one - simulation of pounding on the test site by several users 
will require multi-processing from a pool of parallel jobs.  The standard 
Python library has the tools to handle this, but it isn't an easy subject for 
someone new to programming to get your mental arms wrapped around.  I'm not 
familiar with the Chun book, so my worries may be completely misplaced (and if 
so, I apologize), but if you aren't really comfortable yet with OOP, and class 
definitions that start with '__init__(self…)' - this project isn't a good place 
to start.

You can get some feel for your level of achievement by looking at urllib, 
urllib2, and httplib in the python standard documentation  (and maybe looking 
at beautifulsoup (either BS3 or BS4).  Then, if you want to go ahead - the kind 
of questions you will be coming up with are probably better addressed on the 
more general python-l...@python.org discussion group.  (There are lots of folks 
here to read both, so you won't need to cross post.) 

> These are some of questions that I have.
> 
> How do I go about this? 
> 
> Where do I start?  
> 
> There's just so much out there to help with learning Python I'm experiencing 
> information overload!  
> 
> How do I stop myself from trying to run before I can walk?
> 

My suggestion would be to pick a project that yields something useful around 
your house or apartment (flat?) or a single-function utility that would be 
useful to you (maybe some sort of backup utility that is customized for the way 
you work).

> In a perfect world a step by step guide, in automating web tests, using 
> Python is what I'm after but failing that(!) which sites/forums/mailing lists 
> are of particular interest to someone who would like to learn Python 
> programming initially through automating web tests?  (By web tests, to begin 
> with, I mean automated regression testing of a site by multiple users)
> 

When you get to the point of actually starting to tackle this - there is one 
more question you need to answer before you start.  Are you trying to check for 
correct functionality at all branch points when users respond appropriately, or 
are you wanting to check for possible ways the site can be crashed by users 
typing garbage or attempting to attack the site?  The latter is a MUCH more 
complex project.

Sorry to sound so discouraging (and as I said, others may have much more 
encouraging suggestions for ways to approach this),
-Bill

> At work we use Selenium and Java so I'm aware that Selenium comes with a 
> Python driver.  Would that be a good place to start?
> 
> Apologies if I'm not supposed to ask more than one question per mail but 
> these are all closely related and could be thought of as "newbie struggling 
> to see the wood/forest for the trees!"
> 
> Many thanks for your help
> 
> Regards
> Marcus
> 
> 
> ___
> 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


[Tutor] Learning Python through automating web application testing.

2012-12-14 Thread marcusw4...@hotmail.co.uk
Hello all,

I'm new to posting on mailing lists so hopefully I've picked the correct
one for my question(s).

A little about my programming experience first.

I work as a 'black box' software tester on a website/application so am
familiar with the IT development process but when it comes to
programming I'm very much a keenly interested newbie. To give you some idea
of my current ability it would be (with a bit of revision) around chapter 8
of Wesley Chun's "Core Python programming".

I do not in any way mean this as a criticism of "Core Python" but to learn,
what I really need is a project. Although "Core Python" rigorously tackles
it's subject; I've found I need a more tangible reason than "It would be
great if I could program" to stay focused on working my way through the
book. It took more than one attempt to get to chapter 8 and as I was
stubbornly refusing to ask for help (madness I know) it became quite
disheartening when I found some questions tough going. It will be an
invaluable point of reference in the future, it's simply I don't currently
need to understand it's subject with the depth it offers.  All I need at
the moment is "enough to get started" which by my rough calculation is
around 4.35% (not including appendices) of what "Core Python" has to offer!

So what I need is a small(ish) project that introduces thoroughly a useful
part of the Python language while teaching me how to program.  But for what
will sound like a silly reason I've always managed to avoid undertaking
this task. Basically a fear of failure has stopped me from starting. I mean
I've always talked a good game but what if I'm not sharp enough to learn to
competently program?  Not attempting is better than failing surely?

Because of this fear I've never admitted I've got a ready made project just
waiting for me to tackle...

Until now!

I would like to learn to automate the testing of a http(s) web
site/applications but feel slightly overwhelmed by this task so would like
to ask for some initial guidance.

These are some of questions that I have.

How do I go about this?

Where do I start?

There's just so much out there to help with learning Python I'm
experiencing information overload!

How do I stop myself from trying to run before I can walk?

In a perfect world a step by step guide, in automating web tests, using
Python is what I'm after but failing that(!) which sites/forums/mailing
lists are of particular interest to someone who would like to learn Python
programming initially through automating web tests?  (By web tests, to
begin with, I mean automated regression testing of a site by multiple users)

At work we use Selenium and Java so I'm aware that Selenium comes with a
Python driver.  Would that be a good place to start?

Apologies if I'm not supposed to ask more than one question per mail but
these are all closely related and could be thought of as "newbie struggling
to see the wood/forest for the trees!"

Many thanks for your help

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


Re: [Tutor] Learning Python ...Books

2010-08-13 Thread Wayne Werner
On Fri, Aug 13, 2010 at 5:22 AM, Stephen Farthing wrote:

> Hi everyone,
>
> I am going to learn both Python and Ruby so I can see what suits me best.
> My ultimate aim is to do some open source cross platform development for my
> ham radio and robotics hobbies. One of the key requirements is to be able to
> control hardware, via USB, using a GUI.
>

Using the pyserial module: http://pyserial.sourceforge.net/, and depending
on how advanced you want to get, Tkinter, pyGTK, wxPython, or PyQT (as the
main choices) are great ways to do such a thing. I've used pyserial with my
Arduino under Ubuntu and it worked great.


> What I was wondering is if there is a Python equivalent to "The C
> Programming language" by Kernighan and Richie which is the best text on
> programming i have ever read.
>

 This post:
http://stackoverflow.com/questions/947942/advanced-python-programming-book-like-effective-c
has
several books. I've heard that Wesley Chun's book (who also happens to
contribute here every so often ;) Core Python Programming is a great one.

I'm a big tutorial reader - reading tutorials with plenty of examples is how
I learn best - I've done a lot of eBooks. One great resource that
surprisingly few people mention (mainly because it's "for kids" - that just
means it's a lot more entertaining :) is Snake Wrangling for Kids:
http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids/

It covers all the basic stuff that's easy to blitz through if you're
familiar with programming, and then towards the end it gets a little into
programming with Tkinter.

Anyhow, HTH, good luck, and welcome!
If you get stuck, there are plenty of people here willing to help (which you
may find par for the course when dealing with Pythonistas).
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python ...Books

2010-08-13 Thread Bill Allen
On Fri, Aug 13, 2010 at 7:29 AM, Bill Allen  wrote:

>
>
> There are several books out there, some for Python 2.x, some for Python
> 3.x.   None that are quite like K&R in my opinion.
> However, here are some resources that may be useful for you, web based but
> some providing PDF download so you can build a book if you like.
>
> A Byte of Python 
>
> Dive into Python v.2    Dive into Python
> v.3 
>
> The Learning to Program Website (teaches using 
> Python)
>
> How to Think Like a Computer Scientist (also teaches using 
> Python)
>
> Bill
>
>
> I also forgot to mention that the Python book that I am reading right now
is Programming in Python 3 by Mark
Summerfield


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


[Tutor] Learning Python ...Books

2010-08-13 Thread Bill Allen
On Fri, Aug 13, 2010 at 5:22 AM, Stephen Farthing wrote:

>
> What I was wondering is if there is a Python equivalent to "The C
> Programming language" by Kernighan and Richie which is the best text on
> programming i have ever read.
>
> Thanks in advance,
>
> Steve
>

Steve,

There are several books out there, some for Python 2.x, some for Python
3.x.   None that are quite like K&R in my opinion.
However, here are some resources that may be useful for you, web based but
some providing PDF download so you can build a book if you like.

A Byte of Python 

Dive into Python v.2    Dive into
Python v.3

The Learning to Program Website (teaches using Python)

How to Think Like a Computer Scientist (also teaches using
Python)

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


Re: [Tutor] Learning Python ...Books

2010-08-13 Thread Joel Goldstick
I like "Learning Python" (O'reilly)

Its thicker, but excellent.  There isn't really an equivalent to K & R.
But, you should go to python.org and read the docs.  They are very good

On Fri, Aug 13, 2010 at 6:22 AM, Stephen Farthing wrote:

> Hi everyone,
>
> I am going to learn both Python and Ruby so I can see what suits me best.
> My ultimate aim is to do some open source cross platform development for my
> ham radio and robotics hobbies. One of the key requirements is to be able to
> control hardware, via USB, using a GUI.
>
>  I am an old school programmer - PL/1, Cobol, RTL/2, Algol 60 and I
> currently use C to program microcontrollers. I like Jackson Structured
> Programming (the other Michael Jackson) and am not up to speed with Object
> Orientation.  I also learn stuff best from books.
>
> What I was wondering is if there is a Python equivalent to "The C
> Programming language" by Kernighan and Richie which is the best text on
> programming i have ever read.
>
> Thanks in advance,
>
> Steve
>
> --
> It is vain to do with more that which can be done with less.
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


[Tutor] Learning Python ...Books

2010-08-13 Thread Stephen Farthing
Hi everyone,

I am going to learn both Python and Ruby so I can see what suits me best. My
ultimate aim is to do some open source cross platform development for my ham
radio and robotics hobbies. One of the key requirements is to be able to
control hardware, via USB, using a GUI.

 I am an old school programmer - PL/1, Cobol, RTL/2, Algol 60 and I
currently use C to program microcontrollers. I like Jackson Structured
Programming (the other Michael Jackson) and am not up to speed with Object
Orientation.  I also learn stuff best from books.

What I was wondering is if there is a Python equivalent to "The C
Programming language" by Kernighan and Richie which is the best text on
programming i have ever read.

Thanks in advance,

Steve

-- 
It is vain to do with more that which can be done with less.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning python using Michael Dawson's book

2010-05-17 Thread Steven D'Aprano
On Mon, 17 May 2010 11:08:38 pm Peter wrote:
> Hello,
> I am at the very beginning of learning Python. If anyone is familiar
> with Michael Dawson's book: "Python Programming for the Absolute
> Beginner" The following script (according to the book) should create
> "block lettering" created by dashes and vertical lines. If I could
> show a picture of it I would.

Why don't you copy and paste it?


> I do not get the same result as the book.

What result do you get?

What result do you expect?



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


Re: [Tutor] Learning python using Michael Dawson's book

2010-05-17 Thread Luke Paireepinart
I don't see any printing of dashes whatsoever.
can you explain in more detail what output you're getting, how it's
different from what you expected, and why you think that happened?

On 5/17/10, Peter  wrote:
> Hello,
> I am at the very beginning of learning Python. If anyone is familiar
> with Michael Dawson's book: "Python Programming for the Absolute Beginner"
> The following script (according to the book) should create "block
> lettering" created by dashes and vertical lines. If I could show a
> picture of it I would. I do not get the same result as the book.
> Thank you for any input.
> Peter
>
>
> The script goes like this:
>
> ---
>
> #Game Over- Version 2
> #Demonstrates the use of quotes in strings
>
> print("Program 'Game Over' 2.0")
>
> print("Same", "message", "as before")
>
> print("Just",
>  "a bit",
>  "bigger")
>
> print("Here", end=" ")
> print("it is...")
>
> print(
> """
> """
> )
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

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


[Tutor] Learning python using Michael Dawson's book

2010-05-17 Thread Peter

Hello,
I am at the very beginning of learning Python. If anyone is familiar 
with Michael Dawson's book: "Python Programming for the Absolute Beginner"
The following script (according to the book) should create "block 
lettering" created by dashes and vertical lines. If I could show a 
picture of it I would. I do not get the same result as the book.

Thank you for any input.
Peter


The script goes like this:

---

#Game Over- Version 2
#Demonstrates the use of quotes in strings

print("Program 'Game Over' 2.0")

print("Same", "message", "as before")

print("Just",
"a bit",
"bigger")

print("Here", end=" ")
print("it is...")

print(
   """
   """
   )

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


Re: [Tutor] Learning Python

2009-12-13 Thread David
Hi,

Kent Johnson wrote:
> Python in a Nutshell is good if you want a compressed but readable
> introduction.

I am thinking of buying this one, but the topical 2nd edition is from
2006. Does anyone know if a new version, covering Python 3, is coming to
market soonish?

David


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


Re: [Tutor] Learning Python

2009-12-13 Thread Emile van Sebille

On 12/13/2009 4:36 AM Grigor Kolev said...


Your __init__ looks OK.  All the other methods return either self.list 
or (with sort and append) return None because you've reassigned 
self.list to the return value of self.list.sort() and 
self.list.append()(both sort and append methods change the object in 
place and return None -- which you've then assigned to self.list)


I've added comment lines below that describe what I would expect each 
method to do.  You'll need to write python code to perform each 
description.  I've completed one to get you started.


I'd advise you to revisit the tutorial and refresh your working 
knowledge of core python.  Magic methods might a bit advanced.


Emile



My answer is:
class MyList ():
def __init__(self, value=[]):
self.list=[]
for i in value:
self.list.append(i)
def __add__(self , other):

# add other to self.list
# return self.list += other

return self.list
def __mul__(self , other):

# return the result of multiplying self.list by other

return self .list
def __delitem__(self , other):

# delete item other from self.list

return self .list
def __geritem__(self , other):  

# return self.list's other item

return self.list
def __repeat__(self , other):

# ?? maybe repr?
		return self.list 
	def sort(self  ):

# sort self.list in place

self.list = self.list.sort()
		return self.list 
	def append(self , other):

# append item other to self.list

self.list=self.list.append(other)
		return self.list 



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


Re: [Tutor] Learning Python

2009-12-13 Thread Alan Gauld

"Grigor Kolev"  wrote



My answer is:
class MyList ():
def __init__(self, value=[]):
self.list=[]
for i in value:
self.list.append(i)
def __add__(self , other):
return self.list
def __mul__(self , other):
return self .list
def __delitem__(self , other):
return self .list
def __geritem__(self , other):
return self.list
def __repeat__(self , other):
return self.list
def sort(self  ):
self.list = self.list.sort()
return self.list
def append(self , other):
self.list=self.list.append(other)
return self.list

This is work


Given that add does not add anything how do you define "work"?
Do you mean it executes without error messages?



--
In the book answer is this:

class MyList:
 def _ _init_ _(self, start):
   #self.wrapped = start[:] # Copy start: no side effects
   self.wrapped = []# Make sure it's a list here
for x in start: self.wrapped.append(x)
def _ _add_ _(self, other):
return MyList(self.wrapped + other)
def _ _mul_ _(self, time):
return MyList(self.wrapped * time)
def _ _getitem_ _(self, offset):
return self.wrapped[offset]
def _ _len_ _(self):
return len(self.wrapped)
def _ _getslice_ _(self, low, high):
return MyList(self.wrapped[low:high])
def append(self, node):
self.wrapped.append(node)
def _ _getattr_ _(self, name):   # Other members: sort/reverse/etc
return getattr(self.wrapped, name)
def _ _repr_ _(self):
return repr(self.wrapped)

Answer in the book does not work
Where is the error


What error do you get?
These merthods do entirely different things to yours.
But without an error description its hard to comment, I don't feel like
reading through line buy line trying to guess what the problem might be.

It will also help if you tell us which version of Python you are using and
which Operating System.

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


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


[Tutor] Learning Python

2009-12-13 Thread Grigor Kolev
It is from book Learning Python

Operator overloading. Write a class called Mylist that shadows (“wraps”)
a Python
list: it should overload most list operators and operations, including
+, indexing,
iteration, slicing, and list methods such as append and sort. See the
Python
reference manual for a list of all possible methods to support. Also,
provide a con-
structor for your class that takes an existing list (or a Mylist
instance) and copies
its components into an instance member. Experiment with your class
interac-
tively. Things to explore:
  a. Why is copying the initial value important here?
  b. Can you use an empty slice (e.g., start[:]) to copy the initial
value if it’s a
  Mylist instance?
c. Is there a general way to route list method calls to the wrapped
list?
d. Can you add a Mylist and a regular list? How about a list and a
Mylist
   instance?
e. What type of object should operations like + and slicing return? What
about
   indexing operations?
f. If you are working with a more recent Python release (version 2.2 or
later),
   you may implement this sort of wrapper class by embedding a real list
in a
   standalone class, or by extending the built-in list type with a
subclass.
   Which is easier, and why?

My answer is:
class MyList ():
def __init__(self, value=[]):
self.list=[]
for i in value:
self.list.append(i)
def __add__(self , other):
return self.list
def __mul__(self , other):
return self .list
def __delitem__(self , other):
return self .list
def __geritem__(self , other):  
return self.list
def __repeat__(self , other):
return self.list 
def sort(self  ):
self.list = self.list.sort()
return self.list 
def append(self , other):
self.list=self.list.append(other)
return self.list 

This is work
--
In the book answer is this:

class MyList:
 def _ _init_ _(self, start):
#self.wrapped = start[:] # Copy start: no side effects
self.wrapped = []# Make sure it's a list here
for x in start: self.wrapped.append(x)
def _ _add_ _(self, other):
return MyList(self.wrapped + other)
def _ _mul_ _(self, time):
return MyList(self.wrapped * time)
def _ _getitem_ _(self, offset):
return self.wrapped[offset]
def _ _len_ _(self):
return len(self.wrapped)
def _ _getslice_ _(self, low, high):
return MyList(self.wrapped[low:high])
def append(self, node):
self.wrapped.append(node)
def _ _getattr_ _(self, name):   # Other members: 
sort/reverse/etc
return getattr(self.wrapped, name)
def _ _repr_ _(self):
return repr(self.wrapped)

Answer in the book does not work
Where is the error
-- 
Grigor Kolev 

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


Re: [Tutor] Learning Python from books

2008-06-20 Thread Kent Johnson
On Thu, Jun 19, 2008 at 2:56 PM, Zameer Manji <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
>
> Has anyone here attempted to learn Python from books ?

I learned Python from Learning Python and Python Cookbook initially.
Also lots of practice. Reading comp.lang.python is another good way to
learn.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python from books

2008-06-19 Thread Lowell Tackett
"Python Programming [for the absolute beginner]" by Michael Dawson is-in my 
humble opinion-a programming pedagogical pacesetter.

>From the virtual desk of Lowell Tackett  



--- On Thu, 6/19/08, Zameer Manji <[EMAIL PROTECTED]> wrote:

> From: Zameer Manji <[EMAIL PROTECTED]>
> Subject: [Tutor] Learning Python from books
> To: "Python Tutor mailing list" 
> Date: Thursday, June 19, 2008, 2:56 PM
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
> 
> Has anyone here attempted to learn Python from books ? I
> recently
> purchased "Learning Python" 3rd Edition
> (9780596513986) and if anyone
> here is a good bottom-up learner than it is the perfect
> book. The author
> goes over each feature in python, explaining it's
> syntax, usage and the
> "pythonic" way of using them in programs. It has
> really helped me
> understand some of the more powerful tools in python and I
> am sure it
> will make an excellent reference book in the future. With
> that said, has
> anyone else attempted to learn python from books and if so
> which one ?
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.7 (MingW32)
> 
> iQEcBAEBCgAGBQJIWqvxAAoJEA759sZQuQ1BS+kIAK+6TWqesUQjEQygwsMI3seU
> ZWUkd4wlextCOXIH6mse4TMHdAU3+NHDo1V4QwSYxNTEjwpWFr1Kg2BE0zyMyxPD
> gs8Kaov6/DGQgyFFt5DRcKvkQ0M5St7I/PuP+n/eelMUK1culvXx3oycKBqh8D21
> R/g0SQ0M9pUDLuBEygbgjFw1WVsf/h8/zCc38qHQ+QOQvrVaEciV3I5JLyp3+u8g
> JyjzxjHSRHd4Ik4cnaeKa2OyFn5JaPXxPmrmPiE3WEWnJxLWucXAP/CEm7e9aamQ
> Fv4SYuVmOIGpbAqySgEpQH2yRsd+0qaNKSJq4hqjQ1/z2Bx6hM5LTqJAVjfZMW4=
> =9xVw
> -END PGP SIGNATURE-
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


  

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python from books

2008-06-19 Thread Jason Conner
I use the same books - Learning Python and Core Python Programming, 2nd ed.
I found I got about halfway through Learning Python before I switched to CPP
and had no problems. I also use "Python Phrasebook" (Brad Dayley, 2007) as a
handy reference guide to some common problems as well.

Core Python Programming, 2nd ed. (Wesley Chun, 2007) is my most frequent
instructional guide, though.

On Fri, Jun 20, 2008 at 9:39 AM, jay <[EMAIL PROTECTED]> wrote:

> Me personally, both "Learning Python" and "Core Python Programming".  I am
> by no means an expert, but both of these books are excellent and were quite
> helpful.
>
> jay
>
>
> On Thu, Jun 19, 2008 at 1:56 PM, Zameer Manji <[EMAIL PROTECTED]> wrote:
>
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA512
>>
>> Has anyone here attempted to learn Python from books ? I recently
>> purchased "Learning Python" 3rd Edition (9780596513986) and if anyone
>> here is a good bottom-up learner than it is the perfect book. The author
>> goes over each feature in python, explaining it's syntax, usage and the
>> "pythonic" way of using them in programs. It has really helped me
>> understand some of the more powerful tools in python and I am sure it
>> will make an excellent reference book in the future. With that said, has
>> anyone else attempted to learn python from books and if so which one ?
>> -BEGIN PGP SIGNATURE-
>> Version: GnuPG v1.4.7 (MingW32)
>>
>> iQEcBAEBCgAGBQJIWqvxAAoJEA759sZQuQ1BS+kIAK+6TWqesUQjEQygwsMI3seU
>> ZWUkd4wlextCOXIH6mse4TMHdAU3+NHDo1V4QwSYxNTEjwpWFr1Kg2BE0zyMyxPD
>> gs8Kaov6/DGQgyFFt5DRcKvkQ0M5St7I/PuP+n/eelMUK1culvXx3oycKBqh8D21
>> R/g0SQ0M9pUDLuBEygbgjFw1WVsf/h8/zCc38qHQ+QOQvrVaEciV3I5JLyp3+u8g
>> JyjzxjHSRHd4Ik4cnaeKa2OyFn5JaPXxPmrmPiE3WEWnJxLWucXAP/CEm7e9aamQ
>> Fv4SYuVmOIGpbAqySgEpQH2yRsd+0qaNKSJq4hqjQ1/z2Bx6hM5LTqJAVjfZMW4=
>> =9xVw
>> -END PGP SIGNATURE-
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python from books

2008-06-19 Thread jay
Me personally, both "Learning Python" and "Core Python Programming".  I am
by no means an expert, but both of these books are excellent and were quite
helpful.

jay

On Thu, Jun 19, 2008 at 1:56 PM, Zameer Manji <[EMAIL PROTECTED]> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA512
>
> Has anyone here attempted to learn Python from books ? I recently
> purchased "Learning Python" 3rd Edition (9780596513986) and if anyone
> here is a good bottom-up learner than it is the perfect book. The author
> goes over each feature in python, explaining it's syntax, usage and the
> "pythonic" way of using them in programs. It has really helped me
> understand some of the more powerful tools in python and I am sure it
> will make an excellent reference book in the future. With that said, has
> anyone else attempted to learn python from books and if so which one ?
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.7 (MingW32)
>
> iQEcBAEBCgAGBQJIWqvxAAoJEA759sZQuQ1BS+kIAK+6TWqesUQjEQygwsMI3seU
> ZWUkd4wlextCOXIH6mse4TMHdAU3+NHDo1V4QwSYxNTEjwpWFr1Kg2BE0zyMyxPD
> gs8Kaov6/DGQgyFFt5DRcKvkQ0M5St7I/PuP+n/eelMUK1culvXx3oycKBqh8D21
> R/g0SQ0M9pUDLuBEygbgjFw1WVsf/h8/zCc38qHQ+QOQvrVaEciV3I5JLyp3+u8g
> JyjzxjHSRHd4Ik4cnaeKa2OyFn5JaPXxPmrmPiE3WEWnJxLWucXAP/CEm7e9aamQ
> Fv4SYuVmOIGpbAqySgEpQH2yRsd+0qaNKSJq4hqjQ1/z2Bx6hM5LTqJAVjfZMW4=
> =9xVw
> -END PGP SIGNATURE-
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning Python from books

2008-06-19 Thread Zameer Manji
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Has anyone here attempted to learn Python from books ? I recently
purchased "Learning Python" 3rd Edition (9780596513986) and if anyone
here is a good bottom-up learner than it is the perfect book. The author
goes over each feature in python, explaining it's syntax, usage and the
"pythonic" way of using them in programs. It has really helped me
understand some of the more powerful tools in python and I am sure it
will make an excellent reference book in the future. With that said, has
anyone else attempted to learn python from books and if so which one ?
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)

iQEcBAEBCgAGBQJIWqvxAAoJEA759sZQuQ1BS+kIAK+6TWqesUQjEQygwsMI3seU
ZWUkd4wlextCOXIH6mse4TMHdAU3+NHDo1V4QwSYxNTEjwpWFr1Kg2BE0zyMyxPD
gs8Kaov6/DGQgyFFt5DRcKvkQ0M5St7I/PuP+n/eelMUK1culvXx3oycKBqh8D21
R/g0SQ0M9pUDLuBEygbgjFw1WVsf/h8/zCc38qHQ+QOQvrVaEciV3I5JLyp3+u8g
JyjzxjHSRHd4Ik4cnaeKa2OyFn5JaPXxPmrmPiE3WEWnJxLWucXAP/CEm7e9aamQ
Fv4SYuVmOIGpbAqySgEpQH2yRsd+0qaNKSJq4hqjQ1/z2Bx6hM5LTqJAVjfZMW4=
=9xVw
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python (Ara Kooser)

2007-09-29 Thread Ara Kooser
Fred,

I've been learning python off and on for a couple years now. I recommend:
Alan Gauld's Learning to Program http://www.freenetpages.co.uk/hp/alan.gauld/
and
How to Think Like a Computer Scientist http://www.ibiblio.org/obp/thinkCSpy/

Also find a project you are passionate about and try to program it in Python.

I like Traveller (an old rpg) and text adventure games. So I used
Python to create some utilities and then a game. Hope this helps.

Ara



-- 
Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis
an sub cardine glacialis ursae.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2007-09-29 Thread Alan Gauld

"Fred P" <[EMAIL PROTECTED]> wrote

> I am completely new at python, but not new to programming or
> scripting.  I have a couple of years of LUA scripting experience,
> about a year of C++ classes, and used to be very efficient at 
> c-shell
> scripting in unix.
>
> My question for you guys:
>
> 1) How do I get Started?

Download/install python

> 2) Recommend any specific Books?
> 3) Any online tutors/ forums that would benefit a newbie

There are a bunch of them in the beginners section of the python web 
site.
The best starting point is the official tutor which can be skipped 
through
in a half day and will give you all the basics (and quite a lot of the 
non
basics too)

> 4) Any online classes that teach python?  I have taken online c++
> courses, and found them helpful.  I was hoping to find something for
> python.

You might like the ShowMeDo videos.

> My main objective is to write scripts for the following type of
> applications
> File management, file copies/syncs/ compares
> Text manipulation - like parsing text files to replace or augment
> specific values
> Integration into current applications to write redundant routines 
> and
> maybe some day plugins

You might even find my tutorial useful since it targets those kinds of 
tasks.
It is aimed at absolute beginners however so may well be too basic for
you.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2007-09-29 Thread Kent Johnson
Fred P wrote:

> 1) How do I get Started?

The official tutorial is quite accessible if you have some programming 
experience. More tutorials are listed here:
http://wiki.python.org/moin/BeginnersGuide/Programmers

> 2) Recommend any specific Books?

I like Learning Python (O'Reilly)
Python in a Nutshell is good if you want a compressed but readable 
introduction.

> 3) Any online tutors/ forums that would benefit a newbie

You found that already; stick around!

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2007-09-29 Thread Michael Langford
errhttp://www.diveintopython.org is the actual url

   =Michael

On 9/29/07, Michael Langford <[EMAIL PROTECTED]> wrote:
> http://www.diveintopython.com is a *Great* start for experienced
> software developers. Within a weekend with that book I'd written an
> entire parser/decompiler when I'd never used python before that.
>
> --michael
>
> On 9/29/07, Fred P <[EMAIL PROTECTED]> wrote:
> > Hey Everyone,
> >
> > I am completely new at python, but not new to programming or
> > scripting.  I have a couple of years of LUA scripting experience,
> > about a year of C++ classes, and used to be very efficient at c-shell
> > scripting in unix.
> >
> > My question for you guys:
> >
> > 1) How do I get Started?
> >
> > 2) Recommend any specific Books?
> >
> > 3) Any online tutors/ forums that would benefit a newbie
> >
> > 4) Any online classes that teach python?  I have taken online c++
> > courses, and found them helpful.  I was hoping to find something for
> > python.
> >
> > My main objective is to write scripts for the following type of
> > applications
> > File management, file copies/syncs/ compares
> > Text manipulation - like parsing text files to replace or augment
> > specific values
> > Integration into current applications to write redundant routines and
> > maybe some day plugins
> >
> > I am not even sure what else, but I do know that every time i think
> > of something that we need at work, other people say, "That would be a
> > good task for a python script"  and I would eventually like to be
> > able to do something about that.
> >
> > Thanks
> > Fred
> >
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
> --
> Michael Langford
> Phone: 404-386-0495
> Consulting: http://www.TierOneDesign.com/
> Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/
Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2007-09-29 Thread Michael Langford
http://www.diveintopython.com is a *Great* start for experienced
software developers. Within a weekend with that book I'd written an
entire parser/decompiler when I'd never used python before that.

--michael

On 9/29/07, Fred P <[EMAIL PROTECTED]> wrote:
> Hey Everyone,
>
> I am completely new at python, but not new to programming or
> scripting.  I have a couple of years of LUA scripting experience,
> about a year of C++ classes, and used to be very efficient at c-shell
> scripting in unix.
>
> My question for you guys:
>
> 1) How do I get Started?
>
> 2) Recommend any specific Books?
>
> 3) Any online tutors/ forums that would benefit a newbie
>
> 4) Any online classes that teach python?  I have taken online c++
> courses, and found them helpful.  I was hoping to find something for
> python.
>
> My main objective is to write scripts for the following type of
> applications
> File management, file copies/syncs/ compares
> Text manipulation - like parsing text files to replace or augment
> specific values
> Integration into current applications to write redundant routines and
> maybe some day plugins
>
> I am not even sure what else, but I do know that every time i think
> of something that we need at work, other people say, "That would be a
> good task for a python script"  and I would eventually like to be
> able to do something about that.
>
> Thanks
> Fred
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/
Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning Python

2007-09-29 Thread Fred P
Hey Everyone,

I am completely new at python, but not new to programming or  
scripting.  I have a couple of years of LUA scripting experience,  
about a year of C++ classes, and used to be very efficient at c-shell  
scripting in unix.

My question for you guys:

1) How do I get Started?

2) Recommend any specific Books?

3) Any online tutors/ forums that would benefit a newbie

4) Any online classes that teach python?  I have taken online c++  
courses, and found them helpful.  I was hoping to find something for  
python.

My main objective is to write scripts for the following type of  
applications
File management, file copies/syncs/ compares
Text manipulation - like parsing text files to replace or augment  
specific values
Integration into current applications to write redundant routines and  
maybe some day plugins

I am not even sure what else, but I do know that every time i think  
of something that we need at work, other people say, "That would be a  
good task for a python script"  and I would eventually like to be  
able to do something about that.

Thanks
Fred



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python in cooperative, challenging way.

2007-04-17 Thread Mike Hansen
 

> -Original Message-
> 
> To clarify point #2: Python - as any learning - IS 
> challenging, but as I am
> learning it "just for fun" and without any real need to 
> fulfil, I don't have any
> "operational challenge", if that makes any sense in English... :-/
> 
> So far the best I could find has been: #1 --> this mailing list #2 -->
> http://www.pythonchallenge.com
> 
> Any more suggestions from your side?
> 
> Thank you very much in advance,
> Mac.

You look at some of the ideas at this page.

http://effbot.org/pyfaq/tutor-im-learning-python-what-should-i-program.h
tm

or http://tinyurl.com/yalvar

Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning Python in cooperative, challenging way.

2007-04-17 Thread Giulio 'Mac' Maistrelli
Hello everybody,

I hope this is the right place to make this question. If not I would 
appreciate
help in getting pointed towards a different resource...

I just began to learn python. It is a nice language to learn, and I am 
using
"dive into python" which is also a nicely written book... yet I am missing a lot
two aspects in this learning experience:

1) The co-operation / interaction with other learners (and/or teachers).
2) The challenge

To clarify point #2: Python - as any learning - IS challenging, but as I am
learning it "just for fun" and without any real need to fulfil, I don't have any
"operational challenge", if that makes any sense in English... :-/

So far the best I could find has been: #1 --> this mailing list #2 -->
http://www.pythonchallenge.com

Any more suggestions from your side?

Thank you very much in advance,
Mac.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2006-03-28 Thread Hoffmann
I do recommend three books:

(1) "How to Think Like a Computer Scientist: Learning
with Python", by Allen Downey, Jeffrey Elkner, and
Chris Meyers. There exist a free online version, too:
http://www.ibiblio.org/obp/thinkCSpy/

(2) "Learning Python", by Mark Lutz and David Ascher.

(3) "Beginning Python", by Magnus Lie Hetland.

This is all you need for a good start with python.

Hoffmann

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2006-03-28 Thread stv
If you're a bookish type, I found Magnus Lie Hetland's "Beginning
Python" excellent. It's really more than a beginners books. I came to
Python with a scripting background--mostly lightweight OS stuff
(Applescript, DOS) as well as a lot of lightweight application
programming (Filemaker, SQL, VBA for Excel, etc) and I got a lot out
of the book.

It covers the basics for a true beginner, but not in a dumbed-down
way. It's also well indexed & somewhat useful as a reference for the
most common things.

Mark Pilgrim's "Dive Into Python" comes highly recommended, and is
available on-line.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2006-03-27 Thread Kaushal Shriyan
On 3/27/06, Noufal Ibrahim <[EMAIL PROTECTED]> wrote:
>
> On Mon, March 27, 2006 4:39 pm, Kaushal Shriyan wrote:
> > Hi
> >
> > I am a novice in Python, Which is the best source of learning python
> > for a beginner
>
> If you're already a "programmer", then the python tutorial at
> http://docs.python.org/tut/tut.html + a working python installation is
> enough IMHO.
>
> If you want to learn programming itself, perhaps you should take a look at
> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
>
> Good luck!
> --
> -NI
>
>

Thanks a Ton, I will definetly ping and update all of you :)

Regards

KaushaL
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2006-03-27 Thread Noufal Ibrahim

On Mon, March 27, 2006 4:39 pm, Kaushal Shriyan wrote:
> Hi
>
> I am a novice in Python, Which is the best source of learning python
> for a beginner

If you're already a "programmer", then the python tutorial at
http://docs.python.org/tut/tut.html + a working python installation is
enough IMHO.

If you want to learn programming itself, perhaps you should take a look at
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Good luck!
-- 
-NI

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python

2006-03-27 Thread Kent Johnson
Kaushal Shriyan wrote:
> Hi
> 
> I am a novice in Python, Which is the best source of learning python
> for a beginner

Read one of the tutorials listed here:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Write simple programs to try out what you have learned. Ask questions 
here when you get stuck.

Have fun!
Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning Python

2006-03-27 Thread Kaushal Shriyan
Hi

I am a novice in Python, Which is the best source of learning python
for a beginner

Regards

Kaushal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning Python with a Simple IM

2005-07-10 Thread Alan G
Hi Jorge,

> I am a Java Developer that wants to learn Python by doing.
> I am loving this initial vibe I'm getting out of Python.
> However, because I feel programmers of a certain languages
> bring with them certain vices when moving to other languages,

Absolutely right, thats why its good to learn several languages
- to see the world from different angles! ;-)

> print "Please enter the following information"
> _url = raw_input("URL: ")

Using an underscore in front of a variable is usually done in a class 
to
make the member "invisible" - a wee bit like private in Java, but
much less rigorous. Its not often used for normal variables in a 
program.

> print '\n'
> print "Connecting to server..."
> print '\n'

Using a tripple quioted string might be easier here:

print '''
Connecting to seerver
'''

>def listener():
>while 1:
>time.sleep(5)
>socketOut.sendall('$$$'+_from)
>response = socketOut.recv(8192)
>if response != " ":
>print "\n" + response

There is no break in this loop so it will run forever.
That might be what you want, but usually I'd put some kind of
breakout mechanism even on a long running server daemon.

>if msvcrt.kbhit():
>ch = msvcrt.getche()

I may be wrong but I don;t think you need the kbhit() function,
getch[e]() will block and wait for a keypress.

>else:
>ch = None

Which in turn means ch should never be None...
Although it might never exist if kbhit is not True since getche
will never be called and thus ch will never be created!

Alan G.
(Recovering from G8 riots 300m from his house!)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning Python with a Simple IM

2005-07-10 Thread Jorge Louis De Castro




Hello,
 
I am a Java Developer that wants to learn 
Python by doing. I am loving this initial vibe I'm getting 
out of Python. However, because I feel programmers of a 
certain languages bring with them certain vices when moving to other 
languages, I'd like to have feedback from seasoned Python programmers regarding 
my code.
Using some socket examples I've googled here and 
there I wrote the very simple Instant-Messaging-wannabe program below. I 
was advised to post the code here and get feedback from this 
community.
In my next iteration with this code I'll 
be changing the client to include a server thread listening instead of 
polling the server.
 
Regards
jorge
 
 
THE SIMPLE IM CLIENT
 
import socket, threading, time, msvcrt
 
print "Please enter the following 
information"_url = raw_input("URL: ")_port = raw_input("Port: 
")print "Starting IIM client on port: " + _port
 
socketOut = socket.socket(socket.AF_INET, 
socket.SOCK_STREAM)socketOut.connect((_url, int(_port)))
 
# clear screen here
 
print "Enter your user details"_from = 
raw_input("User id: ")_to = raw_input("Buddy id: ")
 
print '\n'print "Connecting to 
server..."print '\n'
 
# send user details and receive 
responsesocketOut.sendall('@@@'+_from+'##'+_to)response 
= socketOut.recv(8192)
 
def listener():    while 
1:    
time.sleep(5)    
socketOut.sendall('$$$'+_from)    
response = socketOut.recv(8192)    if 
response != " 
":    print 
"\n" + response
 
if response == 'AUTH_OK':    data = 
""    th = 
threading.Thread(target=listener)    
th.setDaemon(1)    th.start()    print 
"Background polling thread started"    while 1:
 
    if 
msvcrt.kbhit():    
ch = msvcrt.getche()    
else:    ch = 
None    if 
ch:    if ch 
!= 
'\r':    
data += ch    
else:    
print 
'\n'    
socketOut.sendall('###'+_from+'##'+data)    
response = 
socketOut.recv(8192)    
if response != " 
":    
print 
response    
data = ""
 
else:    print "Auhentication 
failed!"    
socketOut.close()
 
 
 
 
THE SIMPLE IM SERVER
 
import SocketServer
 
_port = 8881_clients = {}
 
# a connected clientclass Client:    # queue of 
messages sent to this client    queue = 
[]    def __init__(self, _sock, _src, 
_dest):    print "Creating IM 
client"    self.socket = 
_sock    print "Incoming socket: %s" 
% self.socket    self.user = 
_src    print "Username: " + 
self.user    # buddies should be a 
list    self.buddy = 
_dest    print "Buddy: " + 
self.buddy    print "Created IM 
client"
 
# the server handling requestsclass 
Broker(SocketServer.BaseRequestHandler):    def 
handle(self):    print "Connected 
from", self.client_address    while 
True:    
receivedData = 
self.request.recv(8192)    
if not 
receivedData:    
break    
    # if 
handshake packet, extract client 
details    if 
receivedData.startswith('@@@',0,3):    
print "Received handshake 
packet"    
# strip handshake 
code    
receivedData = receivedData.replace('@@@', 
'', 
1).lstrip()    
l = 
receivedData.split('##',1)    
socket = 
self.request    
src = 
"">    
dest = 
l[1]    
c = Client(socket, src, 
dest)    
# use username as key on 
hashmap    
_clients[src] = 
c    
# send success 
message    
socket.sendall('AUTH_OK')    
print "Client " + src + " authenticated"
 
    # if 
polling packet, extract sender details and send 
messages    
if 
receivedData.startswith('$$$',0,3):    
# strip polling 
message    
print "Received polling 
packet"    
src = "" '', 
1).lstrip()    
# only poll if more than 1 
user    
if len(_clients) > 
1:    
    
# use username as key on 
hashmap    
_clients[src] = 
c    
if len(c.queue) < 
1:    
c.socket.sendall(" 
")    
else:    
msgs = 
""    
for q in 
c.queue:    
msgs += q + 
'\n'    
# send queued 
messages    
c.socket.sendall(msgs)    
c.queue = 
[]    
print "Sent all pending messages for " + 
c.user    
else:    
socket.sendall(" ")
 
    # if 
message packet, extract data and append to target 
queue    if 
receivedData.startswith('###',0,3):    
print "Received message 
packet"    
receivedData = receivedData.replace('###', '', 
1).lstrip()    
l = 
receivedData.split('##',1)    
src = 
"">    
text = 
l[1]   

Re: [Tutor] Learning python as a thing to do

2005-02-27 Thread Alan Gauld
> I am a Rubyist, but I've decided to learn Python 

Welcome, could be interesting. I'm a pythonista and 
have learned Ruby but not used it for anything significant 
yet.

> At any rate, so far Python seems to be a very good
> language. Not a great language, but still very good.

There is only one great language: Lisp :-)

> So far, some things I dont care for...
> immutable strings
> no case statement

Yes, most folks find those concepts pretty strange.
Personally I don't miss case statements (see a recent thread) 
I usually find Pythons stricture means I rethink the design 
and usually manage to avoid the need (and potential bugs that 
are inherent in case structures...) but mutable strings would 
be nice, although potentially dangerous for dictionary keys.

> lack of internal iterators

NOt sure what you mean by this one, can you expand?

> The mixing of functions and methods

You mean the fact that Python doesn't insist on everything 
being an object? That simply reflects that Python can be 
used in several difreent paradigms. Functional Programming 
is the biggest "modern" alternative to OOP and support for 
functions as first class objects supports that style. Ruby 
can fake it with its top level "invisible" object, but Python 
just makes that style a natural part of the language.

OTOH if you mean the inconsistencies in the use of methods 
versus functions in the base language (eg files have a close 
method but an open function) then I agree and Python is slowly 
removing those with each release. The biggest step being 
the introduction of strings as objects/methods and another 
step forward being the new-style classes in v2.x

This is one area where Matz learned lessons from Perl/Python 
when he invented Ruby - the advantage of going second (or 
third or fourth...)

> Question(s):
> Are there any good books/documents that actually
> examine the ruby way vs python way? (by someone that
> knows both languages)

NOt that I know of.

> The other day I saw a post from a gentleman trying to
> do a basic prompt and add type of calculator.
> He wanted to assign the +, or * operator to a variable
> to use, but I believe he was told you have to use the
> literal +, or *.

Thats possible using the operator module.

> Are these operators constanst in Python?

Not really, in that you can override them 
(__add__, __Sub__, __mul__ etc) and the operator module 
gives access to the common ones in a generic kind of way.

> If so, is there not a way to send that constant to
> act apon another variable or variables that refer to
> numbers?

I didn't see the post but it sounds as if the poster should 
have been able to do what [s]he wanted.

> In ruby, you can rerence the * operator
> operator = :*   
> num1 = 4
> num2 = 6
> num1.send(operator,num2)

In Python:

import operator
num1 = 4
num2 = 6
operator.mul(num1,num2)

Alan G.


> which returns 24
> 
> Have a nice day :-)
> 
> 
> 
> 
> __ 
> Do you Yahoo!? 
> Yahoo! Mail - now with 250MB free storage. Learn more.
> http://info.mail.yahoo.com/mail_250
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Learning python as a thing to do

2005-02-27 Thread Danny Yoo


On Sun, 27 Feb 2005, Greg T wrote:

> I am a Rubyist, but I've decided to learn Python so that when a
> conversation springs up about the merits of the two languages amd how
> they compare, I will be well informed.

Hi Greg,

Welcome aboard!  That sounds great; you can help us understand Ruby better
when we have questions.  *grin*


> So far, some things I dont care for and have me scratching my head:

Ok, we'll try addressing some of your head-scratching questions:



> immutable strings

Immutable strings aren't unique to Python: technically, string literals in
C are also supposed to be immutable (that's why GCC supports the
'-fno-const-strings' flag!) , and they're also immutable in Java.


The other thing is that Python follows a model where values are objects,
and variable names are just references to values.  So when we do something
like:

###
>>> message = "hello world"
>>> anotherMsg = message
###

Both 'message' and 'anotherMsg' both refer to a single string value.  We
can see this using the id() function:

###
>>> id(message)
3607272
>>> id(anotherMsg)
3607272
###

So there isn't any string copying going on here.


We can simulate mutable strings by turning a string into a list:

###
>>> myBuffer = list("hello world")
>>> myBuffer[1] = 'a'
>>> msg = ''.join(myBuffer)
>>> msg
'hallo world'
###



> no case statement

If you're doing a case analysis based on a single value, then a dispatch
table may be able to do what you want.  You may find:

http://mail.python.org/pipermail/tutor/2004-December/033728.html

helpful.



> lack of internal iterators

I'm not quite sure what you mean by "internal iterators".  There is an
iterator protocol that objects can support:

http://www.python.org/doc/lib/typeiter.html

where lists, files, and strings conform to the protocol and can be
iterated across with a 'for' loop.




> Question(s):
>
> Are there any good books/documents that actually examine the ruby way vs
> python way? (by someone that knows both languages)

I haven't seen one yet; if you find one, let us know.  I'm actually quite
interested in Ruby, since a friend of mine is writing Ruby code that I'll
probably have to maintain soon.  *grin*



> The other day I saw a post from a gentleman trying to do a basic prompt
> and add type of calculator. He wanted to assign the +, or * operator to
> a variable to use, but I believe he was told you have to use the literal
> +, or *.

The 'infix' operators aren't first-class in Python.  That being said,
there are first-class function equivalents in the 'operator' module:

http://www.python.org/doc/lib/module-operator.html

and these are first class, so it's possible to writing something like
this:

###
>>> import operator
>>> sumOfNumbersUpToTen = reduce(operator.add, range(1, 11))
>>> factorialTen = reduce(operator.mul, range(1, 11))
>>> sumOfNumbersUpToTen
55
>>> factorialTen
3628800
###



> In ruby, you can rerence the * operator
> operator = :*
> num1 = 4
> num2 = 6
> num1.send(operator,num2)
> which returns 24

Ok, I see, so in Ruby, numbers can receive a 'multiply' message.  This can
happen in Python too, although it's really not quite Pythonic:

###
>>> num1 = 4
>>> num1.__mul__(6)
24
###

Numbers in Python do have a fixed list of methods that they respond to:

http://www.python.org/doc/ref/numeric-types.html

but most Python numeric code will just use infix operators on numbers and
avoid an explicit message-passing style.


Best of wishes to you!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning python as a thing to do

2005-02-27 Thread Greg T
Hi,
I am a Rubyist, but I've decided to learn Python so
that when a conversation springs up about the merits
of the two languages amd how they compare, I will be
well informed. As it stands now, what you usually see
is people well versed in one or the other, making
generalizations when they dont really know the other
language.

At any rate, so far Python seems to be a very good
language. Not a great language, but still very good.

So far, some things I dont care for and have me
scratching my head:
immutable strings
no case statement
lack of internal iterators
The mixing of functions and methods

Some things that I like:
-list comprehensions
-the indentation scheme (I know alot of people dont
like
it at first experience, but I do)
-'one way to do it' philosophy (I dont have a problem
with 'more than one way to do it', but it makes a
language easier to learn with a 'one way' philosophy)

Question(s):
Are there any good books/documents that actually
examine the ruby way vs python way? (by someone that
knows both languages)

The other day I saw a post from a gentleman trying to
do a basic prompt and add type of calculator.
He wanted to assign the +, or * operator to a variable
to use, but I believe he was told you have to use the
literal +, or *.

Are these operators constanst in Python?
If so, is there not a way to send that constant to
act apon another variable or variables that refer to
numbers?

In ruby, you can rerence the * operator
operator = :*   
num1 = 4
num2 = 6
num1.send(operator,num2)
which returns 24

Have a nice day :-)




__ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor