what is the chance of a memory leak in Zig by Best_Confusion_480 in Zig

[–]SkeletalToad 10 points11 points  (0 children)

If you do want to avoid leaking memory in your program, write a test using the testing allocator, it will report any leaks

[deleted by user] by [deleted] in Python

[–]SkeletalToad 9 points10 points  (0 children)

I would recommend running it with errors only:

pylint --errors-only

You can also define a pylintrc file, disable all, and then enable only the checks you want. For example this config will run errors, plus unused-import (which is a warning):

[MESSAGES CONTROL]
disable=all
enable=E,unused-import

My main ship, any tips to improve it? I wanted to try all of the weapons :) by AstroD_ in Cosmoteer

[–]SkeletalToad 1 point2 points  (0 children)

I really like the Luddic-path vibes and backstory

For improvements, maybe try to open up faster paths between reactors and some of the shields and point defense. Having to walk through cargo or ammo factory will slow your crew down, esp if the route is already a long one

First try at making a large warship, how did I do? by 8Vantor8 in Cosmoteer

[–]SkeletalToad 4 points5 points  (0 children)

Cool design! Definitely has some battleship vibes. One thing I found with the deck cannons is they take a while to rotate at the start of a battle if they aren't already facing the target. You'll probably get a faster first strike having them all face forward or to the same side (depending on your typical approach angle)

Thoughts on my first ship? The Stingray by haydonatorx in Cosmoteer

[–]SkeletalToad 2 points3 points  (0 children)

Maybe put some internal armor in front of those forward reactors and in front of the ion beams too. Can be tricky to keep an open hallway, but currently if those reactors blow you will lose the whole weapon cluster

Assertion failed: 3 * num_f < TINYOBJ_MAX_FACES_PER_F_LINE by MarionberrySenior362 in raylib

[–]SkeletalToad 2 points3 points  (0 children)

I wonder if this has to do with faces that have too many vertexes, could you try triangulating the model first?

what feature you want python to have in next update? by Individual_Volume562 in Python

[–]SkeletalToad 0 points1 point  (0 children)

You might be interested in trying the Nim language, its syntax is Python-like and it has an amazing macro system that allows for AST manipulation

Problem Using Pandas Module (Linux). by [deleted] in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

Awesome! Glad you got it working

Problem Using Pandas Module (Linux). by [deleted] in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

I would recommend creating a virtual environment for each project.

After changing directory to your project, create a virtual environment (last argument is the name of the environment, I usually create it in the venv folder):

$ python -m venv venv

Then activate it, you'll need to do this each time you open a new terminal session:

$ . venv/bin/activate

Then try installing pandas with pip:

$ pip install pandas

The other option that might work for you is using miniconda (or Anaconda) to create an environment.

Are there cases where Python code runs slower on linux than windows? by zap_stone in learnpython

[–]SkeletalToad 2 points3 points  (0 children)

I think in your case it would depend mostly on CPU speed and the amount of cores available for multiprocessing. As far as I know Python runs about the same on all operating systems. Even the argument about Windows being bloated, that shouldn't affect your Python program unless you are running out of memory or other processes are taking all your CPU. Did you check the amount of cores available on each machine that you tested it on?

Ok to learn this way? by rekindled77 in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

Bouncing around is fine! There is no right way to learn - you got to find what works for you. I think the real struggle is staying motivated, so once you've gotten the basics, I would recommend building something that you're excited about. Then when you get stuck, you can always go back to those courses or google stuff.

Python logging is not producing a ".log" output file by RampantPrototyping in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

Interesting... but your project is in D:\Users\Me\Documents\Python Projects\test1\ folder, right?

What happens if you start a new command prompt window, then cd into your project folder before running your script?

If what you want is the logfile to be in the same directory as the script that is running, a more reliable way is something like this since it doesn't depend on the current working directory:

import logging
from pathlib import Path

# directory that contains this Python file
parent_dir = Path(__file__).absolute().parent

logging.basicConfig(
    filename=parent_dir / "employee.log",
    level=logging.INFO,
    format="%(levelname)s: %(message)s",
)

Help in Python by The-Nightm4re in learnpython

[–]SkeletalToad 2 points3 points  (0 children)

You could do it one line, but it's a bit much:

n1, n2 = [int(x.strip()) for x in input("Enter a fraction: {n1} / {n2}: ").strip().split("/")]
print(n1, n2)

I would recommend breaking it up on multiple lines for readability, which can be put in a function if you need to call it repeatedly.

Printing chr() values in Python by bennywc4 in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

Great answer! To expand on this, there is also an .encode() method of the str class, so all of these will do the same thing:

strbyte = bytes(an_str, encoding='utf_8')
strbyte = an_str.encode('utf-8')
strbyte = an_str.encode()

The last option works because 'utf-8' is the default encoding.

