ihatehippies 11

Do you have a file named DailyExpenses.py in the same folder. It is case sensitive.

ihatehippies 11

try raw_input instead of input

ihatehippies 11

On second thought. Is there any reason your methods have to be methods and can't be functions. Why do they need to be inside a class? Are you trying not to pollute the namespace?

ihatehippies 11

So you have to create a unique file name with incremental values starting at 1. First thing you gotta do it separate the file from the folder. os.path is going to be your friend for this one

[CODE=python]
from os import path

get the absolute path

file_path = path.abspath(file_path)

splits the filename from the folder

folder, filename = path.split(file_path)
[/CODE]

then you have to separate the file name from its extension

[CODE=python]
name, ext = path.splitext(filename)[/CODE]

then you have to start your loop that checks for a file's existance

[CODE=python]
n = 0
while exists(file_path):
n += 1
file_path = '%s(%s)%s' % (path.join(folder, name), n, ext)
return path.abspath(file_path)
[/CODE]

ihatehippies 11

To get you started
[CODE]
pw = ''
while len(pw) < 6:
pw = raw_input('Please enter a password at least 6 characters long\n')
if len(pw) < 6:
print('The password needs to be 6 characters long, not (%s)'%len(pw))
raw_input('Good Job!!!!!')[/CODE]

ihatehippies 11

Then just copy the contents of the Unduplicate function (without the return statement) and change the variable names.

[CODE=python]
names = open("Names.txt", 'rU')
for name in names:
name = ' '.join([x for x in name.split(' ') if x])
s = name.split(",")
newNames=s[1].strip() +" "+ s[0].strip()
print newNames[/CODE]

ihatehippies 11

strip removes those characters from the left and right sides of the string. If the character occurs in the middle of the string it will have no effect on it. This is what I use to remove duplicate characters from a string
[CODE=python]
def Unduplicate(string, chars):
for char in chars:
string = char.join([x for x in string.split(char) if x])
return string
[/CODE]

your new code would look like

[CODE=python]
names = open("Names.txt", 'rU')
for name in names:

chr(32) is a space
name = Unduplicate(name, chr(32))
s = name.split(",")
newNames=s[1].strip() +" "+ s[0].strip()
print newNames[/CODE]

ihatehippies 11

You just have to describe the format to python. You are looking for 3 items separated by a comma. The third item is a digit and the second item is a 3 letter month.

*Note: Code is untested
[CODE]
print "You chose to add a new birthday"
with open('birthdays.txt', 'r') as readobj:
filedata = readobj.read()
months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
newLine = raw_input("Enter the name and birthday: ")
try:
name, month, day = [x.strip(' \t\n') for x in newLine.split(',')]
assert day.isdigit()
assert month.lower() in months
with open('birthdays.txt', 'a') as writeobj:
writeobj.write(newLine + '\n')
except (AssertionError, ValueError):
print 'Enter the information in Name, MM, DD format'
[/CODE]

Also seek(0) doesn't work with the file opened in append mode. It always adds it to the end of the file.

TrustyTony commented: Nice short post +13

ihatehippies 11

look into time.strftime (string format time)

[CODE=python]
import time
time.strftime("%a %m/%d/%y @ %H:%M:%S", time.localtime())[/CODE]
returns 'Mon 01/23/12 @ 17:38:22'

if you only wanted the time portion just do

[CODE=python]
time.strftime("%H:%M:%S", time.localtime())[/CODE]

here is a reference for the meaning of each letter

[URL="http://strftime.org/"]http://strftime.org/[/URL]

BustACode commented: Good stuff. +1

ihatehippies 11

I don't understand completely what you're trying to do so this might not be helpful at all, but I feel bad cuz no one's tried to give you an answer.

you would need to make another class to save the attribute 'contents'

[CODE=python]
class container(object):
pass

class CustomError(Exception):
def init(self):
self.historical = container()
self.historical.contents=[]
print "Stack Created"[/CODE]

*untested code

ihatehippies 11

I made a keylogger/screen capture app a little while ago. PyHook did all the heavy lifting. [URL="http://pypi.python.org/pypi/pyHook/1.4/"]http://pypi.python.org/pypi/pyHook/1.4/[/URL]

ihatehippies 11

to find the letter that occurs the most you can do:
[CODE=python]
File = open("path", "rb")
txt = File.read()
File.close()

mode = max(txt, key=txt.count)[/CODE]