How can I run current file other than main file when I click “run” button.
Just click the ⋮ next to “Files” then click “Show hidden files”. Next click on the
.replit file and finally you can change the
run if you’re not using an interpreted language) to whatever file you want to run.
Also see the docs on how to configure a Repl: https://docs.replit.com/programming-ide/configuring-repl
I want to execute the current file every time I click run, instead of modifying the executed file every time.please give an example.
The thing about Replit is instead of creating new files for every program you want to make, you should just create new Repls. So you only have one file you want to run in each Repl. So I recommend just not trying to do this, as it’s a lot of extra effort.
@UMARismyname might know how to do this though, as I think I’ve seen him answer a question similar to this.
Well, somebody did post a hack for it. You might need to search the forum.
I would say … just use the shell instead. I know it is not the same, but still using the shell is good exercise
I know shell can do so.But it is difficult to write code every time
I know. I did put out as requested feature that the ide would actually work like any offline ide (run runs the file being edited) but it did not get any vote.
That’s what I was talking about here:
I vote! Everyone here is doing programs. This matter is not difficult to achieve at all, and I don’t know what the author thinks?
One way is rather than using run button, you can use the shell
There are such commands for all languages
This will just run the provided file.
Don’t you think this is troublesome?
Not if you use Replit right.
You should only ever have to run one file in a Repl, so there’s no need to do this. When using Replit, you should create a new Repl for every program you want to run.
I just realized I’m repeating what I said earlier, lol:
There may be multiple files in a project, such as a module project. In a module, sometimes you just want to test one file in the module, and this requirement is frequent. Why don’t you give the user a setting? Let them choose to run the current file or start with the main Swift file?
All I can say is use the Shell, then. You can copy and paste it.
Ctrl + Shift + V isn’t so much worse than Ctrl + Enter
Do note, we don’t work for Replit. We are just volunteers that want to help others.
There is another advantage in using the shell, at least in the paid plans, your code will run faster
For my monorepls I personally use a
build.sh file which takes an argument for which folder to run, so instead of the actual command, I’ll run e.g.
make may be more suitable depending on what you’re doing.
I’ve done a hack for this for C/++ and Python, but I probably won’t have the time for Swift (check my status…)
One possible solution that i can think of for python is to put all of the code you made into a single function (or several depending on if you made several functions in the other file for that code to run with) and to import the function in to the main.py file. and call the function in the main.py file.
If you have a file called sub.py, put the code in sub.py into a function, then go to main.py.
type “from sub import *”
then call the function you made in sub.py
Thank you, It’s too troublesome to type the code every time.I already find solution, The reason I can not import a class in other file is, according to the mechanism in replit, all files wanted to use must write into parameters in compile command in setting file .replit like this impulse = [ “swiftc” “-o”” main” “main.swift”, “other file.swift”]
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.