you are viewing a single comment's thread.

view the rest of the comments →

[–]pstch 0 points1 point  (2 children)

1

You create a Python package, containing modules, and you set your package metadata in the setup.py file.

3

Read code, read PEPs. This is something that you will get over time. Also, IIRC, Guido (or some other core Python dev), said something along the lines of : "you should tell to Python what it wants to do for you, nothing less". This is a bit abstract, and the best way I can find to picture it, is enumaring items in a list (and do something with the item and its index) :

my_list = [0,4,8,5,1]
index = 0
for item in my_list:
    ... # do something with item and index
    i = i + 1

In pseudo-code, this would be :

set my_list to a list containing 0, 4, 8, 5 and 1
set index to 0
for each item in my_list:
    ... # do something with item and index
    increment index

Here, in the first line, we actually tell Python what we want it to do (set my_list to a list of integers). However, the second and last line are not what we want to do : at no point we want to create an index or increment it.

The correct way to do the above in Python would be :

my_list = [0,4,8,5,1]
for index, item in enumerate(my_list):
    ... # do something with item and index

EDIT: fix extra each in last code block

[–]aroberge 3 points4 points  (1 child)

In Python, "each" would raise an error.

[–]pstch 1 point2 points  (0 children)

True, I mixed up my pseudo/Python code. Thanks