67 Posted Topics

Member Avatar for henryford
Member Avatar for kumar86

You don't have to open Notepad or use extra modules to write and save a text file. It's all built in. [CODE] # Opens a file called Hello.txt for writing. f = open("Hello.txt", "w") #Filename #Mode # Write the text to the file. f.write("Hello world!") # Close the file f.close() …

Member Avatar for kumar86
0
108
Member Avatar for suntom

Instead of using If to handle errors you need to use the Try and Except statement. Here is your code using those. [CODE]import getpass, smtplib gname = raw_input("Username: ") gpass = getpass.getpass("Password: ") try: #Try to execute the code between try: and except: server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() server.ehlo() server.login(gname,gpass) …

Member Avatar for richieking
0
1K
Member Avatar for DocBreen

Whitespace is your friend! Try adding this to your code. [CODE]correct = 0 #Letters correct is zero right now for letter in hangword: #For every letter in the word they're trying to guess if guess == letter: #If their guess is equal to that letter correct += 1 #Add one …

Member Avatar for TrustyTony
0
113
Member Avatar for WildBamaBoy

I'm coming from Python to Visual Basic and it's really playing with my head. This program is intended to scan a list of directories (only have one directory so far) and see if they contain any files. If they do, their directory is added to a list (DirtyFolders) and all …

Member Avatar for WildBamaBoy
0
107
Member Avatar for dustbunny000

Perhaps not the best way to do it, but maybe something like this? [CODE]import random tries = 0 keys='abcdefghijklmnopqrstuvwxyz ' key = random.choice(keys) while key != "m": #While key is not equal to 'm' tries += 1 #Add one to tries key = random.choice(keys) #Choose another key if key == …

Member Avatar for D33wakar
0
168
Member Avatar for WildBamaBoy

I'm attempting to write a game server and I need it to continue on with the code while listening for a connection. I know this is done with the threading module but I don't know how exactly to do this. Python documentation didn't work for me. [CODE] #[LISTENER] print "Initializing …

Member Avatar for lrh9
0
174
Member Avatar for WildBamaBoy

I don't really know how to word what I want to ask so please bear with me. I'm making a program that will start up a game server written in Java and read the outputs and edit the packets so that I can modify this game. It will read outputs …

Member Avatar for WildBamaBoy
0
81
Member Avatar for WildBamaBoy

In this program I have a lot of game directories in a list like so: [CODE]base = "C:/Program Files/Game" expansion = "C:/Program Files/Game/Expansion" Games = [(base, "Base Game"),(expansion, "Expansion 1")] Installed = [][/CODE] The program then sees if they are installed like this: [CODE]for path, name in Games: #For every …

Member Avatar for WildBamaBoy
0
117
Member Avatar for WildBamaBoy

How do I get the same result from this Python script in Visual Basic? [CODE=Python] import os username = os.getenv("USERNAME") desktop = "C:\\Documents and Settings\\%s\\Desktop\\" % username print desktop #Result = C:\Documents and Settings\<MY USERNAME>\Desktop\ [/CODE] I already have this, [CODE] Public Shared username As String = My.User.Name 'Gives computer …

Member Avatar for vb5prgrmr
0
142
Member Avatar for WildBamaBoy

I just learned about dictionaries in Python and tried to implement them into a program I developed. The folders in the dictionary absolutely MUST be created in the listed order. But if for whatever reason they cannot be created, I want the name I specify to be printed instead of …

Member Avatar for TrustyTony
0
113
Member Avatar for WildBamaBoy

In the code below I have a class that handles what folder the user is in, so they can browse through multiple folders. I know that this isn't going to work right just yet. This is the first time I've tried using classes and I don't understand them so well. …

Member Avatar for WildBamaBoy
0
113
Member Avatar for WildBamaBoy

I cannot get shutil to copy one folder to another. This code results in the error below. What am I doing wrong? [CODE]if os.path.exists(backup + "\\Safety Backup"): pass else: print "Backing up original music. . ." os.mkdir(backup + "\\Safety Backup") for folder in musicFolders: shutil.copy2("C:\ABCD123", backup + "\\Safety Backup") print …

Member Avatar for WildBamaBoy
0
20K
Member Avatar for WildBamaBoy

Does anyone here know how to use the UnRAR2 module? [URL="http://code.google.com/p/py-unrar2/downloads/list"]http://code.google.com/p/py-unrar2/downloads/list[/URL] I can't for the life of me I can't figure out how get it to do the same thing that zipfile does in a project I am working on. I want it to look for all files of a …

Member Avatar for Beat_Slayer
0
264
Member Avatar for WildBamaBoy

How do you make Python distinguish from files and folders if they are dragged and dropped into the program's window? [CODE] import os import string newDrag = raw_input("Drag and drop the file or folder you want to add.\n") newStrip = newDrag.strip('"') #Removes the quotes Windows randomly adds for some reason …

Member Avatar for WildBamaBoy
0
142
Member Avatar for WildBamaBoy

This is a section of a program I made that keeps track of some money I'm saving. :cool: When I enter how much I want to add it saves what I enter to a file and updates the current amount I have saved, also in the file. When I enter …

Member Avatar for WildBamaBoy
0
159
Member Avatar for WildBamaBoy

Hi, I'm writing a program that totals how long someone has worked by the starting time and the ending time. It DOES work if the times entered are both AM or PM. Like if they worked from 2:00 to 9:10, it tells me the right answer of 7 hours and …

Member Avatar for WildBamaBoy
0
2K

The End.