I wrote a tic-tac-toe game in C++ (which is the only language I know anything about), and I'm trying to port it to Python since I'm taking a class on the latter. But I'm having trouble getting Python to clear out the window whenever I redraw the game board. Here's a glimpse at my primary loop in C++...for(;!gameOver;){
system("CLS");
drawBoard();
makeMove();
checkWin();
if (gameOver==1) break;
}
endGame();
I know that calling system() isn't a "good programming practice"; I'm just trying to make this thing work on MY PC and move on. Thing is, there's apparently no equivalent that works in IDLE. I don't really get all of the nuance of Python; I only know how to use it in IDLE.
What method should I be using to write/run my code, if not IDLE?
Is there a method that will give me a similar functionality to "CLS" in Python?
How to I turn my code into a file I can share with my friends?
Thanks in advance.
For the record, the game runs totally in a console window. The game board is printed with string literals and variables in std::cout. I'm using print() in python as a substitute.
>system("CLS")
Jesus fucking Christ. Smash your computer and switch majors to sports medicine
>for(;!gameover;)
Why not use a while loop?
The following works for calling programs from the Linux CLI, maybe it will work for Windows too.import subprocess
subprocess.call(["cls"])
>How to I turn my code into a file I can share with my friends?
Use something like p2exe or pyinstaller.
man ncurses
>>56361286
haha Like I said in the OP, I know that system("CLS") should be avoided at all costs.
I'm still a beginner in C++, and I'm just having fun making dumb little in-console games to show my friends. I'll be washing my hands of this system() shit once I get a little farther in my studies.
>>56361302
I think the source actually uses a while loop now. I was just using a for loop for a bit, so I typed that in the OP out of habit.
>>56361353
Ok, thanks, I'll check that stuff out.
>>56361353
Here's the error message that gives me. Should I be doing this in IDLE, or through some other method?
>>56361517
Your python installation is broken
>>56362025
uhh, no. "cls" is a builtin, not a separate executable.import os
os.system("cls")
if you gotta do it full retarded like that
There are numerous responses on stack overflow that pretty much all say you have to use os.system.
I don't like it, and there are several terminal escape character hacks, but if you want something that can trivially account for multiple OSs, it looks like we're stuck with the given solution.
>>56361517
>windows
>programming
pick one
>>56362076
Full retarded is exactly what I need. This is just for fun to see if I can make it happen; don't really care how disgusting things get.
If I run that in IDLE, it doesn't work and the CMD windows appears for just one frame. (So fast that no text is visible.) It interprets without errors, though.
After that, I tried navigating to the file in CMD and ran it that way. Worked like a charm. Once I convert my Python script to an executable with p2exe, will it run in a Windows console window? If so, looks like we've found a solution that'll work in the meantime.
>>56362362
You forgot "programming for Windows".
I recently found out that it actually IS possible! Hop in my Minecraft server and I'll explain the deets over game chat.
Oh, holy shit, you can execute .py files by double-clicking on them? Until now, I thought that would open them in IDLE to be edited.
Oh, wow. So many things make more sense now.
>>56361216
do it in 1 line faggot
>>56362551
I have a 4bit processor here