Beginner looking for beautiful and instructional Python code [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
As a complete beginner with no programming experience, I am trying to find beautiful Python code to study and play with. Please answer by pointing to a website, a book or some software project.
I have the following criterias:
complete code listings (working, hackable code)
beautiful code (highly readable, simple but effective)
instructional for the beginner (yes, hand-holding is needed)
I've tried learning how to program for too long now, never gotten to the point where the rubber hits the road. My main agenda is best spelled out by Nat Friedman's "How to become a hacker".
I'm aware of O'Reilly's "Beautiful Code", but think of it as too advanced and confusing for a beginner.

Buy Programming Collective Intelligence. Great book of interesting AI algorithms based on mining data and all of the examples are in very easy to read Python.
The other great book is Text Processing in Python

Read the Python libraries themselves. They're working, hackable, elegant, and instructional. Some is simple, some is complex.
Best of all, you got it when you downloaded Python itself. It's in your Python library directory. Nothing more to do except start poking around.

Just do it.
Seriously, you're never going to learn to be a good programmer until you write some programs. First you'll write bad programs, then you'll fix them, then you'll write better ones, etc...
If you aren't insatiably motivated to try coding, then maybe it isn't for you. One way to get motivated is to get a job that requires you to code... for me, there's nothing like having my salary and pride on the line to get me working :)

The Python project itself maintains a nice list of beginner's guides.

Beautiful is so hard to define, there's no real answer to this question. Your best advice to follow what Nat says in the post you linked:
Download the source code to the program you want to change
Untar it on your hard drive
Get it to build and run
Open the source code in an editor
Find the part of the code that you need to change to make the program do what you want it to do
Make the changes you need to make to the code and test it to make sure it works
Run the diff -u command and email the output to the mailing list
There is no point looking for beautiful code. Just look at and fix bugs in projects that you use (Django & Twisted might be good candidates).

I've seen How to Think Like a Computer Scientist recommended in many blogs.

I personally think that reading good code won't work until you have a firm understanding of the language, especially of its idioms. First, I recommend the basic Wikibook "Non-Programmer's Tutorial for Python" to start out. If most of that makes sense, you have a good understanding of the basics already.
After that, I recommend Dive into Python. You'll see a lot of other people recommending this book, because it's comprehensive and free. You'll learn a lot of language specific idioms in Dive into Python, especially in the first few chapters. As you're reading it, try to do basic programs using the techniques Mark Pilgrim shows.
Dive into Python gets into specific modules later in the book. That will probably get a little boring, and when it does, you might want to look at code. I don't feel qualified to rank the code used by these, but Django and Deluge are both bigger projects that will show you the organization of large programs. Though they will probably be overwhelming unless you take the time to really attack them one piece at a time and get a firm understanding.

I've learned quite a bit of beautiful and useful Python from O'Reilly's Python Cookbook. http://oreilly.com/catalog/9780596001674/
I've also learned much from ActiveState's Python Recipe's web page. http://code.activestate.com/recipes/langs/python/

I'd recommend you review Exaile music player for linux. It includes a lot of practically useful things like plugins, lambda, decorators, settings manager, gui (using GTK+) and much more.
Exaile source code is not an ideal but will give you enough helpful information and basic Python coding concepts.

Related

How to study python to take part in GSoC?

I'm new to python. I have learnt the basics from learnpythonthehardway.org/book and now I'm unable to understand the codes and libraries method of my favorite projects on github.
What should I do now in step by step manner so that I become capable enough to contribute and hence take part in GSoC no matter how much time it takes?
Some says I should practise python questions on hackerrank and other says I should work on my own project and learn from it. Which should I follow?
If you are just trying to learn Python I know YouTube has a lot of fantastic resources. Since you've already read Learn Python the Hard Way, I would suggest you look for YouTube videos where the host is creating a project (Look for something which interests you), and follow along until you come across something you don't know. Research it, rinse and repeat. As a bonus, you'll end up with some neat Python projects in the end, too.
Another great way to get some Python experience is to find different sources of tutorials. I learned Python from Codecademy, but there are plenty out there.
However, all said, there is simply nothing like figuring things out yourself. Set a goal - think of a project to create - and get as far as you can, and look for as many opportunities to learn as possible. That's my favorite way to learn.
Good luck! :)
As mentioned by #Dylan, YouTube hosts a lot of Python tutorials which are helpful for learning more about Python.
Additionally, I would invest your time in reading some eBooks. They have a wealth of knowledge that can expand your horizons beyond learning the basics of Python and personally I found it to be a huge help in understanding the language. Read these and take some good notes.
Python Cookbook (Second or Third Edition) by David Beazley
Automate
the Boring Stuff With Python by Al Sweigart
A Byte of Python by
Swaroop C.H.
Test-Driven Development with Python by Henry Percival
Real Python for the Web by Michael Herman
Good luck and happy coding!
I use C/C++ language to develop monitor and control software for hardware device for many years. Recently I started to learn Python for some reasons, so I also wondering which way is the best way to study a new language. My learning materials are two books, Learning Python and Programming Python. I think the language's foundational concepts are really important. As my experience in C/C++, the most frequent book I use in my work is the first one I studied in University, as that book focused on the foundational concepts. So I think the most important thing is understanding the foundational concepts,and the best way is typing it and test it by your hand, not only seeing the example.

