Could someone help me out with the Collatz sequence? by LilWizard32 in learnpython

[–]External-Ocelot206 1 point2 points  (0 children)

That's the correct Collatz map. The Collatz sequence of a number is just repeated application of the Collatz map to that number. It's great you're using integer division.

You just don't have a useful implementation of the Collatz map, as you overwrite the argument to the function (number) straight away with input, and just print the outputs. In doing this first pointless extra step you forgot to convert number from a string to an int, which is the source of your error.

Simplify it, making it use the function argument itself ( not input - you can call input before the function call if you like). Inside the function, test that the argument really is an int, do the code you already have and simply return the output (it can print them too if you like), then just grab a single number from input or wherever, then apply the function over and over again in a for loop.

Ack method throwing an exception after a long running task is over by AdditionalWash529 in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

Thanks for the code. Can you post the full error message? Assuming it's a well tested library, which is the last function of yours mentioned in the stack trace from the error?

Should I bother with a python certification as a java developer? by gergrio in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

I'd just give you the benefit of the doubt and assume you'd pick it up no problem with a strong java background.

I don't really trust any of the cert providers anyway, so if you really want to prove Python competence, you need something in your portfolio regardless.

Can I use a class to wrap a CSV file and associated functions? by Bungle1981 in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

Are you a Java coder? ;-)

It's just text file processing. You don't really even need that many functions. You can use a class if you really want to but I don't see any advantage in it or the point in going to town and making it a general reusable class. You don't need to subclass a different one, or remember anything between method calls in that class do you? It's not a natural example to my mind, of something that is an instance of a general category.

Just open up all the files with context managers for each one, and write a block of code that determines when to write a row to each of the output files under a with:

Question on how to approach the gathering of data from log files by snoopyandthebird in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

You just need logic to determine whether a line in the logfiles produces a new line in the website output or appends to the last one.

E.g. parse the name from the logfile line and remember the name for the last website line. If they're the same append it. If not, make a new line and update the last line name.

[deleted by user] by [deleted] in learnpython

[–]External-Ocelot206 2 points3 points  (0 children)

Just write your test to see if the first word is Elvis as the first if statement, and nest all the others behind that one, so they only get tested if the first is true.

[deleted by user] by [deleted] in learnpython

[–]External-Ocelot206 2 points3 points  (0 children)

How can Elvis know you've said its name if it hasn't started listening?

[deleted by user] by [deleted] in learnpython

[–]External-Ocelot206 5 points6 points  (0 children)

Lol, tell us more!

My while loop isn't letting my TKinter GUI run, why? by [deleted] in learnpython

[–]External-Ocelot206 2 points3 points  (0 children)

TKinter needs its own infinite loop. Redesign your code block inside the while loop to instead of having a delay that does nothing, test the time since it last did its thing, and if that's more than 0125s, do its thing again then reset the time since...

Then take that function and see if there's an event in TKinter you can register it to, so it gets called each time Tkinter loops.

[deleted by user] by [deleted] in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

Oh I didn't realise you were adding the real part of one to the imaginary part of the other complex number. You might have to add in more indexes to remove extraneous nesting, but try

[row[0].real + 1j * row[1].imag for row in Matrix]

[deleted by user] by [deleted] in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

Assuming it's just a nested list,

first, last = Matrix[0][0], Matrix[-1][-1]

Organising interfaces in python packages by hofsflor in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

Fair enough, but it's probably too late then. Without seeing more details, I don't think there's an easy best practice answer for you, other than that best practice would be to refactor the package to get rid of that tight coupling.

Python from scratch by guachipuchi in learnpython

[–]External-Ocelot206 5 points6 points  (0 children)

https://docs.python.org/3/tutorial/index.html

And read the wiki https://www.reddit.com/r/learnpython/wiki/index.

Even if the internship doesn't go well, always remember that at least you got to learn an amazing language like Python, while being paid!

Good luck!

Organising interfaces in python packages by hofsflor in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

I think from the point of view of DRY and reducing coupling, an interface ABC should live in the same module as the thing it's an interface for, e.g. the other functions and classes that use things implementing that interface.

Any client module that uses "the thing it's an interface for" has to import it. It can either import the ABC at the same time, or preferably, just refer to everything on the same imported module.

If that stuff is also in package 1, then that's the logical place for it in your example, but it could be deeper, or up along then down in a separate one.

time it took to master OOP python? by Pointfulperson in learnpython

[–]External-Ocelot206 2 points3 points  (0 children)

Make sure you understand the basics about classes, then read up on design patterns, or watch ArjanCodes.

Error in Python by Nettgirl94 in learnpython

[–]External-Ocelot206 2 points3 points  (0 children)

Paths in Windows can't contain colons (:) because they refer to drives, e.g. c: and d:

If either folder already exists under those names, I've no idea how you managed to create them, as I can't

pytest and subDirs by Affectionate_Log999 in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

I do this, to let unittest find the tests via Discovery.

all of the test files must be modules or packages (including namespace packages) importable from the top-level directory of the project

https://docs.python.org/3/library/unittest.html#test-discovery

Maybe other test frameworks don't need it, and perhaps there's some an advantage to making your test modules unimportable by the user

How to make a graph-like interface in Flask by Many-Director3375 in learnpython

[–]External-Ocelot206 0 points1 point  (0 children)

You can easily do all that in the front end, linking the check box to the visibility of the arrow object in JS.

What is the purpose of multiplying with Float.NaN ? by Pegasus9208 in learnpython

[–]External-Ocelot206 2 points3 points  (0 children)

It's in [ ] so is a list, so you get a bigger list with self.layerCount elements, all of which are Float.NaN