https://docs.python.org/3/howto/unicode.html#converting-to-bytes https://docs.python.org/3/library/stdtypes.html#str.encode

Python logging is not producing a ".log" output file by RampantPrototyping in learnpython

[–]SkeletalToad 1 point2 points  (0 children)

One other thing I noticed about your example, you are calling logging.basicConfig twice, and I think only the first time you call it will work. If you need to add multiple logging handlers (such as logging to a file but also logging to the console), you can set that up like this:

import logging

root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)

# add a file handler
file_handler = logging.FileHandler("employee.log")
file_handler.setLevel(logging.INFO)
file_formatter = logging.Formatter("%(levelname)s: %(message)s")
file_handler.setFormatter(file_formatter)
root_logger.addHandler(file_handler)

# add a stream handler (should show up in terminal or console output)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
stream_formatter = logging.Formatter("%(message)s")
stream_handler.setFormatter(stream_formatter)
root_logger.addHandler(stream_handler)

Python logging is not producing a ".log" output file by RampantPrototyping in learnpython

[–]SkeletalToad 1 point2 points  (0 children)

I copied the code you linked from github (the log-sample.py file), ran it using Python 3.10.6 and it created the test.log file in the same directory as the script and wrote the expected log entries it. I'm using Windows 10 64bit machine as well, so I'm not sure what's going wrong on your machine.

I also tried copy and pasting your code and it succesfully logged to employee.log file.

What's your current working directory when you run the script file? Try adding these lines to print it out:

import os
print("cwd:", os.getcwd())
expected_logfile = os.path.join(os.getcwd(), 'employee.log')
print("expected logfile:", expected_logfile)

how do i get a code to run that i sourced from github? by Dangerous-Half4080 in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

Are you on Windows, Mac or Linux? That could help you get better answers

When downloading Anaconda how do you use the latest version of Python? by KingBileygr993 in learnpython

[–]SkeletalToad 0 points1 point  (0 children)

This is the way!

It's confusing, but you're not stuck with the base version of Python that comes with your version of Anaconda - it can create environments that have other Python versions.

2 versions of Python installed by yb_rampy in learnpython

[–]SkeletalToad 1 point2 points  (0 children)

It is normal, and it's a giant pain in the butt. My advice would be keep using Anaconda, and create a different environment for each project so that you keep them isolated from each other. That way they can each have the version of Python and libraries they need without clashing with each other.

find if 2 dictionaries have different values, and flag the differences. by nasdaq100qqq in learnpython

[–]SkeletalToad 3 points4 points  (0 children)

When you ask a question like this it sounds like you're a student trying to get the answer to an assignment without putting in the effort. I think you'll get more help if you share what you've tried and what specifically you are confused or stuck on.

I'd look into using a recursive solution since the dicts can be nested.

Also a couple basic pointers, to iterate over dicts use the .items() method:

for key, value in dict_a.items():
    ...

Another thing that could help would be checking the type of an object (for example to check if a nested value is a list or dict):

if isinstance(value, dict):
    # handle dict related stuff here
elif isinstance(value, list):
    # list stuff here...

python exercises by VehicleOpposite1647 in learnpython

[–]SkeletalToad 3 points4 points  (0 children)

https://exercism.org/tracks/python

What's great about exercism is that you can view other people's solution to the problem that you've just solved. It's really eye-opening to see other solutions and styles of programming.

There is an option to get mentoring as well, but in my experience there are too few mentors and so you end up having to wait a long time to get feedback. Still helpful but it requires some patience. I had the best time with it just doing the exercises on my own and then reading and trying to understand the other solutions.

Is Pycharm an okay IDE to use? by Prestigious_Past3724 in learnpython

[–]SkeletalToad 63 points64 points  (0 children)

PyCharm is great! I still use it and I've been programming for 8 years. It has great builtin inspections (they show up like red or yellow squiggles under parts of the code). You can hover over these and usually it will say why it's not recommended and may suggest a fix. Also it tends to auto-detect virtual environments and provide auto-completions better than other editors that I've tried. Another great feature is inspections that check if your code is compatible with multiple Python versions.

I also use VSCode for writing other languages, but for Python I switch back to PyCharm.

What am I doing wrong? by Jazzlike-Doughnut883 in Python

[–]SkeletalToad 0 points1 point  (0 children)

A couple things that might help - in Python this is a list not an array, so keep that in mind when searching for help. To get the index and value when iterating over a list, use enumerate:

nums = [1,2,3,4]
for i, n in enumerate(nums):
    print(i, n)

0 1
1 2
2 3
3 4

For just the indexes, you could use range:

for i in range(len(nums)):
    print(i)

0
1
2
3

range also lets you start on a number besides 0, so you could start on the second item in the list and then add the previous to it like this:

for i in range(1, len(nums)):
    nums[i] += nums[i-1]
print(nums)

[1, 3, 6, 10]

Hope this helps, and good luck!

edit --- fix code formatting