Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:13:17+00:00 2026-06-16T05:13:17+00:00

As a small project I created a small chatroom. The code follows, may I

  • 0

As a small project I created a small chatroom. The code follows, may I point out that I am new to programming so the structure may not be efficient:

import re, time
user_name = 0
password = 0
chatroom = 0

from users import users
def startup():
      global user_name, password, chatroom
      print "\n" * 100
      user_name = raw_input("Your username: ").upper()
      if users.has_key(str(user_name).lower()) == True:
            password = str(raw_input("Password: "))
            while str(users[user_name.lower()]) != str(password):
                  print "Incorrect password."
                  time.sleep(2)
                  startup()
            else:
                  chatroom = raw_input("Room name: ").lower()
                  chat()
      else:
            print "Invalid username."
            time.sleep(2)
            startup()

def showchat():
      global user_name
      file = open(str(chatroom) + ".txt","r+")
      messages = str(file.read()[-700:])
      file.close
      messages = messages.rstrip('\n')
      print "\n" * 40
      print messages
      print "------ type 'r' to refresh the screen ------"

def writechat():
      global user_name, chatroom
      n = raw_input("________________________________________________________" + "\n" + user_name + ": ")      
      if user_name.lower() == 'admin':
            if n == "clear":
                  file = open(str(chatroom) + ".txt","w")
                  file.write("")
                  file.close
            elif n == "addnewuser":
                  x = "'" + raw_input("new username: ") + "'"
                  y = "'" + raw_input("new password: ") + "'"
                  file = open("users.py","r").read()
                  file = file.replace("'username' : 'password',", x + " : " + y + "," + "'username' : 'password',")
                  open("users.py","w").write(file)
            elif n == "r":
                  chat()
            elif n == "logout":
                  startup()
            else:
                  file = open(str(chatroom) + ".txt","a")
                  file.write(user_name + ": " + str(n) + "\n")
                  file.close()
      else:
            if n == "r":
                  chat()
            elif n == "changepassword":
                  file = open("users.py","r")
                  file.read()
                  oldpass = raw_input("New password: ")
                  users[user_name.lower()] = oldpass
                  print users
                  file.close()
                  file = open("users.py","w")
                  file.write("users = " + str(users))         #here
                  file.close()
            elif n == "logout":
                  startup()
            else:
                  file = open(str(chatroom) + ".txt","a")
                  file.write(user_name + ": " + str(n) + "\n")
                  file.close()

def chat():
      showchat()
      writechat()
      chat()


startup()

This code works perfectly fine in python as long as a chatroom.txt file exists as well as users.py.
The problem occurs once I convert it to .exe, it works fine except that the users.py file does not get written permanently (it does temporarily) when it should, the relevant coding is marked #here.

my setup code is as follows:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe' : {
'packages': ['users'],
"bundle_files" : 2,
}},
    console = [{'script': "chatroom.py"}],
    zipfile = None,
)

users.py is simply just a dictionary of (user:password):

users = {
'admin' : '2588619',
'john' : '1234',
'username' : 'password',
}

so how do I convert it to .exe and make it so users.py gets written permanently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:13:19+00:00Added an answer on June 16, 2026 at 5:13 am

    The package created by py2exe is simply an auto-extracting archive that contains a python interpreter and your program. Everytime the .exe is run everything inside gets extracted in a temporary directory and the program is run by the extracted interpreter.
    This means that what you’re trying to achieve is simply not possible if you put users.py together with the source code.

    You should create a users.py file in some user directory, for example:

    users = open(os.path.join(os.path.expanduser('~'), '_MyProgram', 'users.py'))
    

    Obviously you should also make sure that this directory exists, and eventually create it.

    This can be done automatically by py2exe passing the data_files parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get a small project to do on scoring system. I found out that
I have a small project that I was using node-dirty for, but it's not
I'm working on small open source project for developed Windows. I created new project
I've inherited a small project. The person before me created a native app for
In my small project I'm using System.Reflection classes to produce executable code. I need
I have a small project that I will be working on shortly that collects
I have a small flash project. I created a SWF from the flash sources.
I am using Eclipse with WindowsBuilder. I have created a small simple project to
recently I started a small Django project that I developed on a local machine
I have created a simply Pizza program (for a summer project not education related)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.