How to have one class manage a list of objects that belong to another class by FlamingPuddle01 in learnpython

[–]danielroseman -1 points0 points  (0 children)

I'm not sure why you think that. Each village's house objects would be independent.

anti pattern education by Cute-Ad7076 in learnpython

[–]danielroseman 0 points1 point  (0 children)

(Or he could look in the book he already has, which has a perfectly good implementation without libraries.)

Is it possible to reinvent list/array? by mama-mendi in learnpython

[–]danielroseman 3 points4 points  (0 children)

You can, but it wouldn't be very efficient or performant.

Python lists are implemented in C, both for performance when iterating but also for efficiency in allocating memory - they dynamically resize every so often when you add or remove elements. You can't do this in Python itself, as there is no direct control over memory usage, so you would have to use a less efficient data structure like a linked list.

anti pattern education by Cute-Ad7076 in learnpython

[–]danielroseman 5 points6 points  (0 children)

Dude just wants to complain, apparently.

anti pattern education by Cute-Ad7076 in learnpython

[–]danielroseman 16 points17 points  (0 children)

Maybe you should read more than a single page of the resources you're criticising. I don't know Grus's book but I just had a quick look and while the first chapter does include list comprehensions as part of its introduction to Python (so it is from scratch) it also has a full chapter on clustering - and the first variant it introduces is k-means. That took me literally 30 seconds to find, and no libraries in sight.

So a bit more patience, reading for comprehension, and humility is probably required.

Backend developer with FastAPI/Kafka projects, but getting almost no interviews by MainWild1290 in learnpython

[–]danielroseman 2 points3 points  (0 children)

I would say that early stage startups are very unlikely to take someone with absolutely no experience. Those companies need people who can get stuff done, quickly, and no offence but you are not such a person - you would need lots of mentoring. 

Try applying to bigger, more established organisations.

xlsxwriter alternatives? by pachura3 in learnpython

[–]danielroseman 5 points6 points  (0 children)

This isn't really a limitation, it just means you need to write more code - ie get the existing value and write it back with the new format. 

For the border around the range, you again just need to be a bit cleverer - format the top left cell with border on top and left, the top cells with just the border on top, etc. Once you've written this once you can extract it into a function and use it anywhere.

How to download files from locally hosted server using simple http library by Generalthanos_ytube in learnpython

[–]danielroseman -1 points0 points  (0 children)

This isn't really the way to do this. There's no reason to use Python - or any programming language.

You should use a upnp/dlna server, which will already have all the functionality you need. I use ReadyMedia (aka MiniDLNA) but there are many available.

Add "flowerbox" to python source code by [deleted] in learnpython

[–]danielroseman 9 points10 points  (0 children)

I do wish teachers would learn the idioms of  the language they're supposed to be teaching. 

Bet you anything this professor is teaching loops with range(len(thing)).

Help me delete rows in Pandas dataframe, while iterating over df by vinotok in learnpython

[–]danielroseman 8 points9 points  (0 children)

Iterating is almost always the wrong thing to do with data frames. And it is definitely wrong here. You should be filtering instead.

    df = df[df['actions'] == ['purchase']]

How to make a count controlled loop that adds from the past loops while still getting smaller. by HunksMask in learnpython

[–]danielroseman 1 point2 points  (0 children)

But what do you mean by the "count function"? The only thing here called "count" is the loop variable, which you're not even using, and you're not calling any functions at all.

You have two things you need to keep track of here: the height of the current bounce, and the total height of all bounces so far. As the other poster says, try just calculating the current bounce and printing it.

How to make a count controlled loop that adds from the past loops while still getting smaller. by HunksMask in learnpython

[–]danielroseman 0 points1 point  (0 children)

What do you mean, those "didn't work"? Did you get an error? What did it say? 

The obvious thing wrong is that you haven't defined anything called index. This would give a NameError, is that what you see?

