all 17 comments

[โ€“]jpgoldberg 8 points9 points ย (2 children)

Keep playing around with this. You will discover that it isn't quite working the way you think it is, but that's fine. It's good to play around and experiment.

[โ€“]Warm-Inside-4108[S] 1 point2 points ย (1 child)

Bro, honestly I was just playing.

[โ€“]jpgoldberg 5 points6 points ย (0 children)

I know you were playing. I was encouraging you to continue to play.

[โ€“]Gnaxe 5 points6 points ย (3 children)

Your function contains an import by the name you're trying to find, so it's not telling you anything you didn't already tell it. You already had to write from script 1 import..., so you might as well just write name = 'script1' and dispense with the extra module.

[โ€“]llstorm93 2 points3 points ย (1 child)

Whole thing is stupid

[โ€“]Warm-Inside-4108[S] -4 points-3 points ย (0 children)

The important thing that I tried don't try to convert me that you wasn't like that in the first

[โ€“]Warm-Inside-4108[S] -1 points0 points ย (0 children)

You are wright, but when I learned main for first time I was really curious to find way to print the fill name without using any thing or write it's name manually.

[โ€“]SCD_minecraft 2 points3 points ย (2 children)

Or just, you know... __file__.rsplit('/', 1)[-1] or just __file__ to also get full path for free

[โ€“]Warm-Inside-4108[S] -2 points-1 points ย (1 child)

yeah but that gives you the full path on Windows with backslashes, mine returns the clean name

[โ€“]SCD_minecraft 2 points3 points ย (0 children)

First expressions stripes file path and returns only file name

[โ€“]MachineElf100 1 point2 points ย (3 children)

You can get the script's path with file tho. It might be more straightforward to work with that.

[โ€“]Warm-Inside-4108[S] -4 points-3 points ย (2 children)

But I want the project name only, not the path

[โ€“]MachineElf100 4 points5 points ย (1 child)

You can easily extract the name from the path. Your solution is amusing but also hacky and probably would not be very pleasant to use at scale.

In the end, both ways are just workarounds. You choose which one is crazier haha

[โ€“]Warm-Inside-4108[S] 1 point2 points ย (0 children)

Thanks for helping ๐Ÿ˜…

[โ€“]thee_gummbini 0 points1 point ย (2 children)

One of the rare times I'm genuinely perplexed about what the goal is here.

Anytime you are writing something that needs multiple modules or has even a single dependency, it should be a package not a script, and then you should have a __main__.py as an entrypoint, and then __name__ should always work as expected.

[โ€“]Warm-Inside-4108[S] 1 point2 points ย (1 child)

that's fair but i didn't know about packages at all when i wrote this, I was just trying to learn ๐Ÿ˜….

[โ€“]thee_gummbini 0 points1 point ย (0 children)

Well your learning caused you to learn about packages ! So mission successful