Once I know the basic elements and syntax of Python, what should I do?

Well, I have read several user guides and watched dozens and dozens of video tutorials on how to program with Python, and feel pretty confident about writing simple applications for it. My main point in my question is, where would I be able to learn more advanced programming knowledge about Python?
How simple of applications are you making? Have you gone through the exercises in Google's Python Class? I highly recommend going through those. If you really know what you are doing, you should breeze through them. If not, then you'll be learning some valuable skills and becoming a little more experienced in Python.
After that, it depends on what your end goals are with Python. If you don't have any goals then you should work on setting some goals and making some small applications to develop your skills in the areas that go well with those goals.
Also, a good way to learn more about Python is to try to answer the questions posted on here about Python. Even if you don't find the best answer, reading other people's answers will help you as well as the process of trying to find the answer.
You could try something like Python Cookbook or Python Challenge.
But your question is a little too vague. Why did you learn Python? What kind of problems are you looking at solving? Based on the answer to that, I can direct you to various modules like os, sys, Tkinter, etc
You have given yourself an answer:
and feel pretty confident about
writing simple applications for it
go ahead and write more complex applications!
The issue here is that you do not feel challenged, and you assume that you are done with your basic learning. Just find what to do! Simplify a process (say, file management), retrieve data from Internet (say, the last 25 twitter posts about Python), consolidate your mail clients into a single command line application, etc.
The MOST productive thing you could do (assuming you really don't have problems of your own), is to find an open source Python project (say, Matplotlib) and become a contributor. You will quickly realize that Python is beautiful, but it is a beast nevertheless.
If you still feel unchallenged, contact me and I will send you a ton of stuff to code which, believe me, is not easy.
Good luck!
my favorite way in learning python is ( learning through projects ).
put yourself a goal , like a software for example ( 6 years ago when i started to learn python i picked a messenger . so i had to read more about sockets, network programming , and interfaces libraries ) . start with it , look for examples and resources to learn more . then do it.
the key is NOT TO GIVE UP and keep trying and searching until you make it .
. this can be fastest and the most efficient way in learning any programming language .
good luck ;)
If you like puzzles, you might check out Project Euler. It has a variety of interesting puzzles (some easy, some much harder) that take some logic and programming to solve. (Often you have to find a clever way to solve them, since brute-force methods will take forever.)
If you're at all interested in web development you might look into Django. It's a very nice web framework that lets you use Python; it's mature and quite powerful.
I also second Arrieta's suggestion of finding an open-source Python project and looking into getting involved. You can find a list of such projects on GitHub, freshmeat, and SourceForge, among others.

General questions regarding Python language

