Ask coding questions

← Back to all posts
Using .txt files in python
CarlLiljencrant (9)

I've run in to a problem with my code. I'm trying to create a game for me and my friends just to have some fun togheter and challenge my self. The problem I've gotten is that for some reason my code can't write in .txt files and save that information if you're using the link to directly run the code: https://testing-accounts.carlliljencrant.repl.run and you can not write in the text file so that i can see it in the text file using this link either: https://repl.it/@CarlLiljencrant/testing-accounts Does someone have a solution to this?

Answered by a5rocks (834) [earned 5 cycles]
View Answer
Comments
hotnewtop
a5rocks (834)

You can get free MongoDB hosting (MongoDB Atlas), or you can use jsonstore (someone made a post on repl talk about jsonstore before)

Also, see if becoming an explorer can help. It may corrupt things, but I'm pretty sure they are testing out programmatic writing rn.

CarlLiljencrant (9)

@a5rocks I think I'm going with jsonstore, thanks to everyone!!

qualladoom (372)

Files which were made with code don't update on repl.it. suggest using an external datasystem like PostgreSQL.

CarlLiljencrant (9)

@enigma512 I've done some googleing and came across PostgreSQL, but can you use something inside repl.it?

qualladoom (372)

@CarlLiljencrant At the moment, I don't think so. EDIT: YOU APPARENTLY CAN
-_-

Lord_Poseidon (173)

Files made programmatically don't really update on repl.it. I'd suggest using an external database such as PostgreSQL or even google sheets API

CarlLiljencrant (9)

@Lord_Poseidon I've done some googleing and came across PostgreSQL, but can you use something inside repl.it? Can you use google sheets API in repl.it?

Lord_Poseidon (173)

@CarlLiljencrant You can use Google Sheets API on repl.it
use the package manager to install the module

Vandesm14 (2752)

@Lord_Poseidon Google Sheets API is great and all, but it is not particularly easy to set up. I recommend Airtable API, which uses a database-like format to store everything. https://airtable.com/api

CarlLiljencrant (9)

@Lord_Poseidon @Vandesm14 Do you have any websites or videos were i can learn about those things? I've tried but without any luck :[

OathOfCode (27)

You could use
a = append and add
w = write and replace.
file = open("Whatever you want.txt", "a")
file.write(whatever)
file.close()

I wasn't assigning variables!