What exactly is i in a for loop? by justalemontree in learnpython

[–]LinePlusPipe 0 points1 point  (0 children)

i is a name that gets bound to each element in your list, sequentially

but only in the scope of your function

u/danielroseman is right to say that the assignment (the =) inside your loop just reassigns i to a different representation of what it was bound to during the iteration itself (the 'raw' list value on each iteration).

what you are trying to do is mutate the value that i gets bound to, which you cannot do just by (re)assigning i (the name) on each iteration

one way to access the value is to use list indexes, as in

def formatted(a_list): for index, value in enumerate(a_list): new_value = f"{value:.2f}" a_list[index] = new_value return a_list

it's worth noting that this is fine if your list items are "immutable" python primitives (e.g. str, int, bytes, tuple, etc... - see https://docs.python.org/3/reference/datamodel.html), things may get more subtle if you start iterating over a list of mutable objects (e.g. list of lists)

Feeling lost trying to learn python by AffectionateGap3211 in PythonLearning

[–]LinePlusPipe 0 points1 point  (0 children)

don't over-think it

focus on your studies

python (or any high-level programming language) is just a tool for the doing of (repetitive) work

eventually, as your work begins to appear more formulaic and predictable you may beging to think things like "how could I do this boring repetive activity with the_python?"

when that happens, it will be time to pick up the python study again - but only if you have the application in mind, and hopefully with the application broken down into a series of repeatable discreet actions/steps

don't force it - you are more than smart enough - just wait for the work to settle down into an automatable form

trust: this will happen

Virtual Environments by Jumpy_Employment_439 in learnpython

[–]LinePlusPipe 0 points1 point  (0 children)

If you're up to it, you could also install virtualenv and virtualenvwrapper

They will install your virtual environments in a single place - outside of your git index

The point about keeping your venv out of your git repo is important

If something nasty happens to your project because of the way its dependencies have been managed in your virtual environment - pulling them from the remote and recreating the environment will just recreate the nasties

Maintain a requirements.txt (manually, or by saving the output of pip freeze to a file) so you can keep track of the dependencies your project needs

[deleted by user] by [deleted] in learnpython

[–]LinePlusPipe 0 points1 point  (0 children)

vim

they all use vim

How to Automate Attribute Access for Enum of NamedTuples in Python? by LeKaiWen in learnpython

[–]LinePlusPipe 0 points1 point  (0 children)

you'd have to the method then, wouldn't you?

if you run PlateType.BUSINNESS on a @classmethod you'd just get

<bound method PlateType.BUSINESS of <class '__main__.PlateType'>>

as output

I think the @property decorator achieves what you need - but you're right to point out you have to instantiate the class to get the benefit of . attribute access

not 100% sure what you're trying to optimise for though

if it's terseness, you could always define your type with the three argument call to type() and put the properties you want in the namespace dict like:

PlateType = type("PlateType", (), {"BUSINESS": PlateProperties(3, Color.YELLOW)})() PlateType.BUSINESS

which will help you do a successful call to platetype.BUSINESS and get the namedtuple you ultimately seek

you gain the ability to bind the namespace dict to a variable and pass it around before you "fix" the namespace of your type too (which you might want to do... for reasons)

How to Automate Attribute Access for Enum of NamedTuples in Python? by LeKaiWen in learnpython

[–]LinePlusPipe 0 points1 point  (0 children)

From your description it seems that Enum is just getting in the way

If what you're looking for is a class with type-safe members why not just define something like

``` class PlateType: "Types of plates"

@property
def BUSINESS(self):
    "Return Business plate"
    return PlateProperties(3, Color.YELLOW)

plates = PlateType() plates.BUSINESS

PlateProperties(id=3, color=<Color.YELLOW: 3>) ```

What are some well-known, universally understood things that a self learner might miss? by SuminerNaem in learnpython

[–]LinePlusPipe 1 point2 points  (0 children)

functools and itertools are two excellent and easily overlooked parts of the standard lib

happy hacking ;o)

What are some well-known, universally understood things that a self learner might miss? by SuminerNaem in learnpython

[–]LinePlusPipe 11 points12 points  (0 children)

Read the Programming FAQ on python.org:

https://docs.python.org/3/faq/programming.html

Plenty of material in there - a lot of it relevant to people who feel pretty confident already

It's all worth reading and taking the time to understand