I've been reading Dive Into Python for a couple of days have gotten far enough to tell what the following block of code does if the object variable is an arbitrary Python object

methodList = [method for method in dir(object) if callable(getattr(object, method))]
    processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
    print "\n".join(["%s %s" %
                      (method.ljust(spacing),
                       processFunc(str(getattr(object, method).__doc__)))
                     for method in methodList])

However I've been having a tougher time than I expected with learning Python using Dive Into Python for a couple of reasons, some to do with how the book is laid out and some to do with my choice of IronPython as my Python implementation of choice. The main problems I've been having are

  • IronPython doesn't have a number of standard libraries that are used in the book such as os, xml.dom, UserDict, sgmllib and so on. This means I can't construct or run a number of the more advanced samples in the book.
  • The book seems to dive into meaty topics before covering the basics. For example, introspection (aka reflection) and lambda functions (aka anonymous methods)  are covered in Chapter 4 while defining classes and importing modules is covered in Chapter 5. Similarly, a discussion on for loops seems to have been removed from the most recent version of the book and replaced with a discussion on list comprehensions which are definitely superior but more alien to the novice.
  • I tend to learn comparatively. Thus I would love to get a more direct mapping of constructs in C# to those in Python with  discussions on Python features that don't exist in C#. This is the tack I took with C# from a Java Developers perspective and it seems a lot of people found that useful.

For these reasons, I thought it would be useful to create a set of tutorials for myself that would address some of these issues I've been having. Then I wondered if other C# developers wouldn't find such an article or tutorial useful as well. Are there any C# developers out there that would actually be interested in this or am I an edge case?

PS: I wouldn't expect to get time to actually writing, editing and publishing such tutorials until the summer of next year at the earliest (which I expect should coincide with the availability of IronPython 2.0). 


 

Saturday, November 24, 2007 3:19:02 PM (GMT Standard Time, UTC+00:00)
If you're trying to use IronPython with CPython samples, then you want to download the "IronPython Community Edition" from http://fepy.sourceforge.net
Curt Hagenlocher
Saturday, November 24, 2007 4:45:19 PM (GMT Standard Time, UTC+00:00)
I wonder if this book (http://www.manning.com/foord/) would be more appropriate for people coming from .Net / C# and willing to use IRONpython... have not read it myself, though...
Saturday, November 24, 2007 4:54:25 PM (GMT Standard Time, UTC+00:00)
Also (sorry for comment spam today :-)) the basic flow control and loops of Python are covered in this serie of tutorials at IBM: http://www.ibm.com/developerworks/views/opensource/libraryview.jsp?search_by=discover+python

chapter 5 and 6:
http://www.ibm.com/developerworks/library/os-python5/index.html
http://www.ibm.com/developerworks/library/os-python6/index.html
Saturday, November 24, 2007 5:34:53 PM (GMT Standard Time, UTC+00:00)
Curt,
Since I already had Python 2.4 on my machine, I just followed the directions in the IronPython tutorial and ran

sys.path.append(r"C:\python24\lib")

I still appreciate the suggestion. Thanks.
Saturday, November 24, 2007 6:14:17 PM (GMT Standard Time, UTC+00:00)
Another alternate python learning source
How to Think Like a Computer Scientist: Learning with Python-Online book
http://www.ibiblio.org/obp/thinkCSpy/

Amit C
Saturday, November 24, 2007 10:07:08 PM (GMT Standard Time, UTC+00:00)
No one yet seems to have responded directly to your question. I am a C# programmer, and would be very interested in your proposed tutorials on C# --> Iron Python.
David Grigg
Sunday, November 25, 2007 12:22:52 AM (GMT Standard Time, UTC+00:00)
I am would be interested in Python for C# developers. Last year I tried learning python using Dive into Python, but due to the same reasons you mentioned here I am not able to proceed further on that. Also I tried to learn Python by writing code, that also didn't work well. After that I lost interest in Python. Now I am looking to give another shot at learning Python again. Do you have any suggestions ?
Saravanan
Sunday, November 25, 2007 7:41:24 AM (GMT Standard Time, UTC+00:00)
Python list comprehensions can be compared to C# 3.0's query comprehensions.

Python: methodList = [method for method in dir(object) if callable(getattr(object, method))]
C#: var methodList = from method in obj.GetType().GetMembers() where method is MethodInfo select method;

Of course, in C# you can go ahead and just type "var methodList = obj.GetType().GetMethods()"
Sunday, November 25, 2007 9:34:18 AM (GMT Standard Time, UTC+00:00)
Count me as interested.
Sunday, November 25, 2007 9:54:55 AM (GMT Standard Time, UTC+00:00)
I'd strongly recommend learning python against the standard cpython implementation rather than IronPython. The free Idle editor is perfectly good, although Eclipse with PyDev plugin will give you more intellisense-type functionality.

Python programming requires a slightly different mindset to C#/Java/C++ programming. There are quite a few concepts that don't translate directly (the 'everything is an object' idea will be much more natural to advanced javascript programmers than advanced java programmers, for example). Therefore I'd recommend working with cpython, finishing 'Dive into Python', then doing the Python tutorial at http://docs.python.org/tut/, writing a few little apps of your own, and THEN deciding whether a 'Python for C# developers' would be useful.

Python isn't *difficult* (in fact, if you were learning as your first language, it'd be much easier than C#) but it requires a fair bit of practice to stop thinking about it in terms of C#/java/whatever. I guess it's like learning another spoken language. You don't become really fluent until you're able to *think* in that language rather than constantly trying to translate from your mother tongue.
Carlos
Sunday, November 25, 2007 7:01:09 PM (GMT Standard Time, UTC+00:00)
I am one of the authors of "IronPython in Action". The first six chapters are already available via the Manning Early Access Program. http://www.manning.com/foord

It is intended to be read by C# programmers who have not used Python before (plus Python programmers who have not used .NET before). Chapter 2 is a Python tutorial and the next few chapters go through creating an example application which explores more of Python and the .NET framework.

I realise the book was already mentioned in one of the comments, but I thought Iwould emphasise that the book is specifically intended to help people in your situation. :-)
Sunday, November 25, 2007 7:02:58 PM (GMT Standard Time, UTC+00:00)
Oh - and list comprehensions are most like LINQ over objects. It would be nice to see the rest of LINQ in IronPython.
Monday, November 26, 2007 2:27:47 PM (GMT Standard Time, UTC+00:00)
well, I can think of one C# programmer I have working here that would probably be interested, but I will probably give him some stuff to do it before you are in a position to do your tutorials.

bryan
Thursday, November 29, 2007 6:16:42 AM (GMT Standard Time, UTC+00:00)
I started thinking about a wiki to translate similar concepts/method calls in different programming languages when I was learning Lisp a while back. While I don't have Python there because it's not one of my languages, anyone who wants to can add it.

It's still in progress but the skeleton is already down.
http://pt.strafenet.com

Still working on it--anyone who wants is free to write in it.
Tuesday, December 4, 2007 7:51:27 PM (GMT Standard Time, UTC+00:00)
I am definitely interested.
Comments are closed.