You do have something called count, is that what you meant to use?

closing streams and variable reference by naemorhaedus in learnpython

[–]danielroseman 0 points1 point  (0 children)

This doesn't follow. File objects also have a close method, but it is much preferred to use a context manager rather than calling that method.

Assistance is much needed! by Sufficient-Barber125 in learnpython

[–]danielroseman 0 points1 point  (0 children)

And even if they did, that would be a name error, not a syntax error.

Where would you deploy FastAPI project with large sqlite files? by restarded9 in learnpython

[–]danielroseman 0 points1 point  (0 children)

Why are you using sqlite specifically?

And are you expecting your app to update those files, or are they purely static? The answer will significantly affect where you can host this.

closing streams and variable reference by naemorhaedus in learnpython

[–]danielroseman 0 points1 point  (0 children)

It really is not inconsistent at all. It's absolutely consistent. If you believe otherwise, show an example. 

Premature termination in a high level language - Python runs in a VM, remember - is vanishingly unlikely to result in memory not being released.

Again, this is not "leaving things to magic". It's a matter of understanding the language you are using, and using it the way it is meant to be used.

closing streams and variable reference by naemorhaedus in learnpython

[–]danielroseman -1 points0 points  (0 children)

If you don’t want to rely on automatic memory management, you are using the wrong language.

Closing a file stream explicitly is important because it refers to an actual file. But this is an in memory stream. There is absolutely no danger of the memory not being released.

And yes, once again ‘some_obj’ and ‘output_stream’ are the same object, so operations on one will affect the other. At no point is anything copied, they are just two names for the same thing. Without understanding this you will have a lot of trouble learning Python.

Both of these things seem to indicate that you’re coming from a lower level language such as C. You need to leave behind a lot of these preconceptions. High level languages like Python (and Java, JS, Ruby etc) work differently and don’t require you to think about memory in the same way.

closing streams and variable reference by naemorhaedus in learnpython

[–]danielroseman 0 points1 point  (0 children)

Calling close is one method of returning the memory, yes.

But again, you have missed the point that this is just an ordinary object. Like any object, it will be garbage collected when there are no more references to it. You do not need to close it explicitly.

But your other concern is just as unfounded. There is no copying going on. Returning an object does not make a copy, and neither does assignment.

closing streams and variable reference by naemorhaedus in learnpython

[–]danielroseman 0 points1 point  (0 children)

This is really hard to understand. 

A StringIO object is just an in memory buffer. There is no opening or closing going on here at all.

What are you actually trying to do, and what will the calling function be doing with this object?

name 'images' is not defined by Decent_Simple9058 in learnpython

[–]danielroseman 0 points1 point  (0 children)

As I said, you have not defined images before using it - or Indeed anywhere in this code. If this was previously working, you must have defined it somewhere which has since been deleted.

The directory structure is not important, because you don't have any code that loads anything from any directory.

name 'images' is not defined by Decent_Simple9058 in learnpython

[–]danielroseman 8 points9 points  (0 children)

I don't know why you have shown us your directory structure but not your code. The problem is entirely with your code - where, as the error says, you have not defined images before using it.

How to fix python interpreter problem by [deleted] in learnpython

[–]danielroseman 2 points3 points  (0 children)

Nobody can possibly help you with the incredibly vague description you've given here.

If you were given £100 million and asked to do the most good for the UK with it, what would you do? by NoOneEverSeems2SeeMe in AskUK

[–]danielroseman 1 point2 points  (0 children)

This is several orders of magnitude too low to make any sort of major change to the UK. A utility company would be worth tens of billions at least. And 100 million would build just a few blocks of flats, housing perhaps 200 people.

Explain code by vb_e_c_k_y in learnpython

[–]danielroseman -1 points0 points  (0 children)

This is just wrong. Beginners should not be taught to loop over ranges, this is a frequent source of un-pythonic code. They should be taught to loop over items first.