I'm a newbie to programming and I've decided to start with Python. Just curious though, is it enough/recommended to learn Python from online tutorials or from books? I want to go further than simple "Hello World!" programs. I'm not sure if books will actually teach you how to make more advanced programs.
One example is Exif-py. How do you even start programming a program like this? Do you just sit down and start writing the code, or do you have to search for APIs or anything? I went through the code briefly and it all looked alien to me.
I'm not really sure how to express my questions into words, so do check back because I'll edit my question if the right words come to me.
Well, I learnt all my Python from online sources (not just tutorials, but reference documentation, blog posts and other texts). It's certainly possible, although some people prefer the "guided" way a book teaches you, particularly people new to programming (at that point I had already been programming for years).
To create a program such as Exif.py, you would first have to know what you must do in broad terms BEFORE starting to program. You would study the EXIF format, then figure out how that is put into the image files, then you would have to formulate that in terms of the language you're using (in this case, Python). This usually requires that you're already familiar with it, otherwise it'll be a fairly slow process.
I'd suggest starting with simpler programs to begin with, or maybe follow a book such as Dive Into Python (free online), seeing as you're new to programming, and need to not only learn the language, but to think like a programmer.
The tutorials are there to teach you the language syntax and the standard library, not really on how to solve a particular programming problem. Think of what you learn there as your toolbox.
I think I understand what you are saying. You want to break above and beyond the simple applications and write your own stuff, right? Well, first you need to figure out what it is you want to make. Then comes the hard part; how are you going to make it? I'd suggest starting by trying to break it down into a number of small simple problems instead of tackling it as one large problem.
If you are trying to find examples of larger projects, I'd suggest looking at the Python Cheeseshop (package index) and download a few packages you've heard of to see how they did it. Also, people often post handy pieces of code on their personal blogs and that shows up on PlanetPython.
If stuff like recursion, modules, classes, iteration, exceptions, dictionaries, are indeed new to you, I suggest How to Think Like a Computer Scientist in Python (lovingly abbreviated as ThinkCSPy in the community ;-).
It is a bit outdated - for best results, use Python 2.6 or lower, but then again 3.0 is not that different.
EDIT: If ThinkCSPy has little to teach you, try Dive Into Python. It's advanced and pretty "real-world", but step-by-step.
If by 'newbie to programming' you mean that you just started it last week or something along the lines, then maybe you might want to give the MIT OpenCourseWare Introduction to Computer Science videos (and homework!) a bit of your time.
The opencourse covers the syntax of the Python language, some helpful hints and general do's and don'ts that apply to any programming paradigm.
Though, if by 'newbie to programming', that you already know the basic concepts you need to start writing basic programs (like adding, subtracting, multiplying, logical operations, functions etc).
If so, Project Euler is particularly good for exercising that cranial muscle in problem solving via programming, though most of the problems on the site require you at also have knowledge of mathematics (and if you don't, at least know how to google).
Just remember, if you get stuck on anything don't get put down! It's all part of learning! If you're really stuck, search SO!
There are a few very good online resources:
The Python Tutorial.
Dive Into Python. Python from novice to pro.
Code Like a Pythonista: Idiomatic Python
Another list of resources: Essential Python Reading List.
Most Python books I've seen so far are "not that good" - but that depends
on your background / prior knowledge about Python and programming.
You study the EXIF format, study the GIF/JPEG format, open the binary file, scan it and get the data out.

How to reverse engineer a program which has no documentation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a source of python program which doesn't have any documentation or comments.
I did tried twice to understand it but most of the times I am losing my track, because there are many files.
What should be the steps to understand that program fully and quickly.
Michael Feathers' "Working Effectively with Legacy Code" is a superb starting point for such endeavors -- not particularly language-dependent (his examples are in several non-python languages, but the techniques and mindset DO extend pretty well to Python and just about any other language).
The key focus is, that you want to understand the code for a reason -- modifying it and/or porting it. So, instrumenting the legacy code -- with batteries and scaffolding of tests and tracing/logging -- is the crucial path on the long, hard slog to understanding and modifying safely and responsibly.
Feathers suggests heuristics and techniques for where to focus your efforts and how to get started when the code is a total mess (hence "legacy") - no docs, or misleading docs (describing something quite different, maybe in subtle ways, from what the code actually DOES), no tests, an untestable-without-refactoring tangle of spaghetti dependencies. This may seem an extreme case but anybody who's spent a long-ish career in programming knows it's actually more common than anyone would like;-).
In past I have used 'Python call graph' to understand the source structure
Use a debugger e.g. pdb to wak thru
the code.
Try to read code again after one day
break, that also helps
I would recommend to generate some documentation with epydoc http://epydoc.sourceforge.net/ . For sure, if no docstring exists, the result will be poor but it will give you at least one view of your application and you'lle be able to navigate in the classes more easily.
Then you can try to document by yourself when you understand something new and then regenerate the docs again. It is never too late to start something.
I hope it helps
You are lucky it's in Python which is easy to read. But it is of course possible to write tricky hard to understand code in Python as well.
The steps are:
Run the software and learn to use it, and understand it's features at least a little bit.
Read though the tests, if any.
Read through the code.
When you encounter code you don't understand, put a debug break there, and step through the code, looking at what it does.
If there aren't any tests, or the test coverage is low, write tests to increase the test coverage. It's a good way to learn the system.
Repeat until you feel you have a vague grip on the code. A vague grip is all you need if you are going to manage the code. You'll get a good grip once you start actually working with the code. For a big system that can take years, so don't try to understand it all first.
There are tools that can help you. As Stephen C says, an IDE is a good idea. I'll explain why:
Many editors analyses the code. This typically gives you code completion, but more importantly in this case, it makes it possible to just just ctrl-click on a variable to see where it comes from. This really speeds things up when you want to understand otehr peoples code.
Also, you need to learn a debugger. You will, in tricky parts of the code, have to step through them in a debugger to see what the code actually do. Pythons pdb works, but many IDE's have integrated debuggers, which make debugging easier.
That's it. Good luck.
I have had to do a lot of this in my job. What works for me may be different to what works for you, but I'll share my experience.
I start by trying to identify the data structures being used and draw diagrams showing the relationships between them. Not necessarily something formal like UML, but a sketch on paper which you understand which allows you to see the overall structure of the data being manipulated by the program. Only once I have some view of the data structures being used do I start to try to understand how the data is being manipulated.
Secondly, for a large body of software, sometimes you need to just attack bite sized pieces at first. You won't get an overall understanding straight away, but if you understand small parts in detail and keep chipping away, eventually all the pieces fall together.
I combine these two approaches, switching between them when I am getting overly frustrated or bored. Regular walks around the block are recommended :) I find this gets me good results in the end.
Good luck!
pyreverse from Logilab and PyNSource from Andy Bulka are helpful too for UML diagram generation.
I'd start with a good python IDE. See the answers for this question.
Enterprise Architect by Sparx Systems is very good at processing a source directory and generating class diagrams. It is not free, but very reasonably priced for what you get. (I am not associated with this company in any way, I've just been a satisfied user of their product for several years.)

Contributing to Python

I'm a pretty inexperienced programmer (can make tk apps, text processing, sort of understand oop), but Python is so awesome that I would like to help the community. What's the best way for a beginner to contribute?
Add to the docs. it is downright crappy
Help out other users on the dev and user mailing lists.
TEST PYTHON. bugs in programming languages are real bad. And I have seen someone discover atleast 1 bug in python
Frequent the #python channel on irc.freenode.net
Build something cool in Python and share it with others. Small values of cool are still cool. Not everyone gets to write epic, world-changing software.
Every problem solved well using Python is a way of showing how cool Python is.
I guess one way would be to help with documentation (translation, updating), until you are aware enough about the language. Also following the devs and users mail groups would give you a pretty good idea of what is being done and needs to be done by the community.
I see two ways of going about it: working on Python directly or working on something that utilizes Python
Since you're a beginner, you're probably hesitant to work on the core Python language or feel that you can't contribute in a meaningful way, which is understandable. However, as a beginner, you're in a good position to help improve documentation and other items that are essential to learning Python.
For example, the Python tutorial is less of a tutorial (in the standard sense) and more of a feature listing, at least in my opinion. When I tried to learn from it, I never got the feeling that I was building up my knowledge, like creating an application. It felt more like I was being shown all the parts that make up Python but not how to put them together into a cohesive structure.
Once I became more comfortable with the language (mostly through books and lots of practice), I eventually wrote my own tutorial, trying to provide not only the technical information but also lessons learned and "newbie gotchas".
Alternatively, you can contribute to the Python world by using Python in programs. You can contribute to projects already established, e.g. Django, PyGame, etc., or you can make your own program to "scratch an itch". Either way, you not only build your knowledge of Python but you are giving back to the community.
Finally, you can become an advocate of Python, encouraging others to learn the language. I kept suggesting to my supervisor at my last job to use Python rather than Java when a considering what to use for a new project. I tell everyone I know about the joys of Python and encourage them to give it a try. I convinced the administrator of a computer forum I frequent to create a section for Python. And, as I already said, I wrote a tutorial for Python and I'm working on a new one for wxPython.
There are many ways you can contribute to Python that aren't necessarily programming related. As your programming skills grow, you may want to move further into code contributions. But you may gain more satisfaction by helping others find the same joy you found in Python.
If you aren't up to actually working on the Python core, there are still many ways to contribute.. 2 that immediately come to mind is:
work on documentation.. it can ALWAYS be improved. Take your favorite modules and check out the documentation and add where you can.
Reporting descriptive bugs is very helpful to the development process.
Get involved with the community: http://www.python.org/dev/
Start by contributing to a Python project that you use and enjoy. This can be as simple as answering questions on the mailing list or IRC channel, offering to help with documentation and test writing or fixing bugs.

Categories

Resources