Tutor FAQ Suggestions

This page is used to collect entries for the new tutor FAQ. Post complete article entries below, and we’ll move them to separate pages as soon as possible (using a script). Pages that have been moved will appear on this page.

Markdown Syntax #

The PyFAQ site uses a markup syntax called “markdown” for both articles and comments.

To make an entry heading, start the line with “##” (e.g. ## title). E.g.

## How do I reverse a string ?

The easiest way to ...

    s = s[::-1]
    s = reversed(s)

For more on this, see <http://someurl>, where Guido writes:

> The slice syntax ...

As shown in the example, code snippets should be indented with four spaces, block quotes should be prefixed with > characters (just like in mail), paragraphs separated with at least one empty line, and URL:s enclosed in angle brackets.

For more on markdown syntax, see this page. If you want to experiment, you can use the markdown dingus demo site (but note that you can edit your comments if you make mistakes, so you can “experiment in place” if you prefer).

Ideas #

Here are some ideas for new entries, taken from posts by Mike Hansen and Ed Singleton.

  • How do I name an object based on user input?
  • How do I get an attribute of an object by name
  • How do I read the output from a program called via os.system()
  • Changing elements in a mutable object changes the object for all references

  • ord and chr

  • parsing html beautifulsoup
  • editors/ides
  • getters and setters
  • regex match and find
  • matrix operations
  • how do I make an exe out of a python script
  • books
  • what should I program?
  • unicode/encoding

If you have more ideas, post them below.

 

Comment:

##How much code should I post? Post as much relevant code as you can in your message to python tutor. However, the consensus seems to be that the more code you post, the less likely you'll get someone to review it. A max of 100 lines is suggested. If you have more code, you might post your code at [http://www.rafb.net/paste](http://www.rafb.net/paste) or a similar site and refer to it in your message to python tutor.

Posted by infogami

Comment:

##How do I dynamically name my objects? How do I name my objects based on user input? Rather than performing voodoo by dynamically creating variables, your best bet is to use a dictionary with the keys being the name of the object or user input.

Posted by infogami

Comment:

##Why doesn't my special method add, init, or cmp.. work? Remember to use two underscores before and after the method name `__add__, __init__, __cmp__`...

Posted by infogami

A Django site. rendered by a django application. hosted by webfaction.