[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Any Python people around?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 4

File: python_sh-600x600.png (106KB, 600x600px) Image search: [Google]
python_sh-600x600.png
106KB, 600x600px
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.
>>
File: S9Nb7Rt.png (136KB, 1360x730px) Image search: [Google]
S9Nb7Rt.png
136KB, 1360x730px
>>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
>>
File: 1461813092964.jpg (45KB, 327x316px) Image search: [Google]
1461813092964.jpg
45KB, 327x316px
>>56362551

I have a 4bit processor here
Thread posts: 17
Thread images: 4


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.