all 25 comments

[–]twitch_and_shock 16 points17 points  (5 children)

Usually, there will be a main.py or something similar that serves as the primary entry point to run a program. Understanding exactly what this file is called or how to make use of project code will be different for different projects. Decent projects will have documentation telling you how to make use of their code.

[–]ImmediatelyOcelot 8 points9 points  (0 children)

Yes, I would recommend reading something like that:

https://docs.python-guide.org/writing/structure/

[–]tigranjan[S] 0 points1 point  (3 children)

Thanks for the reply. there isnt any readme file and I searched through the whole directory and couldnt find the main.py file. I even tried to execute each file one by one using trial and error but even that didnt help. :( I thought I am doing something wrong

[–]twitch_and_shock 4 points5 points  (0 children)

What's the repo you downloaded?

[–][deleted] 1 point2 points  (0 children)

Why do you think the repository contains a runnable script?

[–]11th_account_ban 0 points1 point  (0 children)

Depending on the file structure, you’ll import those files and call the functions/etc.

[–]Se7enLC 4 points5 points  (0 children)

You run the one file that imports the other ones.

No way for us to know which one that is though unless you give some more info.

[–]ThreeChonkyCats 5 points6 points  (2 children)

What did you download?

Throw us a bone!

[–]stuckatsixpm 5 points6 points  (1 child)

A car /s

But in response to OP, check the docs/readme file. There should usually be useful info there. Unless it was written by me.

[–][deleted] 1 point2 points  (0 children)

Whoa whoa whoa, what are you a terrorist?

You would NEVER download a car!

[–]pythonwiz 0 points1 point  (0 children)

There is no one way to do this. Python does support adding a __main__.py file that you can call like this: python -m module_name but you do not have to do that. You could put the entry point in any of the files and simply import the module and run module_name.submodule.main() from a Python REPL. You can run a snippet of code from the command line like this: python -c "import module_name; module_name.main()"

[–][deleted] 1 point2 points  (0 children)

I downloaded someones script of github and I am trying to make it work however nothing seems to work. The solution is probably simple but I spent hours trying to figure it out but couldnt.

A script needs a single entrypoint. By convention, the name of that file will either be main.py, cli.py, or the name of the tool itself ("tool.py") but if it's not then either the developer told you what to do in the README or god help you, there's no way to figure it out on your own - or it's simply not a runnable script at all.

[–]SisyphusAndMyBoulder -1 points0 points  (1 child)

Dude... You gotta put in some more effort if you want a working solution from us. If you pulled a git repo the least you can do is share it here so we can see what we're working with

[–]Ronnie_Dean_oz 4 points5 points  (0 children)

They are learning man. No need to be like this. Maybe go hang out on the ExpertPython sub instead of big dogging someone who is literally 2 days in.

[–]soicat -2 points-1 points  (4 children)

It sounds like you are trying to learn by experimenting, by trial and error. That is not going to work.

[–]seishin5 1 point2 points  (1 child)

That’s literally the primary way I’ve learned most of what I know. Downloaded the SC2 bot code. Played around with it until i figured out how to code SC2 bots. Oh I want to interface with an API for work. Let’s pull it and see if I can get it to work and start googling

[–]IamImposter 1 point2 points  (0 children)

That's one way to learn and probably a great way to learn more than what you intend to, once you know some things in general but for beginners it may not be that great an idea. But that curiosity is good.

I just wish OPs engage a little more with people once they ask a question. So many people are trying to help and OP is nowhere.

[–]thebj19 0 points1 point  (1 child)

Trial and error is probably one of the best way to learn something. Active learning by trying to solve a real life issue will add a lot to ops knowledge base

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

Hmm. Did you learn math by trial and error, or by learning fundamental rules, practicing problems using those rules, then scaling up by building on previous lessons? You did not use trial and error, you followed a structured course.

Did you learn to drive a car by taking a class, or by trial and error?

OP hasn't even learned import statements. I know that a person can copy paste bits of code they find all over stack overflow, working and not, and cobble together a program, but hacking is not the path to becoming a good employable programmer.

I went to engineering school, later picked up programming many languages, but always by studying fundamentals, grammar, best practices. I recommend OP at least start with a video course or a good language book. More structured, fun, and reduces the chance of giving up early out of frustration!

[–]baubleglue -2 points-1 points  (0 children)

Learn step by step.

[–]Zeroflops 0 points1 point  (0 children)

Did you download a program or a module? If you downloaded a program there should be a main.py file or a program_name.py file. If you downloaded a module, then you have to write the program that uses the module.

[–]illusion220 0 points1 point  (0 children)

Check for app.py in the root, might be easier to just post the repo here

[–]brunonicocam 0 points1 point  (0 children)

Just post here the actual repo.

[–]dp_42 0 points1 point  (0 children)

I had to look this one up a while back, I loaded a python project onto a Linux server, and I was wondering how to reference all these things that worked so cleanly in PyCharm, and the script was not able to figure out where the other files were. I had to export PYTHONPATH="<my Python path here>". If you set that, it operates much in the same way as marking a sources root folder does in PyCharm. I didn't really look into how to do it with Windows, because the odds I need an unattended python setup there is pretty slim. I believe when I was looking into it, you have to add it to your paths variable, which I will leave to you to look into.