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 2.9.3.1
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

[CODE=python]
def HideFrame(self, evt):
self.Hide()
wx.CallAfter(self.Wait)

def Wait(self):
time.sleep(1)
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.

[CODE=python]
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
try:
self.uPnP.open(port)
except:
print 'retrying to open port', port
sleep(2)
self.uPnP.open(port)
self.ports.append(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):
self.closeall()

ports = Ports()

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

ports.open(15000)

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

[/CODE]

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

[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

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
[CODE=python]
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:
[CODE=python]
def init(self, args):
self.args = args[/CODE]
and then simply pass those saved arguments in your 'run' method.
[CODE=python]
def run(self):
os.system(self.args)[/CODE]

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

ihatehippies 11

[url]http://docs.python.org/tutorial/[/url]

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
[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

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

using

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

reduces the amount of average guesses

ihatehippies 11

tested on python 2.7.2

[CODE=python]
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
else:
break
else:
guess = start
print ('The answer is: %s, thank you for playing'%guess)
return guess

guessing()[/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

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.

[URL="http://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close"]http://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close[/URL]

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

[CODE=python]
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

[CODE=PYTHON]
File = open('path\to\file', 'rb')
Data = File.read()
File.close()

Data.count('aChar')[/CODE]