ihatehippies 11

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

ihatehippies 11

if you google "monitor changes to folder python" the first link that comes up is http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html
Pretty useful article

ihatehippies 11

try raw_input instead of input

ihatehippies 11

The code perfect for me. windows 7, python 2.7.2, wxpython
You can try updating wx or use the wx.CallAfter method which calls whatever you pass to it after the current event has finished processing. Maybe something like

def HideFrame(self, evt):

def Wait(self):
self.Show() [/CODE]

ihatehippies 11

I just dealt with this, asked for help in a post here but didn't get much help. It has to do with nat traversal which can be done from your computer. Hours of googling led me to uPnP. You have to forward public requests to your local (private) ip address. I've attached the files that I found and modified to suite my purposes. Here is the actual implementation of the code.

class Ports(object):
def init(self):

create a folder in c:\python2x\lib called uPnP
  # and extract the zip contents there
  from uPnP.natpunch import _upnp_
  self.ports = []
  self.uPnP = _upnp_

def open(self, *ports):
for port in ports:
if not port in self.ports:
print 'opening port', port
print 'retrying to open port', port

def closeall(self):
print 'closing ports %s' % (', '.join([str(x) for x in self.ports]))
self.ports = [p for p in self.ports if not self.uPnP.close(p)]

def del(self):

ports = Ports()

will go through the process of testing
the best method to open the router ports


should open port 15000
keep the 'ports' reference alive
otherwise it will close the ports
when it is garbage collected (the del method)


Also helpful was [URL="http://pypi.python.org/pypi/pystun"]pyStun[/URL] which allows to get easily get your public ip address programmatically.

ihatehippies 11

no problem

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

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)

then you have to separate the file name from its extension

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

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

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

ihatehippies 11

You didn't use the code sample I posted. Use self.args, not just args. When an instance of ProcessThread is created it saves the argument 'args' to itself. You can access it from the class by invoking 'self.args' anytime after the instance has been created. Or from outside the instance by
instance = ProcessThread(args)
print instance.args[/CODE]

ihatehippies 11

... you have to define args.
args = WhatArgsWasGoingToEqualInYourProgram

ihatehippies 11

I think you'll find that most people hate using globals. I would probaly add an argument to the init method to accept the args:
def init(self, args):
self.args = args[/CODE]
and then simply pass those saved arguments in your 'run' method.
def run(self):

Just pass the args to the thread when you create the instance
worker_thread = AVCThread(args)[/CODE]

ihatehippies 11


basically there are 2 ways to run a python file. Via command line interface or via python's built in IDLE. Python will be installed at c:\python27. At c:\python27\lib you will find python's standard library, a bunch of .py files that give the user python's famed functionality. If you right click any .py/.pyw file there will be an option to 'Edit with IDLE' which will bring up the the code editor. From there pressing f5 will run the 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
def Unduplicate(string, chars):
for char in chars:
string = char.join([x for x in string.split(char) if x])
return string

your new code would look like

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

it waits for the user to enter some text and press the enter key. It will work with IDLE and Console apps but not with programs that suppress the console window (ie .pyw and compiled wxpython apps that hide the console)

ihatehippies 11

instead of random.randint


guess = int((start+stop)/2)[/CODE]

reduces the amount of average guesses

ihatehippies 11

tested on python 2.7.2

import random

def guessing():
start = int(raw_input('enter the starting number\n'))
stop = int(raw_input('enter the ending number\n'))
while start < stop:
guess = random.randint(start, stop)
answer = ''
while answer not in ('higher', 'lower', 'equal'):
answer = raw_input('Is it higher, lower, or equal to %s\n'%guess)
if answer == 'higher':
start = guess+1
elif answer == 'lower':
stop = guess -1
guess = start
print ('The answer is: %s, thank you for playing'%guess)
return guess


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
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: ")
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'

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

Your code example calls 'close()' which normally works fine. The alternative is to call
socket.shutdown(). Here is a good post explaining the difference between the two.


ihatehippies 11

if you end up using threads make sure the threads exit. I've ran into that error a few times only to find an extra instance of python.exe running in the background because a thread never exited.

ihatehippies 11

my bad

[CODE=python]def isprime(num):
if num < 2: return False
elif num == 2: return True
for x in xrange(2,num-1):
if not num % x: return False
return True[/CODE]

as mentioned above '%' returns the remainder

6%3 = 2 remainder 0, so it returns 0
6%4 = 2 remainder 2, so it returns 2

the function goes through the numbers between 2 and the number-1 and checks to see if any number is perfectly divisible.

ihatehippies 11

[CODE=python]def isprime(num):
for x in range(2, num):
if num % x == 0: return False
return True[/CODE]

TrustyTony commented: please let OP to do his part -3

ihatehippies 11

You forgot to reset the hatchlings and hens between loops

[CODE=python]def solve():
roosters = 0
hens = 0
hatchlings = 0
while roosters < 20:
while hens < 33:
while hatchlings < 300:
if (roosters5 + hens3 + hatchlings/3 == 100):
if (roosters + hens + hatchlings == 100):
print [roosters, hens, hatchlings]

            hatchlings +=3
        hens += 1
        hatchlings = 0
    roosters += 1
    hens = 0[/CODE]

ihatehippies 11

for your time question

import time
timestamp = time.time()
convertedtime = time.strftime("%a, %d %b %Y %H:%M:%S", timestamp)[/CODE]

ihatehippies 11

waiting on a new release of py2exe

ihatehippies 11

File = open('path\to\file', 'rb')
Data = File.read()